forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: reset the cwd cache before execution
PR-URL: nodejs#49684 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { | ||
setDeserializeMainFunction, | ||
} = require('v8').startupSnapshot; | ||
|
||
// To make sure the cwd is present in the cache | ||
process.cwd(); | ||
|
||
setDeserializeMainFunction(() => { | ||
console.log(process.cwd()); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
'use strict'; | ||
|
||
// This tests that process.cwd() is accurate when | ||
// restoring state from a snapshot | ||
|
||
require('../common'); | ||
const { spawnSyncAndExitWithoutError } = require('../common/child_process'); | ||
const tmpdir = require('../common/tmpdir'); | ||
const fixtures = require('../common/fixtures'); | ||
const fs = require('fs'); | ||
|
||
tmpdir.refresh(); | ||
const blobPath = tmpdir.resolve('snapshot.blob'); | ||
const file = fixtures.path('snapshot', 'cwd.js'); | ||
|
||
const subdir = tmpdir.resolve('foo'); | ||
fs.mkdirSync(subdir); | ||
|
||
{ | ||
// Create the snapshot. | ||
spawnSyncAndExitWithoutError(process.execPath, [ | ||
'--snapshot-blob', | ||
blobPath, | ||
'--build-snapshot', | ||
file, | ||
], { | ||
cwd: tmpdir.path, | ||
encoding: 'utf8' | ||
}, { | ||
status: 0, | ||
}); | ||
} | ||
|
||
{ | ||
spawnSyncAndExitWithoutError(process.execPath, [ | ||
'--snapshot-blob', | ||
blobPath, | ||
file, | ||
], { | ||
cwd: subdir, | ||
encoding: 'utf8' | ||
}, { | ||
status: 0, | ||
trim: true, | ||
stdout: subdir, | ||
}); | ||
} |