fix: file lookup when the nexe binary is in another directory (#1097)
To match the existing (4.x) behaviour, we need to lookup the zipFS for a file path that's relative to the cwd. This is noticeable when the executable is in another directory because the existing path lookups didn't handle this case.
This commit is contained in:
@@ -130,6 +130,21 @@ export class SnapshotZipFS extends BasePortableFakeFS {
|
||||
)
|
||||
)
|
||||
),
|
||||
ppath.resolve(
|
||||
snapshotPP,
|
||||
npath.toPortablePath(
|
||||
npath.relative(npath.fromPortablePath(process.cwd()), npath.fromPortablePath(p))
|
||||
)
|
||||
),
|
||||
ppath.resolve(
|
||||
snapshotPP,
|
||||
npath.toPortablePath(
|
||||
npath.relative(
|
||||
toNamespacedPath(npath.fromPortablePath(process.cwd())),
|
||||
toNamespacedPath(npath.fromPortablePath(p))
|
||||
)
|
||||
)
|
||||
),
|
||||
])
|
||||
)
|
||||
for (const path of pathsToTry) {
|
||||
|
||||
@@ -6,18 +6,32 @@ const cp = require('child_process')
|
||||
|
||||
async function runTests() {
|
||||
const tempdir = await mkdtemp(path.join(os.tmpdir(), 'nexe-integration-tests-'))
|
||||
const secondTempdir = await mkdtemp(path.join(os.tmpdir(), 'nexe-integration-tests-without-executable-'))
|
||||
const executable = path.join(tempdir, path.basename(process.argv[0]))
|
||||
await copyFile(process.argv[0], executable)
|
||||
process.on('beforeExit', () => rimraf.sync(tempdir))
|
||||
cp.spawn(executable,
|
||||
[
|
||||
path.join(tempdir, 'node_modules/mocha/bin/mocha.js'),
|
||||
path.join(tempdir, 'test/integration/tests.integration-spec.js')
|
||||
],
|
||||
{ stdio: ['inherit', 'inherit', 'inherit', 'ipc'], cwd: tempdir }
|
||||
).on('exit', (code) => {
|
||||
process.exitCode = code
|
||||
process.on('beforeExit', () => {
|
||||
rimraf.sync(tempdir)
|
||||
rimraf.sync(secondTempdir)
|
||||
})
|
||||
console.error('Running integration tests with the binary in the current working directory.')
|
||||
spawnExecutable(tempdir, () => {
|
||||
console.error('Running integration tests with the binary in another directory.')
|
||||
spawnExecutable(secondTempdir)
|
||||
})
|
||||
|
||||
function spawnExecutable(cwd, cb) {
|
||||
cp.spawn(executable,
|
||||
[
|
||||
path.join(tempdir, 'node_modules/mocha/bin/mocha.js'),
|
||||
path.join(tempdir, 'test/integration/tests.integration-spec.js')
|
||||
],
|
||||
{ stdio: ['inherit', 'inherit', 'inherit', 'ipc'], cwd }
|
||||
).on('exit', (code) => {
|
||||
process.exitCode = process.exitCode || code
|
||||
|
||||
if(cb) cb()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
runTests()
|
||||
|
||||
Reference in New Issue
Block a user