GeezerVison is showing github.com — test_runner: mark snapshot testing as stable · nodejs/node@8ff082c
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cli.md +4-14Lines changed: 4 additions & 14 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1115,16 +1115,6 @@ added: v22.3.0 | 1115 | 1115 |
| 1116 | 1116 | Enable module mocking in the test runner. | 1117 | 1117 |
| 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 | | - | 1128 | 1118 | ### `--experimental-vm-modules` | 1129 | 1119 |
| 1130 | 1120 | <!-- YAML | @@ -2472,13 +2462,13 @@ subtests inherit this value from their parent. The default value is `Infinity`. | 2472 | 2462 |
| 2473 | 2463 | <!-- YAML | 2474 | 2464 | 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. | 2475 | 2469 | --> | 2476 | 2470 |
| 2477 | | -> Stability: 1.0 - Early development | 2478 | | -
| 2479 | 2471 | 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. | 2482 | 2472 |
| 2483 | 2473 | ### `--throw-deprecation` | 2484 | 2474 |
| |
Collapse file Copy file name to clipboardExpand all lines: doc/api/test.md +1-3Lines changed: 1 addition & 3 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -937,8 +937,7 @@ compared against a set of known good values. The known good values are known as | 937 | 937 | snapshots, and are stored in a snapshot file. Snapshot files are managed by the | 938 | 938 | test runner, but are designed to be human readable to aid in debugging. Best | 939 | 939 | 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. | 942 | 941 |
| 943 | 942 | Snapshot files are generated by starting Node.js with the | 944 | 943 | [`--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. | 3562 | 3561 | [`--experimental-strip-types`]: cli.md#--experimental-strip-types | 3563 | 3562 | [`--experimental-test-coverage`]: cli.md#--experimental-test-coverage | 3564 | 3563 | [`--experimental-test-module-mocks`]: cli.md#--experimental-test-module-mocks | 3565 | | -[`--experimental-test-snapshots`]: cli.md#--experimental-test-snapshots | 3566 | 3564 | [`--import`]: cli.md#--importmodule | 3567 | 3565 | [`--test-concurrency`]: cli.md#--test-concurrency | 3568 | 3566 | [`--test-coverage-include`]: cli.md#--test-coverage-include | |
Collapse file Copy file name to clipboardExpand all lines: doc/node.1 -3Lines changed: 0 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -191,9 +191,6 @@ Configures the type of test isolation used in the test runner. | 191 | 191 | .It Fl -experimental-test-module-mocks | 192 | 192 | Enable module mocking in the test runner. | 193 | 193 | . | 194 | | -.It Fl -experimental-test-snapshots | 195 | | -Enable snapshot testing in the test runner. | 196 | | -. | 197 | 194 | .It Fl -experimental-strip-types | 198 | 195 | Enable experimental type-stripping for TypeScript files. | 199 | 196 | . | |
Collapse file Copy file name to clipboardExpand all lines: lib/internal/test_runner/test.js +3-6Lines changed: 3 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -104,6 +104,7 @@ function lazyAssertObject(harness) { | 104 | 104 | if (assertObj === undefined) { | 105 | 105 | assertObj = new SafeMap(); | 106 | 106 | const assert = require('assert'); | | 107 | + const { SnapshotManager } = require('internal/test_runner/snapshot'); | 107 | 108 | const methodsToCopy = [ | 108 | 109 | 'deepEqual', | 109 | 110 | 'deepStrictEqual', | @@ -126,12 +127,8 @@ function lazyAssertObject(harness) { | 126 | 127 | assertObj.set(methodsToCopy[i], assert[methodsToCopy[i]]); | 127 | 128 | } | 128 | 129 |
| 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()); | 135 | 132 | } | 136 | 133 | return assertObj; | 137 | 134 | } | |
Collapse file Copy file name to clipboardExpand all lines: lib/test.js +21-24Lines changed: 21 additions & 24 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 |
| 8 | 8 | const { test, suite, before, after, beforeEach, afterEach } = require('internal/test_runner/harness'); | 9 | 9 | const { run } = require('internal/test_runner/runner'); | 10 | | -const { getOptionValue } = require('internal/options'); | 11 | 10 |
| 12 | 11 | module.exports = test; | 13 | 12 | ObjectAssign(module.exports, { | @@ -39,28 +38,26 @@ ObjectDefineProperty(module.exports, 'mock', { | 39 | 38 | }, | 40 | 39 | }); | 41 | 40 |
| 42 | | -if (getOptionValue('--experimental-test-snapshots')) { | 43 | | - let lazySnapshot; | | 41 | +let lazySnapshot; | 44 | 42 |
| 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 | + } | 62 | 60 |
| 63 | | - return lazySnapshot; | 64 | | - }, | 65 | | - }); | 66 | | -} | | 61 | + return lazySnapshot; | | 62 | + }, | | 63 | +}); |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.cc +1-3Lines changed: 1 addition & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -703,9 +703,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { | 703 | 703 | AddOption("--experimental-test-module-mocks", | 704 | 704 | "enable module mocking in the test runner", | 705 | 705 | &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{}); | 709 | 707 | AddOption("--test-name-pattern", | 710 | 708 | "run tests whose name matches this regular expression", | 711 | 709 | &EnvironmentOptions::test_name_pattern, | |
Collapse file Copy file name to clipboardExpand all lines: src/node_options.h -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -190,7 +190,6 @@ class EnvironmentOptions : public Options { | 190 | 190 | uint64_t test_coverage_functions = 0; | 191 | 191 | uint64_t test_coverage_lines = 0; | 192 | 192 | bool test_runner_module_mocks = false; | 193 | | - bool test_runner_snapshots = false; | 194 | 193 | bool test_runner_update_snapshots = false; | 195 | 194 | std::vector<std::string> test_name_pattern; | 196 | 195 | std::vector<std::string> test_reporter; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-assert.js +8-7Lines changed: 8 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -3,13 +3,14 @@ require('../common'); | 3 | 3 | const assert = require('node:assert'); | 4 | 4 | const test = require('node:test'); | 5 | 5 |
| 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(); | 13 | 14 | assert.deepStrictEqual(Object.keys(t.assert).sort(), expectedKeys); | 14 | 15 | }); | 15 | 16 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-runner-snapshot-tests.js +4-7Lines changed: 4 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | | -// Flags: --expose-internals --experimental-test-snapshots | | 1 | +// Flags: --expose-internals | 2 | 2 | /* eslint-disable no-template-curly-in-string */ | 3 | 3 | 'use strict'; | 4 | 4 | const common = require('../common'); | @@ -299,7 +299,7 @@ test('t.assert.snapshot()', async (t) => { | 299 | 299 | await t.test('fails prior to snapshot generation', async (t) => { | 300 | 300 | const child = await common.spawnPromisified( | 301 | 301 | process.execPath, | 302 | | - ['--experimental-test-snapshots', fixture], | | 302 | + [fixture], | 303 | 303 | { cwd: tmpdir.path }, | 304 | 304 | ); | 305 | 305 |
| @@ -314,7 +314,7 @@ test('t.assert.snapshot()', async (t) => { | 314 | 314 | await t.test('passes when regenerating snapshots', async (t) => { | 315 | 315 | const child = await common.spawnPromisified( | 316 | 316 | process.execPath, | 317 | | - ['--test-update-snapshots', '--experimental-test-snapshots', fixture], | | 317 | + ['--test-update-snapshots', fixture], | 318 | 318 | { cwd: tmpdir.path }, | 319 | 319 | ); | 320 | 320 |
| @@ -328,7 +328,7 @@ test('t.assert.snapshot()', async (t) => { | 328 | 328 | await t.test('passes when snapshots exist', async (t) => { | 329 | 329 | const child = await common.spawnPromisified( | 330 | 330 | process.execPath, | 331 | | - ['--experimental-test-snapshots', fixture], | | 331 | + [fixture], | 332 | 332 | { cwd: tmpdir.path }, | 333 | 333 | ); | 334 | 334 |
| @@ -350,7 +350,6 @@ test('snapshots from multiple files (isolation=none)', async (t) => { | 350 | 350 | const args = [ | 351 | 351 | '--test', | 352 | 352 | '--experimental-test-isolation=none', | 353 | | - '--experimental-test-snapshots', | 354 | 353 | fixture, | 355 | 354 | fixture2, | 356 | 355 | ]; | @@ -372,7 +371,6 @@ test('snapshots from multiple files (isolation=none)', async (t) => { | 372 | 371 | const args = [ | 373 | 372 | '--test', | 374 | 373 | '--experimental-test-isolation=none', | 375 | | - '--experimental-test-snapshots', | 376 | 374 | '--test-update-snapshots', | 377 | 375 | fixture, | 378 | 376 | fixture2, | @@ -394,7 +392,6 @@ test('snapshots from multiple files (isolation=none)', async (t) => { | 394 | 392 | const args = [ | 395 | 393 | '--test', | 396 | 394 | '--experimental-test-isolation=none', | 397 | | - '--experimental-test-snapshots', | 398 | 395 | fixture, | 399 | 396 | fixture2, | 400 | 397 | ]; | |
|