Skip to content

Commit 38a7e6b

Browse files
tests: separate asset and chunk snapshots
1 parent 60e44a1 commit 38a7e6b

File tree

7 files changed

+119
-25
lines changed

7 files changed

+119
-25
lines changed

tests/macros.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,25 @@ const { rollup } = require("rollup");
22

33
function noop() { }
44

5-
function normalizeRollupOutput(output) {
6-
return output.map(chunkOrAsset => {
7-
if (chunkOrAsset.type === "asset") return chunkOrAsset;
8-
9-
// These properties are inconsistent between platforms.
10-
// (absolute paths, end of line chars)
11-
const {
12-
dynamicImports,
13-
facadeModuleId,
14-
importedBindings,
15-
imports,
16-
modules,
17-
referencedFiles,
18-
code,
19-
...rest
20-
} = chunkOrAsset;
21-
22-
return {
23-
...rest,
24-
code: code.replace(/\r\n|\n/g, "\n"),
25-
};
26-
});
27-
}
5+
const normalizeChunks = chunks => chunks.map(chunk => {
6+
// These properties are inconsistent between platforms.
7+
// (absolute paths, end of line chars)
8+
const {
9+
dynamicImports,
10+
facadeModuleId,
11+
importedBindings,
12+
imports,
13+
modules,
14+
referencedFiles,
15+
code,
16+
...rest
17+
} = chunk;
18+
19+
return {
20+
...rest,
21+
code: code.replace(/\r\n|\n/g, "\n"),
22+
};
23+
});
2824

