Skip to content

Remove file fingerprints from e2e assertions #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 5 additions & 86 deletions test/cases/adjacent-asset.js

Large diffs are not rendered by default.

36 changes: 25 additions & 11 deletions test/cases/common/assert.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

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

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

exports.assertCssAndSourceMapContent = (cssOutputFile, {sourceRoot = '.', sanitiseSources = false} = {}) =>
const sanitiseSourceMappingUrl = (text, placeholder) =>
text.replace(
/(sourceMappingURL=\w+\.)([0-9a-z]+)|(\s+)([0-9a-z]+)(?=\.css\.map)/g,
(_, p1, p2, p3, p4) => `${p1 || p3}${(p2 || p4).replace(/[0-9a-z]/g, placeholder)}`
);

exports.assertCssAndSourceMapContent = (cssOutputFile) =>
(expected) => {
return sequence(
assertCssFiles(({equal}, exec, list) => {
const expected = rebaseToOutput(cssOutputFile)(exec);
const [path] = list;
equal(list.length, 1, 'should yield single css file');
equal(sanitisePath(path), expected, 'should yield css file at the expected path');
if (cssOutputFile) {
const expected = rebaseToOutput(cssOutputFile)(exec);
const [path] = list;
equal(sanitisePath(path), expected, 'should yield css file at the expected path');
}
}),
assertSourceMapFiles(({equal}, exec, list) => {
const expected = rebaseToOutput(`${cssOutputFile}.map`)(exec);
const [path] = list;
equal(list.length, 1, 'should yield single source-map file');
equal(sanitisePath(path), expected, 'should yield source-map file at the expected path');
if (cssOutputFile) {
const expected = rebaseToOutput(`${cssOutputFile}.map`)(exec);
const [path] = list;
equal(sanitisePath(path), expected, 'should yield source-map file at the expected path');
}
}),
env({
WIDTH: 100,
READ: rebaseToOutput(cssOutputFile),
READ: rebaseToOutput((outputDir) => join(
outputDir,
readdirSync(outputDir).filter((v) => v.endsWith(`.css`)).shift()
)),
WRITE: 'stdout',
MAP_EXT: '.map',
SOURCE_ROOT: rebaseToCwd(sourceRoot),
SANITISE_SOURCES: !!sanitiseSources,
SOURCE_ROOT: rebaseToCwd('.'),
SANITISE_SOURCES: false,
}),
exec('sourcemap-to-string'),
assertExitCodeZero('sourcemap-to-string'),
saveOutput('sourcemap-to-string'),
assert(({equal}, exec) => {
const {stdout} = exec;
equal(
stdout,
sanitiseSourceMappingUrl(stdout.toString(), '□'),
expected,
'should match expected source-map'
);
Expand Down
98 changes: 9 additions & 89 deletions test/cases/declaration-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
const {assertCssAndSourceMapContent} = require('./common/assert');
const {assertCssContent} = require('../lib/assert');
const {
onlyMeta, assertWebpackOk, assertWebpackNotOk, assertNoErrors, assertNoMessages, assertStdout,
assertWebpackOk, assertWebpackNotOk, assertNoErrors, assertNoMessages, assertStdout,
assertCssSourceMapComment, assertCssFile, assertSourceMapFile, assertAssetError
} = require('../lib/assert');

Expand Down Expand Up @@ -85,8 +85,7 @@ module.exports = test(
assertIncludeMessages,
assertCssSourceMapComment(true),
compose(
onlyMeta('meta.version.webpack == 4'),
assertCssAndSourceMapContent('main.52cfa9838af1696e9321.css'),
assertCssAndSourceMapContent(),
outdent
)`
./src/index.scss
Expand All @@ -101,28 +100,8 @@ module.exports = test(
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 2:37 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░; }⏎
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.52cfa9838af1696e93
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 21.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
`,
compose(
onlyMeta('meta.version.webpack >= 5'),
assertCssAndSourceMapContent('main.00abd28f6856af6b42c9.css'),
outdent
)`
./src/index.scss
---------------------------------------------------------------------------------------------------
2:01 .some-class-name {⏎ 1:01 .some-class-name {⏎
@include feature;⏎ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

./src/feature/mixins.scss
---------------------------------------------------------------------------------------------------
2:03 ░░background-image: url('img.jpg')░░░░░░░░░░ 2:03 ░░background-image: url("./img.jpg")░░░░░░░░
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 2:37 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░; }⏎
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.00abd28f6856af6b42
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ c9.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.□□□□□□□□□□□□□□□□□□
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ □□.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
`
),
buildProdNormal(
Expand All @@ -140,26 +119,7 @@ module.exports = test(
assertIncludeMessages,
assertCssSourceMapComment(false),
compose(
onlyMeta('meta.version.webpack == 4'),
assertCssAndSourceMapContent('main.dde052fd081dda9c864c.css'),
outdent
)`
./src/index.scss
---------------------------------------------------------------------------------------------------
2:01 .some-class-name {⏎ 1:01 .some-class-name{░░░░░░░░░░░░░░░░░░░░░░░░░░░
@include feature;⏎ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

./src/feature/mixins.scss
---------------------------------------------------------------------------------------------------
2:03 ░░background-image: url('img.jpg')░░░░░░░░░░ 1:18 ░░░░░░░░░░░░░░░░░background-image:url(img.jp
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ g)░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 1:47 ░░}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
`,
compose(
onlyMeta('meta.version.webpack >= 5'),
assertCssAndSourceMapContent('main.c7a39e4f9127e1c6b77d.css'),
assertCssAndSourceMapContent(),
outdent
)`
./src/index.scss
Expand Down Expand Up @@ -217,8 +177,7 @@ module.exports = test(
assertMixinMessages,
assertCssSourceMapComment(true),
compose(
onlyMeta('meta.version.webpack == 4'),
assertCssAndSourceMapContent('main.1534ff5cd1402fb725ce.css'),
assertCssAndSourceMapContent(),
outdent
)`
./src/index.scss
Expand All @@ -233,28 +192,8 @@ module.exports = test(
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 2:45 ; }⏎
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.1534ff5cd1402fb725
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ce.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
`,
compose(
onlyMeta('meta.version.webpack >= 5'),
assertCssAndSourceMapContent('main.613c31543a6423df814a.css'),
outdent
)`
./src/index.scss
---------------------------------------------------------------------------------------------------
2:01 .some-class-name {⏎ 1:01 .some-class-name {⏎
@include feature;⏎ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

./src/feature/mixins.scss
---------------------------------------------------------------------------------------------------
2:03 ░░background-image: url('img.jpg')░░░░░░░░░░ 2:03 ░░background-image: url("./feature/img.jpg")
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 2:45 ; }⏎
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ⏎
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.613c31543a6423df81
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 4a.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ /*# sourceMappingURL=main.□□□□□□□□□□□□□□□□□□
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ □□.css.map*/░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
`
),
buildProdNormal(
Expand All @@ -272,26 +211,7 @@ module.exports = test(
assertMixinMessages,
assertCssSourceMapComment(false),
compose(
onlyMeta('meta.version.webpack == 4'),
assertCssAndSourceMapContent('main.de970111de16ddcf4132.css'),
outdent
)`
./src/index.scss
---------------------------------------------------------------------------------------------------
2:01 .some-class-name {⏎ 1:01 .some-class-name{░░░░░░░░░░░░░░░░░░░░░░░░░░░
@include feature;⏎ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

./src/feature/mixins.scss
---------------------------------------------------------------------------------------------------
2:03 ░░background-image: url('img.jpg')░░░░░░░░░░ 1:18 ░░░░░░░░░░░░░░░░░background-image:url(featur
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ e/img.jpg)░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
2:35 ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░;⏎ 1:55 ░░░░░░░░░░}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
}░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
`,
compose(
onlyMeta('meta.version.webpack >= 5'),
assertCssAndSourceMapContent('main.9da305b887718db0f8b1.css'),
assertCssAndSourceMapContent(),
outdent
)`
./src/index.scss
Expand Down
Loading