Skip to content

Commit

Permalink
split build tests in different snapshot files
Browse files Browse the repository at this point in the history
  • Loading branch information
remorses committed Oct 12, 2020
1 parent 7ec1dcf commit e6b2380
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions test/build/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const {readdirSync, readFileSync, statSync, existsSync} = require('fs');
const glob = require('glob');
const os = require('os');

require('jest-specific-snapshot'); // allows to call expect().toMatchSpecificSnapshot(filename, snapshotName)

const STRIP_WHITESPACE = /((\s+$)|((\\r\\n)|(\\n)))/gm;
const STRIP_REV = /\?rev=\w+/gm;
const STRIP_CHUNKHASH = /([\w\-]+\-)[a-z0-9]{8}(\.js)/g;
Expand All @@ -15,7 +17,7 @@ function format(stdout) {
.replace(STRIP_REV, '?rev=XXXXXXXXXX')
.replace(STRIP_CHUNKHASH, '$1XXXXXXXX$2')
.replace(STRIP_WHITESPACE, '')
.replace(STRIP_ROOTDIR, (_, p1, p2)=> {
.replace(STRIP_ROOTDIR, (_, p1, p2) => {
return `/HOME${(p1 + p2).replace(/\\{1,2}/g, '/')}`;
});
}
Expand Down Expand Up @@ -57,7 +59,11 @@ describe('snowpack build', () => {
throw new Error('Empty build directory!');
}

expect(allFiles.map((f) => f.replace(/\\/g, '/'))).toMatchSnapshot('allFiles');
const snapshotFile = path.join(cwd, 'snapshots')
expect(allFiles.map((f) => f.replace(/\\/g, '/'))).toMatchSpecificSnapshot(
snapshotFile,
'allFiles',
);

// If any diffs are detected, we'll assert the difference so that we get nice output.
for (const entry of allFiles) {
Expand All @@ -69,7 +75,7 @@ describe('snowpack build', () => {
entry.endsWith('.map')
) {
const f1 = readFileSync(path.resolve(actual, entry), {encoding: 'utf8'});
expect(format(f1)).toMatchSnapshot(entry.replace(/\\/g, '/'));
expect(format(f1)).toMatchSpecificSnapshot(snapshotFile, `build/${entry.replace(/\\/g, '/')}`);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/esinstall/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const execa = require('execa');
const rimraf = require('rimraf');
const glob = require('glob');

require('jest-specific-snapshot');
require('jest-specific-snapshot'); // allows to call expect().toMatchSpecificSnapshot(filename, snapshotName)

const KEEP_LOCKFILE = [
'source-pika-lockfile', // We explicitly want to test the lockfile in this test
Expand Down

0 comments on commit e6b2380

Please sign in to comment.