2925
module.exports.outputSnapshotMacro = async function (t, options) {
3026
let { output: outputOptions = {}, ...inputOptions } = options;
@@ -36,7 +32,11 @@ module.exports.outputSnapshotMacro = async function (t, options) {
3632
const bundle = await rollup(inputOptions);
3733
t.teardown(async () => await bundle.close());
3834
const { output } = await bundle.generate(outputOptions);
39-
const normalizedOutput = normalizeRollupOutput(output);
4035

41-
t.snapshot(normalizedOutput);
36+
const chunks = output.filter(element => element.type === "chunk");
37+
const assets = output.filter(element => element.type === "asset");
38+
const normalizedChunks = normalizeChunks(chunks);
39+
40+
t.snapshot(normalizedChunks);
41+
t.snapshot(assets);
4242
};

tests/snapshots/general.test.js.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Generated by [AVA](https://avajs.dev).
4747
name: 'index2',
4848
type: 'chunk',
4949
},
50+
]
51+
52+
> Snapshot 2
53+
54+
[
5055
{
5156
fileName: 'assets/image-0fc60877.png',
5257
isAsset: true,
9 Bytes
Binary file not shown.

tests/snapshots/output.test.js.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ Generated by [AVA](https://avajs.dev).
4040
name: 'index1',
4141
type: 'chunk',
4242
},
43+
]
44+
45+
> Snapshot 2
46+
47+
[
4348
{
4449
fileName: 'assets/image-0fc60877.png',
4550
isAsset: true,
@@ -5486,6 +5491,11 @@ Generated by [AVA](https://avajs.dev).
54865491
name: 'index1',
54875492
type: 'chunk',
54885493
},
5494+
]
5495+
5496+
> Snapshot 2
5497+
5498+
[
54895499
{
54905500
fileName: 'assets/image-0fc60877.png',
54915501
isAsset: true,
@@ -10930,6 +10940,11 @@ Generated by [AVA](https://avajs.dev).
1093010940
name: 'index1',
1093110941
type: 'chunk',
1093210942
},
10943+
]
10944+
10945+
> Snapshot 2
10946+
10947+
[
1093310948
{
1093410949
fileName: 'assets/image-0fc60877.png',
1093510950
isAsset: true,
@@ -16377,6 +16392,10 @@ Generated by [AVA](https://avajs.dev).
1637716392
},
1637816393
]
1637916394

16395+
> Snapshot 2
16396+
16397+
[]
16398+
1638016399
## output.format = 'umd'
1638116400

1638216401
> Snapshot 1
@@ -16422,6 +16441,11 @@ Generated by [AVA](https://avajs.dev).
1642216441
name: 'index1',
1642316442
type: 'chunk',
1642416443
},
16444+
]
16445+
16446+
> Snapshot 2
16447+
16448+
[
1642516449
{
1642616450
fileName: 'assets/image-0fc60877.png',
1642716451
isAsset: true,
@@ -21870,6 +21894,11 @@ Generated by [AVA](https://avajs.dev).
2187021894
name: 'index1',
2187121895
type: 'chunk',
2187221896
},
21897+
]
21898+
21899+
> Snapshot 2
21900+
21901+
[
2187321902
{
2187421903
fileName: 'assets/image-0fc60877.png',
2187521904
isAsset: true,
@@ -27337,6 +27366,11 @@ Generated by [AVA](https://avajs.dev).
2733727366
name: 'index1',
2733827367
type: 'chunk',
2733927368
},
27369+
]
27370+
27371+
> Snapshot 2
27372+
27373+
[
2734027374
{
2734127375
fileName: 'assets/image-0fc60877.png',
2734227376
isAsset: true,
@@ -32776,6 +32810,11 @@ Generated by [AVA](https://avajs.dev).
3277632810
name: 'index1',
3277732811
type: 'chunk',
3277832812
},
32813+
]
32814+
32815+
> Snapshot 2
32816+
32817+
[
3277932818
{
3278032819
fileName: 'assets/image-0fc60877.png',
3278132820
isAsset: true,
@@ -38215,6 +38254,11 @@ Generated by [AVA](https://avajs.dev).
3821538254
name: 'index1',
3821638255
type: 'chunk',
3821738256
},
38257+
]
38258+
38259+
> Snapshot 2
38260+
38261+
[
3821838262
{
3821938263
fileName: 'assets/image-0fc60877.png',
3822038264
isAsset: true,
@@ -43654,6 +43698,11 @@ Generated by [AVA](https://avajs.dev).
4365443698
name: 'index1',
4365543699
type: 'chunk',
4365643700
},
43701+
]
43702+
43703+
> Snapshot 2
43704+
43705+
[
4365743706
{
4365843707
fileName: 'assets/sub/image_0fc60877.png',
4365943708
isAsset: true,
@@ -49093,6 +49142,11 @@ Generated by [AVA](https://avajs.dev).
4909349142
name: 'index1',
4909449143
type: 'chunk',
4909549144
},
49145+
]
49146+
49147+
> Snapshot 2
49148+
49149+
[
4909649150
{
4909749151
fileName: 'assets/sub/image_0fc60877.png',
4909849152
isAsset: true,
@@ -54565,6 +54619,11 @@ Generated by [AVA](https://avajs.dev).
5456554619
name: 'file2',
5456654620
type: 'chunk',
5456754621
},
54622+
]
54623+
54624+
> Snapshot 2
54625+
54626+
[
5456854627
{
5456954628
fileName: 'assets/image-0fc60877.png',
5457054629
isAsset: true,
@@ -60048,6 +60107,11 @@ Generated by [AVA](https://avajs.dev).
6004860107
name: 'file2',
6004960108
type: 'chunk',
6005060109
},
60110+
]
60111+
60112+
> Snapshot 2
60113+
60114+
[
6005160115
{
6005260116
fileName: 'assets/image-0fc60877.png',
6005360117
isAsset: true,
@@ -65486,6 +65550,11 @@ Generated by [AVA](https://avajs.dev).
6548665550
name: 'index1',
6548765551
type: 'chunk',
6548865552
},
65553+
]
65554+
65555+
> Snapshot 2
65556+
65557+
[
6548965558
{
6549065559
fileName: 'assets/image-0fc60877.png',
6549165560
isAsset: true,
@@ -70929,6 +70998,11 @@ Generated by [AVA](https://avajs.dev).
7092970998
name: 'image',
7093070999
type: 'chunk',
7093171000
},
71001+
]
71002+
71003+
> Snapshot 2
71004+
71005+
[
7093271006
{
7093371007
fileName: 'assets/text-6d7076f2.txt',
7093471008
isAsset: true,
@@ -76367,6 +76441,11 @@ Generated by [AVA](https://avajs.dev).
7636776441
name: 'index6',
7636876442
type: 'chunk',
7636976443
},
76444+
]
76445+
76446+
> Snapshot 2
76447+
76448+
[
7637076449
{
7637176450
fileName: 'assets/image-0fc60877.png',
7637276451
isAsset: true,
18 Bytes
Binary file not shown.

tests/snapshots/resolve.test.js.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Generated by [AVA](https://avajs.dev).
4747
name: 'index2',
4848
type: 'chunk',
4949
},
50+
]
51+
52+
> Snapshot 2
53+
54+
[
5055
{
5156
fileName: 'assets/image-0fc60877.png',
5257
isAsset: true,
@@ -7158,6 +7163,11 @@ Generated by [AVA](https://avajs.dev).
71587163
name: 'index3',
71597164
type: 'chunk',
71607165
},
7166+
]
7167+
7168+
> Snapshot 2
7169+
7170+
[
71617171
{
71627172
fileName: 'assets/image-0fc60877.png',
71637173
isAsset: true,
15 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)