Skip to content

Commit

Permalink
assert: remove assert.snapshot
Browse files Browse the repository at this point in the history
PR-URL: #46112
Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
  • Loading branch information
MoLow authored and RafaelGSS committed Jan 20, 2023
1 parent e222a2f commit def3694
Show file tree
Hide file tree
Showing 22 changed files with 6 additions and 405 deletions.
44 changes: 0 additions & 44 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -2093,48 +2093,6 @@ argument, then `error` is assumed to be omitted and the string will be used for
example in [`assert.throws()`][] carefully if using a string as the second
argument gets considered.

## `assert.snapshot(value, name)`

<!-- YAML
added: v18.8.0
-->

> Stability: 1 - Experimental
* `value` {any} the value to snapshot.
* `name` {string} the name of the snapshot.
* Returns: {Promise}

Reads the `name` snapshot from a file and compares `value` to the snapshot.
`value` is serialized with [`util.inspect()`][]. If the value is not strictly
equal to the snapshot, `assert.snapshot()` returns a rejected `Promise` with an
[`AssertionError`][].

The snapshot filename uses the same basename as the application's main
entrypoint with a `.snapshot` extension. If the snapshot file does not exist,
it is created. The [`--update-assert-snapshot`][] command line flag can be used
to force the update of an existing snapshot.

```mjs
import assert from 'node:assert/strict';

// Assuming that the application's main entrypoint is app.mjs, this reads the
// 'snapshotName' snapshot from app.snapshot and strictly compares its value
// to `util.inspect('value')`.
await assert.snapshot('value', 'snapshotName');
```

```cjs
const assert = require('node:assert/strict');

(async () => {
// Assuming that the application's main entrypoint is app.js, this reads the
// 'snapshotName' snapshot from app.snapshot and strictly compares its value
// to `util.inspect('value')`.
await assert.snapshot('value', 'snapshotName');
})();
```

## `assert.strictEqual(actual, expected[, message])`

