Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Apr 8, 2020
1 parent 08ee622 commit b6e979f
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe('AsyncHooksContextManager', () => {
});

describe('.withAsync/with()', () => {
it('should correctly restore scope', async () => {
it('with() inside withAsync() should correctly restore context', async () => {
const scope1 = '1' as any;
const scope2 = '2' as any;
let done = false;
Expand All @@ -184,23 +184,25 @@ describe('AsyncHooksContextManager', () => {
assert.ok(done);
});

it('should correctly restore scope', done => {
it('withAsync() inside with() should correctly restore conxtext', done => {
const scope1 = '1' as any;
const scope2 = '2' as any;

contextManager.with(scope1, async () => {
assert.strictEqual(contextManager.active(), scope1);
await contextManager.withAsync(scope2, async () => {
assert.strictEqual(contextManager.active(), scope2);
return done();
});
assert.strictEqual(contextManager.active(), scope1);
return done();
});
assert.strictEqual(contextManager.active(), Context.ROOT_CONTEXT);
});

it('should correctly restore scope', done => {
it('not awaited withAsync() inside with() should not restore context', done => {
const scope1 = '1' as any;
const scope2 = '2' as any;
let _done: boolean = false;

contextManager.with(scope1, () => {
assert.strictEqual(contextManager.active(), scope1);
Expand All @@ -210,15 +212,21 @@ describe('AsyncHooksContextManager', () => {
})
.then(() => {
assert.strictEqual(contextManager.active(), scope1);
return done();
_done = true;
});
// in this case the current scope is 2 since we
// didnt waited the withAsync call
assert.strictEqual(contextManager.active(), scope2);
setTimeout(() => {
assert.strictEqual(contextManager.active(), scope1);
assert(_done);
return done();
}, 100);
});
assert.strictEqual(contextManager.active(), Context.ROOT_CONTEXT);
});

it('should correctly restore scope', done => {
it('withAsync() inside a setTimeout inside a with() should correctly restore context', done => {
const scope1 = '1' as any;
const scope2 = '2' as any;

Expand All @@ -237,9 +245,10 @@ describe('AsyncHooksContextManager', () => {
}, 5);
assert.strictEqual(contextManager.active(), scope1);
});
assert.strictEqual(contextManager.active(), Context.ROOT_CONTEXT);
});

it('should correctly restore scope', done => {
it('with() inside a setTimeout inside withAsync() should correctly restore context', done => {
const scope1 = '1' as any;
const scope2 = '2' as any;

Expand Down

0 comments on commit b6e979f

Please sign in to comment.