test_runner: mark snapshot testing as stable · nodejs/node@8ff082c · GitHub
Skip to content

Commit 8ff082c

Browse files
cjihrigruyadorno
authored andcommitted
test_runner: mark snapshot testing as stable
This commit marks the test runner's snapshot testing API as stable. PR-URL: #55897 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 55239a4 commit 8ff082c

9 files changed

Lines changed: 42 additions & 68 deletions

File tree

doc/api/cli.md

Lines changed: 4 additions & 14 deletions

doc/api/test.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -937,8 +937,7 @@ compared against a set of known good values. The known good values are known as
937937
snapshots, and are stored in a snapshot file. Snapshot files are managed by the
938938
test runner, but are designed to be human readable to aid in debugging. Best
939939
practice is for snapshot files to be checked into source control along with your
940-
test files. In order to enable snapshot testing, Node.js must be started with
941-
the [`--experimental-test-snapshots`][] command-line flag.
940+
test files.
942941

943942
Snapshot files are generated by starting Node.js with the
944943
[`--test-update-snapshots`][] command-line flag. A separate snapshot file is
@@ -3562,7 +3561,6 @@ Can be used to abort test subtasks when the test has been aborted.
35623561
[`--experimental-strip-types`]: cli.md#--experimental-strip-types
35633562
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
35643563
[`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks
3565-
[`--experimental-test-snapshots`]: cli.md#--experimental-test-snapshots
35663564
[`--import`]: cli.md#--importmodule
35673565
[`--test-concurrency`]: cli.md#--test-concurrency
35683566
[`--test-coverage-include`]: cli.md#--test-coverage-include

doc/node.1

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ Configures the type of test isolation used in the test runner.
191191
.It Fl -experimental-test-module-mocks
192192
Enable module mocking in the test runner.
193193
.
194-
.It Fl -experimental-test-snapshots
195-
Enable snapshot testing in the test runner.
196-
.
197194
.It Fl -experimental-strip-types
198195
Enable experimental type-stripping for TypeScript files.
199196
.

lib/internal/test_runner/test.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ function lazyAssertObject(harness) {
104104
if (assertObj === undefined) {
105105
assertObj = new SafeMap();
106106
const assert = require('assert');
107+
const { SnapshotManager } = require('internal/test_runner/snapshot');
107108
const methodsToCopy = [
108109
'deepEqual',
109110
'deepStrictEqual',
@@ -126,12 +127,8 @@ function lazyAssertObject(harness) {
126127
assertObj.set(methodsToCopy[i], assert[methodsToCopy[i]]);
127128
}
128129

129-
const { getOptionValue } = require('internal/options');
130-
if (getOptionValue('--experimental-test-snapshots')) {
131-
const { SnapshotManager } = require('internal/test_runner/snapshot');
132-
harness.snapshotManager = new SnapshotManager(harness.config.updateSnapshots);
133-
assertObj.set('snapshot', harness.snapshotManager.createAssert());
134-
}
130+
harness.snapshotManager = new SnapshotManager(harness.config.updateSnapshots);
131+
assertObj.set('snapshot', harness.snapshotManager.createAssert());
135132
}
136133
return assertObj;
137134
}

lib/test.js

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const {
77

88
const { test, suite, before, after, beforeEach, afterEach } = require('internal/test_runner/harness');
99
const { run } = require('internal/test_runner/runner');
10-
const { getOptionValue } = require('internal/options');
1110

1211
module.exports = test;
1312
ObjectAssign(module.exports, {
@@ -39,28 +38,26 @@ ObjectDefineProperty(module.exports, 'mock', {
3938
},
4039
});
4140

42-
if (getOptionValue('--experimental-test-snapshots')) {
43-
let lazySnapshot;
41+
let lazySnapshot;
4442

45-
ObjectDefineProperty(module.exports, 'snapshot', {
46-
__proto__: null,
47-
configurable: true,
48-
enumerable: true,
49-
get() {
50-
if (lazySnapshot === undefined) {
51-
const {
52-
setDefaultSnapshotSerializers,
53-
setResolveSnapshotPath,
54-
} = require('internal/test_runner/snapshot');
55-
56-
lazySnapshot = {
57-
__proto__: null,
58-
setDefaultSnapshotSerializers,
59-
setResolveSnapshotPath,
60-
};
61-
}
43+
ObjectDefineProperty(module.exports, 'snapshot', {
44+
__proto__: null,
45+
configurable: true,
46+
enumerable: true,
47+
get() {
48+
if (lazySnapshot === undefined) {
49+
const {
50+
setDefaultSnapshotSerializers,
51+
setResolveSnapshotPath,
52+
} = require('internal/test_runner/snapshot');
53+
54+
lazySnapshot = {
55+
__proto__: null,
56+
setDefaultSnapshotSerializers,
57+
setResolveSnapshotPath,
58+
};
59+
}
6260

63-
return lazySnapshot;
64-
},
65-
});
66-
}
61+
return lazySnapshot;
62+
},
63+
});

src/node_options.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -703,9 +703,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
703703
AddOption("--experimental-test-module-mocks",
704704
"enable module mocking in the test runner",
705705
&EnvironmentOptions::test_runner_module_mocks);
706-
AddOption("--experimental-test-snapshots",
707-
"enable snapshot testing in the test runner",
708-
&EnvironmentOptions::test_runner_snapshots);
706+
AddOption("--experimental-test-snapshots", "", NoOp{});
709707
AddOption("--test-name-pattern",
710708
"run tests whose name matches this regular expression",
711709
&EnvironmentOptions::test_name_pattern,

src/node_options.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ class EnvironmentOptions : public Options {
190190
uint64_t test_coverage_functions = 0;
191191
uint64_t test_coverage_lines = 0;
192192
bool test_runner_module_mocks = false;
193-
bool test_runner_snapshots = false;
194193
bool test_runner_update_snapshots = false;
195194
std::vector<std::string> test_name_pattern;
196195
std::vector<std::string> test_reporter;

test/parallel/test-runner-assert.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ require('../common');
33
const assert = require('node:assert');
44
const test = require('node:test');
55

6-
const uncopiedKeys = [
7-
'AssertionError',
8-
'CallTracker',
9-
'strict',
10-
];
11-
test('only methods from node:assert are on t.assert', (t) => {
12-
const expectedKeys = Object.keys(assert).filter((key) => !uncopiedKeys.includes(key)).sort();
6+
test('expected methods are on t.assert', (t) => {
7+
const uncopiedKeys = [
8+
'AssertionError',
9+
'CallTracker',
10+
'strict',
11+
];
12+
const assertKeys = Object.keys(assert).filter((key) => !uncopiedKeys.includes(key));
13+
const expectedKeys = ['snapshot'].concat(assertKeys).sort();
1314
assert.deepStrictEqual(Object.keys(t.assert).sort(), expectedKeys);
1415
});
1516

test/parallel/test-runner-snapshot-tests.js

Lines changed: 4 additions & 7 deletions

0 commit comments

Comments
 (0)