<!-- YAML
Expand Down Expand Up @@ -2571,7 +2529,6 @@ argument.
[Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript
[Object.prototype.toString()]: https://tc39.github.io/ecma262/#sec-object.prototype.tostring
[`!=` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality
[`--update-assert-snapshot`]: cli.md#--update-assert-snapshot
[`===` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality
[`==` operator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality
[`AssertionError`]: #class-assertassertionerror
Expand Down Expand Up @@ -2603,6 +2560,5 @@ argument.
[`process.on('exit')`]: process.md#event-exit
[`tracker.calls()`]: #trackercallsfn-exact
[`tracker.verify()`]: #trackerverify
[`util.inspect()`]: util.md#utilinspectobject-options
[enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties
[prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
10 changes: 0 additions & 10 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1513,14 +1513,6 @@ occurs. One of the following modes can be chosen:
If a rejection happens during the command line entry point's ES module static
loading phase, it will always raise it as an uncaught exception.

### `--update-assert-snapshot`

<!-- YAML
added: v18.8.0
-->

Updates snapshot files used by [`assert.snapshot()`][].

### `--use-bundled-ca`, `--use-openssl-ca`

<!-- YAML
Expand Down Expand Up @@ -1943,7 +1935,6 @@ Node.js options that are allowed are:
* `--trace-warnings`
* `--track-heap-objects`
* `--unhandled-rejections`
* `--update-assert-snapshot`
* `--use-bundled-ca`
* `--use-largepages`
* `--use-openssl-ca`
Expand Down Expand Up @@ -2324,7 +2315,6 @@ done
[`NO_COLOR`]: https://no-color.org
[`SlowBuffer`]: buffer.md#class-slowbuffer
[`YoungGenerationSizeFromSemiSpaceSize`]: https://chromium.googlesource.com/v8/v8.git/+/refs/tags/10.3.129/src/heap/heap.cc#328
[`assert.snapshot()`]: assert.md#assertsnapshotvalue-name
[`dns.lookup()`]: dns.md#dnslookuphostname-options-callback
[`dns.setDefaultResultOrder()`]: dns.md#dnssetdefaultresultorderorder
[`dnsPromises.lookup()`]: dns.md#dnspromiseslookuphostname-options
Expand Down
7 changes: 0 additions & 7 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,6 @@ A special type of error that can be triggered whenever Node.js detects an
exceptional logic violation that should never occur. These are raised typically
by the `node:assert` module.

<a id="ERR_ASSERT_SNAPSHOT_NOT_SUPPORTED"></a>

### `ERR_ASSERT_SNAPSHOT_NOT_SUPPORTED`

An attempt was made to use `assert.snapshot()` in an environment that
does not support snapshots, such as the REPL, or when using `node --eval`.

<a id="ERR_ASYNC_CALLBACK"></a>

### `ERR_ASYNC_CALLBACK`
Expand Down
3 changes: 0 additions & 3 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,6 @@ Track heap object allocations for heap snapshots.
.It Fl -unhandled-rejections=mode
Define the behavior for unhandled rejections. Can be one of `strict` (raise an error), `warn` (enforce warnings) or `none` (silence warnings).
.
.It Fl -update-assert-snapshot
Updates snapshot files used by `assert.snapshot()`.
.
.It Fl -use-bundled-ca , Fl -use-openssl-ca
Use bundled Mozilla CA store as supplied by current Node.js version or use OpenSSL's default CA store.
The default store is selectable at build-time.
Expand Down
3 changes: 0 additions & 3 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,6 @@ assert.doesNotMatch = function doesNotMatch(string, regexp, message) {

assert.CallTracker = CallTracker;

const snapshot = require('internal/assert/snapshot');
assert.snapshot = snapshot;

/**
* Expose a strict only variant of assert.
* @param {...any} args
Expand Down
129 changes: 0 additions & 129 deletions lib/internal/assert/snapshot.js

This file was deleted.

2 changes: 0 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,6 @@ module.exports = {
E('ERR_AMBIGUOUS_ARGUMENT', 'The "%s" argument is ambiguous. %s', TypeError);
E('ERR_ARG_NOT_ITERABLE', '%s must be iterable', TypeError);
E('ERR_ASSERTION', '%s', Error);
E('ERR_ASSERT_SNAPSHOT_NOT_SUPPORTED',
'Snapshot is not supported in this context ', TypeError);
E('ERR_ASYNC_CALLBACK', '%s must be a function', TypeError);
E('ERR_ASYNC_TYPE', 'Invalid name for async "type": %s', TypeError);
E('ERR_BROTLI_INVALID_PARAM', '%s is not a valid Brotli parameter', RangeError);
Expand Down
5 changes: 0 additions & 5 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,6 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
&EnvironmentOptions::force_repl);
AddAlias("-i", "--interactive");

AddOption("--update-assert-snapshot",
"update assert snapshot files",
&EnvironmentOptions::update_assert_snapshot,
kAllowedInEnvvar);

AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvvar);

AddOption("--tls-keylog",
Expand Down
1 change: 0 additions & 1 deletion src/node_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class EnvironmentOptions : public Options {
bool preserve_symlinks = false;
bool preserve_symlinks_main = false;
bool prof_process = false;
bool update_assert_snapshot = false;
#if HAVE_INSPECTOR
std::string cpu_prof_dir;
static const uint64_t kDefaultCpuProfInterval = 1000;
Expand Down
3 changes: 0 additions & 3 deletions test/fixtures/assert-snapshot/basic.mjs

This file was deleted.

4 changes: 0 additions & 4 deletions test/fixtures/assert-snapshot/multiple.mjs

This file was deleted.

4 changes: 0 additions & 4 deletions test/fixtures/assert-snapshot/non-existing-name.mjs

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/assert-snapshot/non-existing-name.snapshot

This file was deleted.

11 changes: 0 additions & 11 deletions test/fixtures/assert-snapshot/random.mjs

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/assert-snapshot/random.snapshot

This file was deleted.

11 changes: 0 additions & 11 deletions test/fixtures/assert-snapshot/serialize.mjs

This file was deleted.

11 changes: 0 additions & 11 deletions test/fixtures/assert-snapshot/serialize.snapshot

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/assert-snapshot/single.mjs

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/assert-snapshot/value-changed.mjs

This file was deleted.

2 changes: 0 additions & 2 deletions test/fixtures/assert-snapshot/value-changed.snapshot

This file was deleted.

Loading

0 comments on commit def3694

Please sign in to comment.