Skip to content

Commit

Permalink
fix: rm redundant root ctx assignment (#432)
Browse files Browse the repository at this point in the history
* fix: rm redundant root ctx assignment

* chore: revert symbol export
  • Loading branch information
antongolub committed Jun 8, 2022
1 parent 3b6f856 commit 0598e2e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/context.ts
Expand Up @@ -47,7 +47,6 @@ export function getCtx() {
}

export function setRootCtx(ctx: Options) {
storage.enterWith(ctx)
root = ctx
}

Expand Down
8 changes: 6 additions & 2 deletions src/core.ts
Expand Up @@ -89,8 +89,12 @@ export class ProcessPromise extends Promise<ProcessOutput> {
readonly ctx: Context
constructor(cb: (resolve: Function, reject?: Function) => void) {
super(cb)
this.ctx = {...getCtx()}
Object.defineProperty(this, 'ctx', { value: this.ctx, writable: false, configurable: false })
this.ctx = { ...getCtx() }
Object.defineProperty(this, 'ctx', {
value: this.ctx,
writable: false,
configurable: false,
})
}

get stdin() {
Expand Down
17 changes: 17 additions & 0 deletions test/experimental.test.js
Expand Up @@ -111,6 +111,23 @@ test('ctx() provides isolates running scopes', async () => {
$.verbose = false
})

test('bound ctx is attached to Promise', async () => {
const kResourceStoreSymbol = Object.getOwnPropertySymbols(
new Promise(() => {})
)[2]
assert.is(new Promise(() => {})[kResourceStoreSymbol], undefined)

await ctx(async ($) => {
await ctx(async ($) => {
assert.is(new Promise(() => {})[kResourceStoreSymbol], $)
})

assert.is(new Promise(() => {})[kResourceStoreSymbol], $)
})

assert.is(new Promise(() => {})[kResourceStoreSymbol], undefined)
})

test('log() API is available', () => {
assert.ok(typeof log === 'function')
})
Expand Down

0 comments on commit 0598e2e

Please sign in to comment.