Skip to content

Commit 8ff082c

Browse files
cjihrigruyadorno
authored andcommittedJan 5, 2025
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

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
@@ -1115,16 +1115,6 @@ added: v22.3.0
11151115
11161116
Enable module mocking in the test runner.
11171117

1118-
### `--experimental-test-snapshots`
1119-
1120-
<!-- YAML
1121-
added: v22.3.0
1122-
-->
1123-
1124-
> Stability: 1.0 - Early development
1125-
1126-
Enable [snapshot testing][] in the test runner.
1127-
11281118
### `--experimental-vm-modules`
11291119

11301120
<!-- YAML
@@ -2472,13 +2462,13 @@ subtests inherit this value from their parent. The default value is `Infinity`.
24722462

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

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

24832473
### `--throw-deprecation`
24842474

‎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
@@ -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

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

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

+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)
Please sign in to comment.