Skip to content

Commit 585478a

Browse files
committed
fixup! fix(sandbox): fix illegal invocation errors in early node 10.x releases
1 parent cce0701 commit 585478a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/fixtures/sandbox.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,14 @@ class Sandbox extends EventEmitter {
275275
this[_npm] = this[_test].mock('../../lib/npm.js', this[_mocks])
276276
this[_npm].output = (...args) => this[_output].push(args)
277277
await this[_npm].load()
278+
// in some node versions (later 10.x) our executionAsyncId at this point
279+
// will for some reason appear to have been triggered by a different parent
280+
// so immediately after load, if we can see that we lost our ancestry, we
281+
// fix it here with a hammer
282+
if (chain.get(executionAsyncId()) !== this[_parent]) {
283+
chain.set(executionAsyncId(), this[_parent])
284+
process = this[_proxy]
285+
}
278286

279287
const cmd = this[_npm].argv.shift()
280288
const impl = this[_npm].commands[cmd]
@@ -325,6 +333,14 @@ class Sandbox extends EventEmitter {
325333
this[_npm] = this[_test].mock('../../lib/npm.js', this[_mocks])
326334
this[_npm].output = (...args) => this[_output].push(args)
327335
await this[_npm].load()
336+
// in some node versions (later 10.x) our executionAsyncId at this point
337+
// will for some reason appear to have been triggered by a different parent
338+
// so immediately after load, if we can see that we lost our ancestry, we
339+
// fix it here with a hammer
340+
if (chain.get(executionAsyncId()) !== this[_parent]) {
341+
chain.set(executionAsyncId(), this[_parent])
342+
process = this[_proxy]
343+
}
328344

329345
const impl = this[_npm].commands[command]
330346
if (!impl) {

0 commit comments

Comments
 (0)