Skip to content

Commit

Permalink
tests: separate asset and chunk snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
recursive-beast committed Mar 5, 2021
1 parent 60e44a1 commit 38a7e6b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 25 deletions.
50 changes: 25 additions & 25 deletions tests/macros.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@ const { rollup } = require("rollup");

function noop() { }

function normalizeRollupOutput(output) {
return output.map(chunkOrAsset => {
if (chunkOrAsset.type === "asset") return chunkOrAsset;

// These properties are inconsistent between platforms.
// (absolute paths, end of line chars)
const {
dynamicImports,
facadeModuleId,
importedBindings,
imports,
modules,
referencedFiles,
code,
...rest
} = chunkOrAsset;

return {
...rest,
code: code.replace(/\r\n|\n/g, "\n"),
};
});
}
const normalizeChunks = chunks => chunks.map(chunk => {
// These properties are inconsistent between platforms.
// (absolute paths, end of line chars)
const {
dynamicImports,
facadeModuleId,
importedBindings,
imports,
modules,
referencedFiles,
code,
...rest
} = chunk;

return {
...rest,
code: code.replace(/\r\n|\n/g, "\n"),
};
});

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

t.snapshot(normalizedOutput);
const chunks = output.filter(element => element.type === "chunk");
const assets = output.filter(element => element.type === "asset");
const normalizedChunks = normalizeChunks(chunks);

t.snapshot(normalizedChunks);
t.snapshot(assets);
};
5 changes: 5 additions & 0 deletions tests/snapshots/general.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index2',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down
Binary file modified tests/snapshots/general.test.js.snap
Binary file not shown.
79 changes: 79 additions & 0 deletions tests/snapshots/output.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -5486,6 +5491,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -10930,6 +10940,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -16377,6 +16392,10 @@ Generated by [AVA](https://avajs.dev).
},
]

> Snapshot 2

[]

## output.format = 'umd'

> Snapshot 1
Expand Down Expand Up @@ -16422,6 +16441,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -21870,6 +21894,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -27337,6 +27366,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -32776,6 +32810,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -38215,6 +38254,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -43654,6 +43698,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/sub/image_0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -49093,6 +49142,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/sub/image_0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -54565,6 +54619,11 @@ Generated by [AVA](https://avajs.dev).
name: 'file2',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -60048,6 +60107,11 @@ Generated by [AVA](https://avajs.dev).
name: 'file2',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -65486,6 +65550,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index1',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -70929,6 +70998,11 @@ Generated by [AVA](https://avajs.dev).
name: 'image',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/text-6d7076f2.txt',
isAsset: true,
Expand Down Expand Up @@ -76367,6 +76441,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index6',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down
Binary file modified tests/snapshots/output.test.js.snap
Binary file not shown.
10 changes: 10 additions & 0 deletions tests/snapshots/resolve.test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index2',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down Expand Up @@ -7158,6 +7163,11 @@ Generated by [AVA](https://avajs.dev).
name: 'index3',
type: 'chunk',
},
]

> Snapshot 2

[
{
fileName: 'assets/image-0fc60877.png',
isAsset: true,
Expand Down
Binary file modified tests/snapshots/resolve.test.js.snap
Binary file not shown.

0 comments on commit 38a7e6b

Please sign in to comment.