Skip to content

Commit 89b0398

Browse files
authored
test: use snapshot-diffs (#572)
* test: add snapshot-diff Also restructure how custom snapshot matchers are loaded * test: rollup watch test using snapshot diffs * test: change read-dir.js output ... and all the snapshots that use that output
1 parent 0284b11 commit 89b0398

13 files changed

+412
-603
lines changed

jest.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ module.exports = {
1717
"/output/",
1818
"/specimens/",
1919
],
20+
21+
setupFilesAfterEnv : [
22+
"<rootDir>/packages/test-utils/expect/toMatchDiffSnapshot.js",
23+
"<rootDir>/packages/test-utils/expect/toMatchRollupSnapshot.js",
24+
"<rootDir>/packages/test-utils/expect/toMatchRollupCodeSnapshot.js",
25+
],
26+
27+
snapshotSerializers : [
28+
require.resolve("snapshot-diff/serializer.js"),
29+
],
2030
},
2131
{
2232
displayName : "lint",

package-lock.json

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"rollup": "^1.7.0",
4545
"rollup-plugin-svelte": "^5.0.3",
4646
"shelljs": "^0.8.3",
47+
"snapshot-diff": "^0.5.1",
4748
"sugarss": "^2.0.0",
4849
"svelte": "^2.16.1",
4950
"watchify": "^3.11.1",

packages/rollup-rewriter/test/rewriter.test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ const { rollup } = require("rollup");
55

66
const shell = require("shelljs");
77

8-
const prefix = require("@modular-css/test-utils/prefix.js")(__dirname);
9-
const namer = require("@modular-css/test-utils/namer.js");
10-
const logs = require("@modular-css/test-utils/logs.js");
11-
12-
require("@modular-css/test-utils/rollup-build-snapshot.js");
8+
const prefix = require("@modular-css/test-utils/prefix.js")(__dirname);
9+
const namer = require("@modular-css/test-utils/namer.js");
10+
const logs = require("@modular-css/test-utils/logs.js");
1311

1412
const css = require("@modular-css/rollup");
1513

packages/rollup/test/__snapshots__/rollup.test.js.snap

+25-64
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,47 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`/rollup.js case sensitivity tests should remove repeated references that point at the same files 1`] = `
4-
Array [
5-
Object {
6-
"file": "assets/foo.css",
7-
"text": "/* packages/rollup/test/specimens/casing/bar.css */
4+
Object {
5+
"assets/foo.css": "/* packages/rollup/test/specimens/casing/bar.css */
86
.mc79ab9c62_bar {
97
display: none;
108
}
119
/* packages/rollup/test/specimens/casing/foo.css */
1210
.mc3dd08d27_foo {
1311
color: #F00;
1412
}",
15-
},
16-
Object {
17-
"file": "main.js",
18-
"text": "var bar = \\"mc79ab9c62_bar\\";
13+
"main.js": "var bar = \\"mc79ab9c62_bar\\";
1914
2015
var foo = \\"mc79ab9c62_bar mc3dd08d27_foo\\";
2116
2217
var bar$1 = \\"mc79ab9c62_bar\\";
2318
2419
console.log({ foo, bar: bar$1, bar2: bar });
2520
",
26-
},
27-
]
21+
}
2822
`;
2923

3024
exports[`/rollup.js should accept an existing processor instance (no css in bundle) 1`] = `
31-
Array [
32-
Object {
33-
"file": "fake.css",
34-
"text": "/* packages/rollup/test/specimens/fake.css */
25+
Object {
26+
"fake.css": "/* packages/rollup/test/specimens/fake.css */
3527
.fake {
3628
color: yellow;
3729
}",
38-
},
39-
]
30+
}
4031
`;
4132

4233
exports[`/rollup.js should accept an existing processor instance 1`] = `
43-
Array [
44-
Object {
45-
"file": "fake.css",
46-
"text": "/* packages/rollup/test/specimens/fake.css */
34+
Object {
35+
"fake.css": "/* packages/rollup/test/specimens/fake.css */
4736
.fake {
4837
color: yellow;
4938
}",
50-
},
51-
Object {
52-
"file": "simple.css",
53-
"text": "/* packages/rollup/test/specimens/simple.css */
39+
"simple.css": "/* packages/rollup/test/specimens/simple.css */
5440
.fooga {
5541
color: red;
5642
}
5743
",
58-
},
59-
]
44+
}
6045
`;
6146

