| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent abe9052 commit aee01ff
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const { | ||
| 4 | + setDeserializeMainFunction, | ||
| 5 | + isBuildingSnapshot | ||
| 6 | + } = require('v8').startupSnapshot; | ||
| 7 | + | ||
| 8 | + function spawn() { | ||
| 9 | + const { spawnSync, execFileSync, execSync } = require('child_process'); | ||
| 10 | + spawnSync(process.execPath, [ __filename, 'spawnSync' ], { stdio: 'inherit' }); | ||
| 11 | + execSync(`"${process.execPath}" "${__filename}" "execSync"`, { stdio: 'inherit' }); | ||
| 12 | + execFileSync(process.execPath, [ __filename, 'execFileSync' ], { stdio: 'inherit' }); | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + if (process.argv[2] !== undefined) { | ||
| 16 | + console.log('From child process', process.argv[2]); | ||
| 17 | + } else { | ||
| 18 | + spawn(); | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + if (isBuildingSnapshot()) { | ||
| 22 | + setDeserializeMainFunction(() => { | ||
| 23 | + spawn(); | ||
| 24 | + }); | ||
| 25 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,53 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + // This tests that process.cwd() is accurate when | ||
| 4 | + // restoring state from a snapshot | ||
| 5 | + | ||
| 6 | + require('../common'); | ||
| 7 | + const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
| 8 | + const tmpdir = require('../common/tmpdir'); | ||
| 9 | + const fixtures = require('../common/fixtures'); | ||
| 10 | + const assert = require('assert'); | ||
| 11 | + | ||
| 12 | + tmpdir.refresh(); | ||
| 13 | + const blobPath = tmpdir.resolve('snapshot.blob'); | ||
| 14 | + const file = fixtures.path('snapshot', 'child-process-sync.js'); | ||
| 15 | + const expected = [ | ||
| 16 | + 'From child process spawnSync', | ||
| 17 | + 'From child process execSync', | ||
| 18 | + 'From child process execFileSync', | ||
| 19 | + ]; | ||
| 20 | + | ||
| 21 | + { | ||
| 22 | + // Create the snapshot. | ||
| 23 | + spawnSyncAndExitWithoutError(process.execPath, [ | ||
| 24 | + '--snapshot-blob', | ||
| 25 | + blobPath, | ||
| 26 | + '--build-snapshot', | ||
| 27 | + file, | ||
| 28 | + ], { | ||
| 29 | + cwd: tmpdir.path, | ||
| 30 | + }, { | ||
| 31 | + trim: true, | ||
| 32 | + stdout(output) { | ||
| 33 | + assert.deepStrictEqual(output.split('\n'), expected); | ||
| 34 | + return true; | ||
| 35 | + } | ||
| 36 | + }); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + { | ||
| 40 | + spawnSyncAndExitWithoutError(process.execPath, [ | ||
| 41 | + '--snapshot-blob', | ||
| 42 | + blobPath, | ||
| 43 | + file, | ||
| 44 | + ], { | ||
| 45 | + cwd: tmpdir.path, | ||
| 46 | + }, { | ||
| 47 | + trim: true, | ||
| 48 | + stdout(output) { | ||
| 49 | + assert.deepStrictEqual(output.split('\n'), expected); | ||
| 50 | + return true; | ||
| 51 | + } | ||
| 52 | + }); | ||
| 53 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments