diff --git a/asyncforge.js b/asyncforge.js index 295a96b..c8dc208 100644 --- a/asyncforge.js +++ b/asyncforge.js @@ -2,7 +2,7 @@ const { AsyncLocalStorage } = require('node:async_hooks') -const asyncLocalStorage = new AsyncLocalStorage(); +const asyncLocalStorage = new AsyncLocalStorage() function start (config) { const store = Object.create(null) diff --git a/test/basic.test.js b/test/basic.test.js index f2aa99e..2b35e23 100644 --- a/test/basic.test.js +++ b/test/basic.test.js @@ -9,6 +9,10 @@ const tspl = require('@matteo.collina/tspl') test('start and forge', async (t) => { const { a, b } = require('./fixture/basic') + start({ + foo: 'bar' + }) + assert.deepEqual(a(), { value: 'bar' }) assert.equal(a(), a()) assert.deepEqual(b(), { @@ -20,6 +24,22 @@ test('start and forge', async (t) => { await immediate() assert.deepEqual(a(), { value: 'bar' }) + + start({ + foo: 'baz' + }) + + assert.deepEqual(a(), { value: 'baz' }) + assert.equal(a(), a()) + assert.deepEqual(b(), { + fromA: { + value: 'baz' + } + }) + + await immediate() + + assert.deepEqual(a(), { value: 'baz' }) }) test('start and forge with different config', async (t) => { diff --git a/test/fixture/basic/index.js b/test/fixture/basic/index.js index c30e2d1..9531bfb 100644 --- a/test/fixture/basic/index.js +++ b/test/fixture/basic/index.js @@ -3,12 +3,6 @@ const a = require('./a') const b = require('./b') -const { start } = require('../../../') - -start({ - foo: 'bar' -}) - module.exports = { a, b diff --git a/test/memo.test.js b/test/memo.test.js index 504068d..6f74fb9 100644 --- a/test/memo.test.js +++ b/test/memo.test.js @@ -1,9 +1,7 @@ 'use strict' const { test } = require('node:test') -const assert = require('node:assert/strict') -const { start, forge, memo } = require('../') -const { setImmediate: immediate } = require('node:timers/promises') +const { start, memo } = require('../') const tspl = require('@matteo.collina/tspl') test('memo', async (t) => {