6247
exports[`/rollup.js should allow disabling of named exports 1`] = `
@@ -81,63 +66,45 @@ console.log(fooga);
8166
`;
8267

8368
exports[`/rollup.js should correctly handle hashed output 1`] = `
84-
Array [
85-
Object {
86-
"file": "assets/simple-8d1bcf7b.css",
87-
"text": "/* packages/rollup/test/specimens/simple.css */
69+
Object {
70+
"assets/simple-8d1bcf7b.css": "/* packages/rollup/test/specimens/simple.css */
8871
.fooga {
8972
color: red;
9073
}
9174
",
92-
},
93-
Object {
94-
"file": "hashes.js",
95-
"text": "var css = {
75+
"hashes.js": "var css = {
9676
\\"str\\": \\"\\\\\\"string\\\\\\"\\",
9777
\\"fooga\\": \\"fooga\\"
9878
};
9979
10080
console.log(css);
10181
",
102-
},
103-
]
82+
}
10483
`;
10584

10685
exports[`/rollup.js should correctly handle hashed output with external source maps & json files 1`] = `
107-
Array [
108-
Object {
109-
"file": "assets/exports-24307d7d.json",
110-
"text": "{
86+
Object {
87+
"assets/exports-24307d7d.json": "{
11188
\\"packages/rollup/test/specimens/simple.css\\": {
11289
\\"str\\": \\"\\\\\\"string\\\\\\"\\",
11390
\\"fooga\\": \\"fooga\\"
11491
}
11592
}",
116-
},
117-
Object {
118-
"file": "assets/simple-8d1bcf7b.css",
119-
"text": "/* packages/rollup/test/specimens/simple.css */
93+
"assets/simple-8d1bcf7b.css": "/* packages/rollup/test/specimens/simple.css */
12094
.fooga {
12195
color: red;
12296
}
12397
12498
/*# sourceMappingURL=simple-8d1bcf7b.css.map */",
125-
},
126-
Object {
127-
"file": "assets/simple-8d1bcf7b.css.map",
128-
"text": "{\\"version\\":3,\\"sources\\":[\\"../../../specimens/simple.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,8CAAA;AAEA;IACI,UAAU;AACd\\",\\"file\\":\\"simple-[hash].css\\",\\"sourcesContent\\":[\\"@value str: \\\\\\"string\\\\\\";\\\\n\\\\n.fooga {\\\\n color: red;\\\\n}\\\\n\\"]}",
129-
},
130-
Object {
131-
"file": "hashes.js",
132-
"text": "var css = {
99+
"assets/simple-8d1bcf7b.css.map": "{\\"version\\":3,\\"sources\\":[\\"../../../specimens/simple.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA,8CAAA;AAEA;IACI,UAAU;AACd\\",\\"file\\":\\"simple-[hash].css\\",\\"sourcesContent\\":[\\"@value str: \\\\\\"string\\\\\\";\\\\n\\\\n.fooga {\\\\n color: red;\\\\n}\\\\n\\"]}",
100+
"hashes.js": "var css = {
133101
\\"str\\": \\"\\\\\\"string\\\\\\"\\",
134102
\\"fooga\\": \\"fooga\\"
135103
};
136104
137105
console.log(css);
138106
",
139-
},
140-
]
107+
}
141108
`;
142109

143110
exports[`/rollup.js should correctly pass to/from params for relative paths 1`] = `
@@ -416,23 +383,17 @@ console.log(style);
416383
`;
417384
418385
exports[`/rollup.js should output unreferenced CSS 1`] = `
419-
Array [
420-
Object {
421-
"file": "fake.css",
422-
"text": "/* packages/rollup/test/specimens/fake.css */
386+
Object {
387+
"fake.css": "/* packages/rollup/test/specimens/fake.css */
423388
.fake {
424389
color: yellow;
425390
}",
426-
},
427-
Object {
428-
"file": "simple.css",
429-
"text": "/* packages/rollup/test/specimens/simple.css */
391+
"simple.css": "/* packages/rollup/test/specimens/simple.css */
430392
.fooga {
431393
color: red;
432394
}
433395
",
434-
},
435-
]
396+
}
436397
`;
437398
438399
exports[`/rollup.js should provide named exports 1`] = `

0 commit comments

Comments
 (0)