Skip to content

Commit def3694

Browse files
MoLowRafaelGSS
authored andcommittedJan 20, 2023
assert: remove assert.snapshot
PR-URL: #46112 Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent e222a2f commit def3694

22 files changed

+6
-405
lines changed
 

‎doc/api/assert.md

-44
Original file line numberDiff line numberDiff line change
@@ -2093,48 +2093,6 @@ argument, then `error` is assumed to be omitted and the string will be used for
20932093
example in [`assert.throws()`][] carefully if using a string as the second
20942094
argument gets considered.
20952095

2096-
## `assert.snapshot(value, name)`
2097-
2098-
<!-- YAML
2099-
added: v18.8.0
2100-
-->
2101-
2102-
> Stability: 1 - Experimental
2103-
2104-
* `value` {any} the value to snapshot.
2105-
* `name` {string} the name of the snapshot.
2106-
* Returns: {Promise}
2107-
2108-
Reads the `name` snapshot from a file and compares `value` to the snapshot.
2109-
`value` is serialized with [`util.inspect()`][]. If the value is not strictly
2110-
equal to the snapshot, `assert.snapshot()` returns a rejected `Promise` with an
2111-
[`AssertionError`][].
2112-
2113-
The snapshot filename uses the same basename as the application's main
2114-
entrypoint with a `.snapshot` extension. If the snapshot file does not exist,
2115-
it is created. The [`--update-assert-snapshot`][] command line flag can be used
2116-
to force the update of an existing snapshot.
2117-
2118-
```mjs
2119-
import assert from 'node:assert/strict';
2120-
2121-
// Assuming that the application's main entrypoint is app.mjs, this reads the
2122-
// 'snapshotName' snapshot from app.snapshot and strictly compares its value
2123-
// to `util.inspect('value')`.
2124-
await assert.snapshot('value', 'snapshotName');
2125-
```
2126-
2127-
```cjs
2128-
const assert = require('node:assert/strict');
2129-
2130-
(async () => {
2131-
// Assuming that the application's main entrypoint is app.js, this reads the
2132-
// 'snapshotName' snapshot from app.snapshot and strictly compares its value
2133-
// to `util.inspect('value')`.
2134-
await assert.snapshot('value', 'snapshotName');
2135-
})();
2136-
```
2137-
21382096
## `assert.strictEqual(actual, expected[, message])`
21392097

