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

Is it possible to use k6chaijs with async function? For example in browser tests? #15

Closed
aswarcewicz opened this issue Jul 13, 2024 · 1 comment

Comments

@aswarcewicz
Copy link

I'd like to use k6chaijs with browser k6 module, but I have observed that messages are printed in wrong order.

For example this test function:

export default () => {
    describe('New page verifier', async () => {
        const page = await browser.newPage();
        try {
            expect(page, "page").to.be.null;
        } finally {
            await page.close();
        }
    })
}

Prints output like this:


     ✗ expected page to be null
      ↳  0% — ✓ 0 / ✗ 1

     █ New page verifier

   ✗ checks...............: 0.00% ✓ 0        ✗ 1  
     data_received........: 0 B   0 B/s
     data_sent............: 0 B   0 B/s

Text from describe function is after assertion what is not expected

@bdshadow
Copy link

since describe is the wrapper of a group, then it probably has the same issues with async. Check the big red warning here: https://grafana.com/docs/k6/latest/javascript-api/k6/group/:

WARNING
Avoid using group with async functions or asynchronous code. If you do, k6 might apply tags in a way that is unreliable or unintuitive.
If you start promise chains or even use await within group, some code within the group will be waited for and tagged with the proper group tag, but others won’t be.
To avoid confusion, async functions are forbidden as group() arguments. This still lets users make and chain promises within a group, but doing so is unsupported and not recommended.
For more information, refer to k6 #2728, which tracks possible solutions and provides detailed explanations.

P.S
I'm not a k6 developer, just bumped into the same issue while using it

@aswarcewicz aswarcewicz closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2024
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

2 participants