Skip to content

Commit 39e5f28

Browse files
committed
Skip snapshot tests when snapshots are disabled
These tests create node snapshots even when node snapshots are disabled. Node snapshots don't work at the moment because FunctionTemplateInfo objects with fast API callbacks are put into the snapshot, but this causes security issues.
1 parent 8209a15 commit 39e5f28

26 files changed

Lines changed: 63 additions & 21 deletions

test/common/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const hasCrypto = Boolean(process.versions.openssl) &&
6868
!process.env.NODE_SKIP_CRYPTO;
6969

7070
const hasInspector = Boolean(process.features.inspector);
71+
const hasSnapshot = Boolean(process.features.node_use_node_snapshot);
7172
const hasSQLite = Boolean(process.versions.sqlite);
7273

7374
const hasQuic = hasCrypto && !!process.features.quic;
@@ -743,6 +744,13 @@ function skipIfInspectorDisabled() {
743744
}
744745
}
745746

747+
function skipIfSnapshotDisabled() {
748+
console.log("Snapshot: ", hasSnapshot);
749+
if (!hasSnapshot) {
750+
skip('Node snapshot is disabled');
751+
}
752+
}
753+
746754
function skipIf32Bits() {
747755
if (bits < 64) {
748756
skip('The tested feature is not available in 32bit builds');
@@ -972,6 +980,7 @@ const common = {
972980
hasCrypto,
973981
hasQuic,
974982
hasInspector,
983+
hasSnapshot,
975984
hasSQLite,
976985
invalidArgTypeHelper,
977986
isAlive,
@@ -1003,6 +1012,7 @@ const common = {
10031012
skipIf32Bits,
10041013
skipIfEslintMissing,
10051014
skipIfInspectorDisabled,
1015+
skipIfSnapshotDisabled,
10061016
skipIfSQLiteMissing,
10071017
spawnPromisified,
10081018
sleepSync,

test/common/snapshot.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
'use strict';
22

3+
const common = require('../common');
4+
common.skipIfSnapshotDisabled();
5+
36
const tmpdir = require('../common/tmpdir');
47
const { spawnSync } = require('child_process');
58
const fs = require('fs');

test/parallel/test-inspect-address-in-use.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22
const common = require('../common');
33
common.skipIfInspectorDisabled();
4+
common.skipIfSnapshotDisabled();
45

56
const { spawnSync } = require('child_process');
67
const { createServer } = require('http');

test/parallel/test-snapshot-api.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
// This tests snapshot JS API using the example in the docs.
44

5-
require('../common');
5+
const common = require('../common');
6+
common.skipIfSnapshotDisabled();
67
const assert = require('assert');
78
const tmpdir = require('../common/tmpdir');
89
const fixtures = require('../common/fixtures');

test/parallel/test-snapshot-argv1.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// This tests snapshot JS API using the example in the docs.
44

5-
require('../common');
5+
const common = require('../common');
6+
common.skipIfSnapshotDisabled();
7+
68
const assert = require('assert');
79
const { spawnSync } = require('child_process');
810
const tmpdir = require('../common/tmpdir');

test/parallel/test-snapshot-basic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// This tests that user land snapshots works when the instance restored from
44
// the snapshot is launched with --help, --check
55

6-
require('../common');
6+
const common = require('../common');
7+
common.skipIfSnapshotDisabled();
78
const assert = require('assert');
89
const tmpdir = require('../common/tmpdir');
910
const fixtures = require('../common/fixtures');

test/parallel/test-snapshot-child-process-sync.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// This tests that process.cwd() is accurate when
44
// restoring state from a snapshot
55

6-
const { isInsideDirWithUnusualChars } = require('../common');
6+
const { isInsideDirWithUnusualChars, skipIfSnapshotDisabled } = require('../common');
7+
skipIfSnapshotDisabled();
78
const { spawnSyncAndAssert } = require('../common/child_process');
89
const tmpdir = require('../common/tmpdir');
910
const fixtures = require('../common/fixtures');

test/parallel/test-snapshot-cjs-main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// This tests that user land snapshots works when the instance restored from
44
// the snapshot is launched as a CJS module.
55

6-
require('../common');
6+
const common = require('../common');
7+
common.skipIfSnapshotDisabled();
78
const assert = require('assert');
89
const { spawnSync } = require('child_process');
910
const tmpdir = require('../common/tmpdir');

test/parallel/test-snapshot-config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
// This tests --build-snapshot-config.
44

5-
require('../common');
5+
const common = require('../common');
6+
common.skipIfSnapshotDisabled();
7+
68
const assert = require('assert');
79
const {
810
spawnSyncAndAssert,

test/parallel/test-snapshot-console.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
const common = require('../common');
66
common.skipIfInspectorDisabled();
7+
common.skipIfSnapshotDisabled();
78

89
const assert = require('assert');
910
const { spawnSync } = require('child_process');

0 commit comments

Comments
 (0)