mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
9f6c12413c
This commit adds a t.assert.snapshot() method that implements snapshot testing. Serialization uses JSON.stringify() by default, but users can configure the serialization to meet their needs. PR-URL: https://github.com/nodejs/node/pull/53169 Fixes: https://github.com/nodejs/node/issues/48260 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
67 lines
1.3 KiB
JavaScript
67 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const {
|
|
ObjectAssign,
|
|
ObjectDefineProperty,
|
|
} = primordials;
|
|
|
|
const { test, suite, before, after, beforeEach, afterEach } = require('internal/test_runner/harness');
|
|
const { run } = require('internal/test_runner/runner');
|
|
const { getOptionValue } = require('internal/options');
|
|
|
|
module.exports = test;
|
|
ObjectAssign(module.exports, {
|
|
after,
|
|
afterEach,
|
|
before,
|
|
beforeEach,
|
|
describe: suite,
|
|
it: test,
|
|
run,
|
|
suite,
|
|
test,
|
|
});
|
|
|
|
let lazyMock;
|
|
|
|
ObjectDefineProperty(module.exports, 'mock', {
|
|
__proto__: null,
|
|
configurable: true,
|
|
enumerable: true,
|
|
get() {
|
|
if (lazyMock === undefined) {
|
|
const { MockTracker } = require('internal/test_runner/mock/mock');
|
|
|
|
lazyMock = new MockTracker();
|
|
}
|
|
|
|
return lazyMock;
|
|
},
|
|
});
|
|
|
|
if (getOptionValue('--experimental-test-snapshots')) {
|
|
let lazySnapshot;
|
|
|
|
ObjectDefineProperty(module.exports, 'snapshot', {
|
|
__proto__: null,
|
|
configurable: true,
|
|
enumerable: true,
|
|
get() {
|
|
if (lazySnapshot === undefined) {
|
|
const {
|
|
setDefaultSnapshotSerializers,
|
|
setResolveSnapshotPath,
|
|
} = require('internal/test_runner/snapshot');
|
|
|
|
lazySnapshot = {
|
|
__proto__: null,
|
|
setDefaultSnapshotSerializers,
|
|
setResolveSnapshotPath,
|
|
};
|
|
}
|
|
|
|
return lazySnapshot;
|
|
},
|
|
});
|
|
}
|