-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathtest-embedding-snapshot-basic.js
More file actions
50 lines (41 loc) · 1.42 KB
/
test-embedding-snapshot-basic.js
File metadata and controls
50 lines (41 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
// Tests snapshot support in embedded environments.
// See embedtest.cc for the API usage.
const common = require('../common');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const {
spawnSyncAndAssert,
spawnSyncAndExitWithoutError,
} = require('../common/child_process');
const snapshotFixture = fixtures.path('snapshot', 'echo-args.js');
const embedtest = common.resolveBuiltBinary('embedtest');
const buildSnapshotExecArgs = [
`eval(require("fs").readFileSync(${JSON.stringify(snapshotFixture)}, "utf8"))`,
'arg1', 'arg2',
];
const snapshotBlobArgs = [
'--embedder-snapshot-blob', tmpdir.resolve('embedder-snapshot.blob'),
];
const runSnapshotExecArgs = ['arg3', 'arg4'];
tmpdir.refresh();
// Build the snapshot with the default flags.
spawnSyncAndExitWithoutError(
embedtest,
['--', ...buildSnapshotExecArgs, ...snapshotBlobArgs, '--embedder-snapshot-create'],
{ cwd: tmpdir.path });
// Run the snapshot and check the serialized and refreshed argv values.
spawnSyncAndAssert(
embedtest,
['--', ...runSnapshotExecArgs, ...snapshotBlobArgs ],
{ cwd: tmpdir.path },
{
stdout(output) {
assert.deepStrictEqual(JSON.parse(output), {
originalArgv: [embedtest, '__node_anonymous_main', ...buildSnapshotExecArgs],
currentArgv: [embedtest, ...runSnapshotExecArgs],
});
return true;
},
});