GeezerVison is showing github.com — test: test syncrhnous methods of child_process in snapshot · nodejs/node@aee01ff
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboard +25Lines changed: 25 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +} |
Collapse file Copy file name to clipboard +53Lines changed: 53 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +} |
|