Commit 0598e2e

Anton Golub <antongolub@antongolub.com>
2022-06-08 14:56:59
fix: rm redundant root ctx assignment (#432)
* fix: rm redundant root ctx assignment * chore: revert symbol export
v6
1 parent 3b6f856
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')
 })