21402098
<!-- YAML
@@ -2571,7 +2529,6 @@ argument.
25712529
[Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript
25722530
[Object.prototype.toString()]: https://tc39.github.io/ecma262/#sec-object.prototype.tostring
25732531
[`!=` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality
2574-
[`--update-assert-snapshot`]: cli.md#--update-assert-snapshot
25752532
[`===` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality
25762533
[`==` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality
25772534
[`AssertionError`]: #class-assertassertionerror
@@ -2603,6 +2560,5 @@ argument.
26032560
[`process.on('exit')`]: process.md#event-exit
26042561
[`tracker.calls()`]: #trackercallsfn-exact
26052562
[`tracker.verify()`]: #trackerverify
2606-
[`util.inspect()`]: util.md#utilinspectobject-options
26072563
[enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
26082564
[prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots

‎doc/api/cli.md

-10
Original file line numberDiff line numberDiff line change
@@ -1513,14 +1513,6 @@ occurs. One of the following modes can be chosen:
15131513
If a rejection happens during the command line entry point's ES module static
15141514
loading phase, it will always raise it as an uncaught exception.
15151515

1516-
### `--update-assert-snapshot`
1517-
1518-
<!-- YAML
1519-
added: v18.8.0
1520-
-->
1521-
1522-
Updates snapshot files used by [`assert.snapshot()`][].
1523-
15241516
### `--use-bundled-ca`, `--use-openssl-ca`
15251517

15261518
<!-- YAML
@@ -1943,7 +1935,6 @@ Node.js options that are allowed are:
19431935
* `--trace-warnings`
19441936
* `--track-heap-objects`
19451937
* `--unhandled-rejections`
1946-
* `--update-assert-snapshot`
19471938
* `--use-bundled-ca`
19481939
* `--use-largepages`
19491940
* `--use-openssl-ca`
@@ -2324,7 +2315,6 @@ done
23242315
[`NO_COLOR`]: https://no-color.org
23252316
[`SlowBuffer`]: buffer.md#class-slowbuffer
23262317
[`YoungGenerationSizeFromSemiSpaceSize`]: https://chromium.googlesource.com/v8/v8.git/+/refs/tags/10.3.129/src/heap/heap.cc#328
2327-
[`assert.snapshot()`]: assert.md#assertsnapshotvalue-name
23282318
[`dns.lookup()`]: dns.md#dnslookuphostname-options-callback
23292319
[`dns.setDefaultResultOrder()`]: dns.md#dnssetdefaultresultorderorder
23302320
[`dnsPromises.lookup()`]: dns.md#dnspromiseslookuphostname-options

‎doc/api/errors.md

-7
Original file line numberDiff line numberDiff line change
@@ -705,13 +705,6 @@ A special type of error that can be triggered whenever Node.js detects an
705705
exceptional logic violation that should never occur. These are raised typically
706706
by the `node:assert` module.
707707

708-
<a id="ERR_ASSERT_SNAPSHOT_NOT_SUPPORTED"></a>
709-
710-
### `ERR_ASSERT_SNAPSHOT_NOT_SUPPORTED`
711-
712-
An attempt was made to use `assert.snapshot()` in an environment that
713-
does not support snapshots, such as the REPL, or when using `node --eval`.
714-
715708
<a id="ERR_ASYNC_CALLBACK"></a>
716709

717710
### `ERR_ASYNC_CALLBACK`

‎doc/node.1

-3
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,6 @@ Track heap object allocations for heap snapshots.
491491
.It Fl -unhandled-rejections=mode
492492
Define the behavior for unhandled rejections. Can be one of `strict` (raise an error), `warn` (enforce warnings) or `none` (silence warnings).
493493
.
494-
.It Fl -update-assert-snapshot
495-
Updates snapshot files used by `assert.snapshot()`.
496-
.
497494
.It Fl -use-bundled-ca , Fl -use-openssl-ca
498495
Use bundled Mozilla CA store as supplied by current Node.js version or use OpenSSL's default CA store.
499496
The default store is selectable at build-time.

‎lib/assert.js

-3
Original file line numberDiff line numberDiff line change
@@ -1052,9 +1052,6 @@ assert.doesNotMatch = function doesNotMatch(string, regexp, message) {
10521052

10531053
assert.CallTracker = CallTracker;
10541054

1055-
const snapshot = require('internal/assert/snapshot');
1056-
assert.snapshot = snapshot;
1057-
10581055
/**
10591056
* Expose a strict only variant of assert.
10601057
* @param {...any} args

‎lib/internal/assert/snapshot.js

-129
This file was deleted.

‎lib/internal/errors.js

-2
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,6 @@ module.exports = {
962962
E('ERR_AMBIGUOUS_ARGUMENT', 'The "%s" argument is ambiguous. %s', TypeError);
963963
E('ERR_ARG_NOT_ITERABLE', '%s must be iterable', TypeError);
964964
E('ERR_ASSERTION', '%s', Error);
965-
E('ERR_ASSERT_SNAPSHOT_NOT_SUPPORTED',
966-
'Snapshot is not supported in this context ', TypeError);
967965
E('ERR_ASYNC_CALLBACK', '%s must be a function', TypeError);
968966
E('ERR_ASYNC_TYPE', 'Invalid name for async "type": %s', TypeError);
969967
E('ERR_BROTLI_INVALID_PARAM', '%s is not a valid Brotli parameter', RangeError);

‎src/node_options.cc

-5
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
657657
&EnvironmentOptions::force_repl);
658658
AddAlias("-i", "--interactive");
659659

660-
AddOption("--update-assert-snapshot",
661-
"update assert snapshot files",
662-
&EnvironmentOptions::update_assert_snapshot,
663-
kAllowedInEnvvar);
664-
665660
AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvvar);
666661

667662
AddOption("--tls-keylog",

‎src/node_options.h

-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ class EnvironmentOptions : public Options {
139139
bool preserve_symlinks = false;
140140
bool preserve_symlinks_main = false;
141141
bool prof_process = false;
142-
bool update_assert_snapshot = false;
143142
#if HAVE_INSPECTOR
144143
std::string cpu_prof_dir;
145144
static const uint64_t kDefaultCpuProfInterval = 1000;

‎test/fixtures/assert-snapshot/basic.mjs

-3
This file was deleted.

‎test/fixtures/assert-snapshot/multiple.mjs

-4
This file was deleted.

‎test/fixtures/assert-snapshot/non-existing-name.mjs

-4
This file was deleted.

‎test/fixtures/assert-snapshot/non-existing-name.snapshot

-5
This file was deleted.

‎test/fixtures/assert-snapshot/random.mjs

-11
This file was deleted.

‎test/fixtures/assert-snapshot/random.snapshot

-5
This file was deleted.

‎test/fixtures/assert-snapshot/serialize.mjs

-11
This file was deleted.

‎test/fixtures/assert-snapshot/serialize.snapshot

-11
This file was deleted.

‎test/fixtures/assert-snapshot/single.mjs

-3
This file was deleted.

‎test/fixtures/assert-snapshot/value-changed.mjs

-3
This file was deleted.

‎test/fixtures/assert-snapshot/value-changed.snapshot

-2
This file was deleted.

‎test/parallel/test-assert-snapshot.mjs

-133
This file was deleted.

‎test/parallel/test-runner-run.mjs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,39 +14,39 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
1414
stream.on('test:fail', common.mustNotCall());
1515
stream.on('test:pass', common.mustNotCall());
1616
// eslint-disable-next-line no-unused-vars
17-
for await (const _ of stream); // TODO(MoLow): assert.snapshot
17+
for await (const _ of stream);
1818
});
1919

2020
it('should fail with non existing file', async () => {
2121
const stream = run({ files: ['a-random-file-that-does-not-exist.js'] });
2222
stream.on('test:fail', common.mustCall(1));
2323
stream.on('test:pass', common.mustNotCall());
2424
// eslint-disable-next-line no-unused-vars
25-
for await (const _ of stream); // TODO(MoLow): assert.snapshot
25+
for await (const _ of stream);
2626
});
2727

2828
it('should succeed with a file', async () => {
2929
const stream = run({ files: [join(testFixtures, 'test/random.cjs')] });
3030
stream.on('test:fail', common.mustNotCall());
3131
stream.on('test:pass', common.mustCall(2));
3232
// eslint-disable-next-line no-unused-vars
33-
for await (const _ of stream); // TODO(MoLow): assert.snapshot
33+
for await (const _ of stream);
3434
});
3535

3636
it('should run same file twice', async () => {
3737
const stream = run({ files: [join(testFixtures, 'test/random.cjs'), join(testFixtures, 'test/random.cjs')] });
3838
stream.on('test:fail', common.mustNotCall());
3939
stream.on('test:pass', common.mustCall(4));
4040
// eslint-disable-next-line no-unused-vars
41-
for await (const _ of stream); // TODO(MoLow): assert.snapshot
41+
for await (const _ of stream);
4242
});
4343

4444
it('should run a failed test', async () => {
4545
const stream = run({ files: [testFixtures] });
4646
stream.on('test:fail', common.mustCall(1));
4747
stream.on('test:pass', common.mustNotCall());
4848
// eslint-disable-next-line no-unused-vars
49-
for await (const _ of stream); // TODO(MoLow): assert.snapshot
49+
for await (const _ of stream);
5050
});
5151

5252
it('should support timeout', async () => {
@@ -57,7 +57,7 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
5757
stream.on('test:fail', common.mustCall(2));
5858
stream.on('test:pass', common.mustNotCall());
5959
// eslint-disable-next-line no-unused-vars
60-
for await (const _ of stream); // TODO(MoLow): assert.snapshot
60+
for await (const _ of stream);
6161
});
6262

6363
it('should validate files', async () => {

0 commit comments

Comments
 (0)
Please sign in to comment.