Skip to content

Commit dd8222b

Browse files
authored
Merge pull request #220 from bholloway/remove-file-fingerprints-from-e2e-assertions
Remove file fingerprints from e2e assertions
2 parents 557a5c9 + 0a6fa49 commit dd8222b

14 files changed

+127
-993
lines changed

test/cases/adjacent-asset.js

+5-86
Large diffs are not rendered by default.

test/cases/common/assert.js

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const {join, isAbsolute} = require('path');
4+
const {readdirSync} = require('fs');
45
const sequence = require('promise-compose');
56
const {env, exec, assert} = require('test-my-cli');
67

@@ -11,36 +12,49 @@ const rebaseToOutput = rebaseTo(
1112
({root, cwd, env: {OUTPUT}}) => isAbsolute(cwd) ? join(cwd, OUTPUT) : join(root, cwd, OUTPUT)
1213
);
1314

14-
exports.assertCssAndSourceMapContent = (cssOutputFile, {sourceRoot = '.', sanitiseSources = false} = {}) =>
15+
const sanitiseSourceMappingUrl = (text, placeholder) =>
16+
text.replace(
17+
/(sourceMappingURL=\w+\.)([0-9a-z]+)|(\s+)([0-9a-z]+)(?=\.css\.map)/g,
18+
(_, p1, p2, p3, p4) => `${p1 || p3}${(p2 || p4).replace(/[0-9a-z]/g, placeholder)}`
19+
);
20+
21+
exports.assertCssAndSourceMapContent = (cssOutputFile) =>
1522
(expected) => {
1623
return sequence(
1724
assertCssFiles(({equal}, exec, list) => {
18-
const expected = rebaseToOutput(cssOutputFile)(exec);
19-
const [path] = list;
2025
equal(list.length, 1, 'should yield single css file');
21-
equal(sanitisePath(path), expected, 'should yield css file at the expected path');
26+
if (cssOutputFile) {
27+
const expected = rebaseToOutput(cssOutputFile)(exec);
28+
const [path] = list;
29+
equal(sanitisePath(path), expected, 'should yield css file at the expected path');
30+
}
2231
}),
2332
assertSourceMapFiles(({equal}, exec, list) => {
24-
const expected = rebaseToOutput(`${cssOutputFile}.map`)(exec);
25-
const [path] = list;
2633
equal(list.length, 1, 'should yield single source-map file');
27-
equal(sanitisePath(path), expected, 'should yield source-map file at the expected path');
34+
if (cssOutputFile) {
35+
const expected = rebaseToOutput(`${cssOutputFile}.map`)(exec);
36+
const [path] = list;
37+
equal(sanitisePath(path), expected, 'should yield source-map file at the expected path');
38+
}
2839
}),
2940
env({
3041
WIDTH: 100,
31-
READ: rebaseToOutput(cssOutputFile),
42+
READ: rebaseToOutput((outputDir) => join(
43+
outputDir,
44+
readdirSync(outputDir).filter((v) => v.endsWith(`.css`)).shift()
45+
)),
3246
WRITE: 'stdout',
3347
MAP_EXT: '.map',
34-
SOURCE_ROOT: rebaseToCwd(sourceRoot),
35-
SANITISE_SOURCES: !!sanitiseSources,
48+
SOURCE_ROOT: rebaseToCwd('.'),
49+
SANITISE_SOURCES: false,
3650
}),
3751
exec('sourcemap-to-string'),
3852
assertExitCodeZero('sourcemap-to-string'),
3953
saveOutput('sourcemap-to-string'),
4054
assert(({equal}, exec) => {
4155
const {stdout} = exec;
4256
equal(
43-
stdout,
57+
sanitiseSourceMappingUrl(stdout.toString(), '□'),
4458
expected,
4559
'should match expected source-map'
4660
);

test/cases/declaration-mixin.js

+9-89
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const {
1414
const {assertCssAndSourceMapContent} = require('./common/assert');
1515
const {assertCssContent} = require('../lib/assert');
1616
const {
17-
onlyMeta, assertWebpackOk, assertWebpackNotOk, assertNoErrors, assertNoMessages, assertStdout,
17+
assertWebpackOk, assertWebpackNotOk, assertNoErrors, assertNoMessages, assertStdout,
1818
assertCssSourceMapComment, assertCssFile, assertSourceMapFile, assertAssetError
1919
} = require('../lib/assert');
2020

@@ -85,8 +85,7 @@ module.exports = test(
8585
assertIncludeMessages,
8686
assertCssSourceMapComment(true),
8787
compose(
88-
onlyMeta('meta.version.webpack == 4'),
89-
assertCssAndSourceMapContent('main.52cfa9838af1696e9321.css'),
88+
assertCssAndSourceMapContent(),
9089
outdent
9190
)`
9291
./src/index.scss
@@ -101,28 +100,8 @@ module.exports = test(
101100
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 2:37 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░; }⏎
102101
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
103102
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
104-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.52cfa9838af1696e93
105-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 21.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
106-
`,
107-
compose(
108-
onlyMeta('meta.version.webpack >= 5'),
109-
assertCssAndSourceMapContent('main.00abd28f6856af6b42c9.css'),
110-
outdent
111-
)`
112-
./src/index.scss
113-
---------------------------------------------------------------------------------------------------
114-
2:01 .some-class-name {⏎ 1:01 .some-class-name {⏎
115-
@include feature;⏎ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
116-
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
117-
118-
./src/feature/mixins.scss
119-
---------------------------------------------------------------------------------------------------
120-
2:03 ░░background-image: url('img.jpg')░░░░░░░░░░ 2:03 ░░background-image: url("./img.jpg")░░░░░░░░
121-
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 2:37 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░; }⏎
122-
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
123-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
124-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.00abd28f6856af6b42
125-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ c9.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
103+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.□□□□□□□□□□□□□□□□□□
104+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ □□.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
126105
`
127106
),
128107
buildProdNormal(
@@ -140,26 +119,7 @@ module.exports = test(
140119
assertIncludeMessages,
141120
assertCssSourceMapComment(false),
142121
compose(
143-
onlyMeta('meta.version.webpack == 4'),
144-
assertCssAndSourceMapContent('main.dde052fd081dda9c864c.css'),
145-
outdent
146-
)`
147-
./src/index.scss
148-
---------------------------------------------------------------------------------------------------
149-
2:01 .some-class-name {⏎ 1:01 .some-class-name{░░░░░░░░░░░░░░░░░░░░░░░░░░░
150-
@include feature;⏎ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
151-
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
152-
153-
./src/feature/mixins.scss
154-
---------------------------------------------------------------------------------------------------
155-
2:03 ░░background-image: url('img.jpg')░░░░░░░░░░ 1:18 ░░░░░░░░░░░░░░░░░background-image:url(img.jp
156-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ g)░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
157-
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 1:47 ░░}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
158-
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
159-
`,
160-
compose(
161-
onlyMeta('meta.version.webpack >= 5'),
162-
assertCssAndSourceMapContent('main.c7a39e4f9127e1c6b77d.css'),
122+
assertCssAndSourceMapContent(),
163123
outdent
164124
)`
165125
./src/index.scss
@@ -217,8 +177,7 @@ module.exports = test(
217177
assertMixinMessages,
218178
assertCssSourceMapComment(true),
219179
compose(
220-
onlyMeta('meta.version.webpack == 4'),
221-
assertCssAndSourceMapContent('main.1534ff5cd1402fb725ce.css'),
180+
assertCssAndSourceMapContent(),
222181
outdent
223182
)`
224183
./src/index.scss
@@ -233,28 +192,8 @@ module.exports = test(
233192
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 2:45 ; }⏎
234193
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
235194
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
236-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.1534ff5cd1402fb725
237-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ce.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
238-
`,
239-
compose(
240-
onlyMeta('meta.version.webpack >= 5'),
241-
assertCssAndSourceMapContent('main.613c31543a6423df814a.css'),
242-
outdent
243-
)`
244-
./src/index.scss
245-
---------------------------------------------------------------------------------------------------
246-
2:01 .some-class-name {⏎ 1:01 .some-class-name {⏎
247-
@include feature;⏎ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
248-
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
249-
250-
./src/feature/mixins.scss
251-
---------------------------------------------------------------------------------------------------
252-
2:03 ░░background-image: url('img.jpg')░░░░░░░░░░ 2:03 ░░background-image: url("./feature/img.jpg")
253-
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 2:45 ; }⏎
254-
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
255-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
256-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.613c31543a6423df81
257-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 4a.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
195+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.□□□□□□□□□□□□□□□□□□
196+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ □□.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
258197
`
259198
),
260199
buildProdNormal(
@@ -272,26 +211,7 @@ module.exports = test(
272211
assertMixinMessages,
273212
assertCssSourceMapComment(false),
274213
compose(
275-
onlyMeta('meta.version.webpack == 4'),
276-
assertCssAndSourceMapContent('main.de970111de16ddcf4132.css'),
277-
outdent
278-
)`
279-
./src/index.scss
280-
---------------------------------------------------------------------------------------------------
281-
2:01 .some-class-name {⏎ 1:01 .some-class-name{░░░░░░░░░░░░░░░░░░░░░░░░░░░
282-
@include feature;⏎ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
283-
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
284-
285-
./src/feature/mixins.scss
286-
---------------------------------------------------------------------------------------------------
287-
2:03 ░░background-image: url('img.jpg')░░░░░░░░░░ 1:18 ░░░░░░░░░░░░░░░░░background-image:url(featur
288-
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ e/img.jpg)░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
289-
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 1:55 ░░░░░░░░░░}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
290-
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
291-
`,
292-
compose(
293-
onlyMeta('meta.version.webpack >= 5'),
294-
assertCssAndSourceMapContent('main.9da305b887718db0f8b1.css'),
214+
assertCssAndSourceMapContent(),
295215
outdent
296216
)`
297217
./src/index.scss

0 commit comments

Comments
 (0)