This commit refactors the internals of snapshot tests to get the name of the test file from the test context instead of passing it to the SnapshotManager constructor. This is prep work for supporting running test files in the test runner process. PR-URL: https://github.com/nodejs/node/pull/53853 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
30 lines
723 B
JavaScript
30 lines
723 B
JavaScript
'use strict';
|
|
const { snapshot, suite, test } = require('node:test');
|
|
const { basename, join } = require('node:path');
|
|
|
|
snapshot.setResolveSnapshotPath((testFile) => {
|
|
return join(process.cwd(), `${basename(testFile)}.snapshot`);
|
|
});
|
|
|
|
suite('suite', () => {
|
|
test('test with plan', (t) => {
|
|
t.plan(2);
|
|
t.assert.snapshot({ foo: 1, bar: 2 });
|
|
t.assert.snapshot(5);
|
|
});
|
|
});
|
|
|
|
test('test', async (t) => {
|
|
t.assert.snapshot({ baz: 9 });
|
|
});
|
|
|
|
test('`${foo}`', async (t) => {
|
|
const options = { serializers: [() => { return '***'; }]};
|
|
t.assert.snapshot('snapshotted string', options);
|
|
});
|
|
|
|
test('escapes in `\\${foo}`\n', async (t) => {
|
|
t.assert.snapshot('`\\${foo}`\n');
|
|
});
|
|
|
|
require('./imported-tests');
|