|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +// Tests node::EmbedderSnapshotData::FromFile() works correctly. |
| 4 | +// The snapshot is created in embedtest.cc. |
| 5 | + |
| 6 | +constcommon=require('../common'); |
| 7 | +consttmpdir=require('../common/tmpdir'); |
| 8 | +constassert=require('assert'); |
| 9 | +constfixtures=require('../common/fixtures'); |
| 10 | + |
| 11 | +const{ |
| 12 | + spawnSyncAndAssert, |
| 13 | + spawnSyncAndExitWithoutError, |
| 14 | +}=require('../common/child_process'); |
| 15 | + |
| 16 | +constsnapshotFixture=fixtures.path('snapshot','echo-args.js'); |
| 17 | +constembedtest=common.resolveBuiltBinary('embedtest'); |
| 18 | + |
| 19 | +constbuildSnapshotExecArgs=[ |
| 20 | +`eval(require("fs").readFileSync(${JSON.stringify(snapshotFixture)}, "utf8"))`, |
| 21 | +'arg1','arg2', |
| 22 | +]; |
| 23 | +constsnapshotBlobArgs=[ |
| 24 | +'--embedder-snapshot-blob',tmpdir.resolve('embedder-snapshot.blob'), |
| 25 | +]; |
| 26 | + |
| 27 | +construnSnapshotExecArgs=['arg3','arg4']; |
| 28 | + |
| 29 | +tmpdir.refresh(); |
| 30 | + |
| 31 | +// Build the snapshot with the --embedder-snapshot-as-file flag. |
| 32 | +spawnSyncAndExitWithoutError( |
| 33 | +embedtest, |
| 34 | +['--', ...buildSnapshotExecArgs, ...snapshotBlobArgs,'--embedder-snapshot-as-file','--embedder-snapshot-create'], |
| 35 | +{cwd: tmpdir.path}); |
| 36 | + |
| 37 | +// Run the snapshot and check the serialized and refreshed argv values. |
| 38 | +spawnSyncAndAssert( |
| 39 | +embedtest, |
| 40 | +['--', ...runSnapshotExecArgs, ...snapshotBlobArgs], |
| 41 | +{cwd: tmpdir.path}, |
| 42 | +{ |
| 43 | +stdout(output){ |
| 44 | +assert.deepStrictEqual(JSON.parse(output),{ |
| 45 | +originalArgv: [embedtest,'__node_anonymous_main', ...buildSnapshotExecArgs], |
| 46 | +currentArgv: [embedtest, ...runSnapshotExecArgs], |
| 47 | +}); |
| 48 | +returntrue; |
| 49 | +}, |
| 50 | +}); |
0 commit comments