Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rm redundant root ctx assignment #432

Merged
merged 2 commits into from Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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