Commit 0598e2e
Changed files (3)
src
test
src/context.ts
@@ -47,7 +47,6 @@ export function getCtx() {
}
export function setRootCtx(ctx: Options) {
- storage.enterWith(ctx)
root = ctx
}
src/core.ts
@@ -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() {
test/experimental.test.js
@@ -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')
})