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

Node.js AsyncHooks support: BeforeEach increase asyncId for each test #3

Open
hadarbmdev opened this issue May 10, 2020 · 0 comments
Open

Comments

@hadarbmdev
Copy link

🐛 Bug Report

When importing (only!) the package, and trying to set context based on
asyncHooks.executionAsyncId();
in BeforeEach
the returned executionId is X, and in the upcoming test (right after the beforeEach), the returned
asyncHooks.executionAsyncId();
is X+1.

this is the resolution for the issue why getExecutionContext() returns undefined, although setExecutionContext({test:1}) was called in beforeEach, meaning before the test.

To Reproduce

uncomment the line:
const contextProvider = require('@mondaydotcomorg/node-execution-context');
`const asyncHooks = require('async_hooks');
const contextProvider = require('@mondaydotcomorg/node-execution-context');

let asyncIdBefore: number;
describe('AsyncHook test', () => {

beforeEach(() => {
    asyncIdBefore = asyncHooks.executionAsyncId();
    console.log(`asyncIdBefore: ${asyncIdBefore}`);
    // contextProvider.createExecutionContext({test: 1});

});

test('test if asynchook was increased', () => {
   const asyncId = asyncHooks.executionAsyncId();
   console.log(`asyncId: ${asyncId}`);
   expect(asyncId).toEqual(asyncIdBefore);
  // expect(contextProvider.getExecutionContext()).toMatchObject({test: 1});
});

});
`

Expected behavior

jest BeforeEach and the test should share the same context create with setExecutionContext in beforeEach.

envinfo

Node version: v10.15.3
"@mondaydotcomorg/node-execution-context": "^1.0.4",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant