Skip to content

Commit

Permalink
fixup! fix(sandbox): fix illegal invocation errors in early node 10.x…
Browse files Browse the repository at this point in the history
… releases
  • Loading branch information
nlf committed Aug 25, 2021
1 parent cce0701 commit 585478a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/fixtures/sandbox.js
Expand Up @@ -275,6 +275,14 @@ class Sandbox extends EventEmitter {
this[_npm] = this[_test].mock('../../lib/npm.js', this[_mocks])
this[_npm].output = (...args) => this[_output].push(args)
await this[_npm].load()
// in some node versions (later 10.x) our executionAsyncId at this point
// will for some reason appear to have been triggered by a different parent
// so immediately after load, if we can see that we lost our ancestry, we
// fix it here with a hammer
if (chain.get(executionAsyncId()) !== this[_parent]) {
chain.set(executionAsyncId(), this[_parent])
process = this[_proxy]
}

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

const impl = this[_npm].commands[command]
if (!impl) {
Expand Down

0 comments on commit 585478a

Please sign in to comment.