Skip to content

Commit 8197815

Browse files
cjihrigaduh95
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 <[email protected]> Reviewed-By: Pietro Marchini <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Jacob Smith <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
1 parent 8a5d8c7 commit 8197815

File tree

9 files changed

+42
-68
lines changed

9 files changed

+42
-68
lines changed

doc/api/cli.md

+4-14
Original file line numberDiff line numberDiff line change
@@ -1135,16 +1135,6 @@ added:
11351135
11361136
Enable module mocking in the test runner.
11371137

1138-
### `--experimental-test-snapshots`
1139-
1140-
<!-- YAML
1141-
added: v22.3.0
1142-
-->
1143-
1144-
> Stability: 1.0 - Early development
1145-
1146-
Enable [snapshot testing][] in the test runner.
1147-
11481138
### `--experimental-vm-modules`
11491139

11501140
<!-- YAML
@@ -2473,13 +2463,13 @@ subtests inherit this value from their parent. The default value is `Infinity`.
24732463

24742464
<!-- YAML
24752465
added: v22.3.0
2466+
changes:
2467+
- version: REPLACEME
2468+
pr-url: https://github.com/nodejs/node/pull/55897
2469+
description: Snapsnot testing is no longer experimental.
24762470
-->
24772471

2478-
> Stability: 1.0 - Early development
2479-
24802472
Regenerates the snapshot files used by the test runner for [snapshot testing][].
2481-
Node.js must be started with the `--experimental-test-snapshots` flag in order
2482-
to use this functionality.
24832473

24842474
### `--throw-deprecation`
24852475

doc/api/test.md

+1-3
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
@@ -3591,7 +3590,6 @@ Can be used to abort test subtasks when the test has been aborted.
35913590
[`--experimental-strip-types`]: cli.md#--experimental-strip-types
35923591
[`--experimental-test-coverage`]: cli.md#--experimental-test-coverage
35933592
[`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks
3594-
[`--experimental-test-snapshots`]: cli.md#--experimental-test-snapshots
35953593
[`--import`]: cli.md#--importmodule
35963594
[`--test-concurrency`]: cli.md#--test-concurrency
35973595
[`--test-coverage-include`]: cli.md#--test-coverage-include

doc/node.1

-3
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

+3-6
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

+21-24
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

+1-3
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
691691
AddOption("--experimental-test-module-mocks",
692692
"enable module mocking in the test runner",
693693
&EnvironmentOptions::test_runner_module_mocks);
694-
AddOption("--experimental-test-snapshots",
695-
"enable snapshot testing in the test runner",
696-
&EnvironmentOptions::test_runner_snapshots);
694+
AddOption("--experimental-test-snapshots", "", NoOp{});
697695
AddOption("--test-name-pattern",
698696
"run tests whose name matches this regular expression",
699697
&EnvironmentOptions::test_name_pattern,

src/node_options.h

-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ class EnvironmentOptions : public Options {
189189
uint64_t test_coverage_functions = 0;
190190
uint64_t test_coverage_lines = 0;
191191
bool test_runner_module_mocks = false;
192-
bool test_runner_snapshots = false;
193192
bool test_runner_update_snapshots = false;
194193
std::vector<std::string> test_name_pattern;
195194
std::vector<std::string> test_reporter;

test/parallel/test-runner-assert.js

+8-7
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

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Flags: --expose-internals --experimental-test-snapshots
1+
// Flags: --expose-internals
22
/* eslint-disable no-template-curly-in-string */
33
'use strict';
44
const common = require('../common');
@@ -299,7 +299,7 @@ test('t.assert.snapshot()', async (t) => {
299299
await t.test('fails prior to snapshot generation', async (t) => {
300300
const child = await common.spawnPromisified(
301301
process.execPath,
302-
['--experimental-test-snapshots', fixture],
302+
[fixture],
303303
{ cwd: tmpdir.path },
304304
);
305305

@@ -314,7 +314,7 @@ test('t.assert.snapshot()', async (t) => {
314314
await t.test('passes when regenerating snapshots', async (t) => {
315315
const child = await common.spawnPromisified(
316316
process.execPath,
317-
['--test-update-snapshots', '--experimental-test-snapshots', fixture],
317+
['--test-update-snapshots', fixture],
318318
{ cwd: tmpdir.path },
319319
);
320320

@@ -328,7 +328,7 @@ test('t.assert.snapshot()', async (t) => {
328328
await t.test('passes when snapshots exist', async (t) => {
329329
const child = await common.spawnPromisified(
330330
process.execPath,
331-
['--experimental-test-snapshots', fixture],
331+
[fixture],
332332
{ cwd: tmpdir.path },
333333
);
334334

@@ -350,7 +350,6 @@ test('snapshots from multiple files (isolation=none)', async (t) => {
350350
const args = [
351351
'--test',
352352
'--experimental-test-isolation=none',
353-
'--experimental-test-snapshots',
354353
fixture,
355354
fixture2,
356355
];
@@ -372,7 +371,6 @@ test('snapshots from multiple files (isolation=none)', async (t) => {
372371
const args = [
373372
'--test',
374373
'--experimental-test-isolation=none',
375-
'--experimental-test-snapshots',
376374
'--test-update-snapshots',
377375
fixture,
378376
fixture2,
@@ -394,7 +392,6 @@ test('snapshots from multiple files (isolation=none)', async (t) => {
394392
const args = [
395393
'--test',
396394
'--experimental-test-isolation=none',
397-
'--experimental-test-snapshots',
398395
fixture,
399396
fixture2,
400397
];

0 commit comments

Comments
 (0)