-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fixture do not work when esbuild target is set to ES2015, ES2016 or esbuild.supported.['async-await'] = false #6042
Comments
Interesting point, but I wonder what is the point of setting |
@sheremet-va But a valid case would be that the user uses Angular with vitest. Angular can not use async/await natively if zone.js is used
In this case the user must set esbuild to ES2015, ES2016 (or vitest/packages/runner/src/fixture.ts Lines 212 to 216 in 200a434
Edit the following config also won't work with fixtures:
That being said, angular is moving away from Zone.js for those kind of reasons. |
Then I think we can just support esbuild's |
@hi-ogawa Thanks for working on this! I tried it out, but there are still cases that break. For example, const test = base.extend<Fixture>({
simple: async ({}, use) => {
await use("simple");
},
async method ({ simple }, use) {
await use("method:" + simple);
},
});
|
@kasperpeulen Hmm, interesting. I thought we only supported arrow functions for fixtures, so haven't considered that case. I've only seen arrow functions, but the doc has this too https://vitest.dev/guide/test-context.html#fixture-initialization, which probably also breaks. Let me check it again. |
Describe the bug
I'm not 100% sure if this is a bug or by design.
If you set the vite config to target ES2015, async/await will be transpiled and Vitest can not analyse the
fn.toString()
call correctly to determine where the fixture depends on.With the following test:
Gives the following error:
See the reproduction.
In storybook we are considering also adopting fixture, and we started to use some similar as vitest to implement the mount RFC:
storybookjs/storybook#27389
Which you can see as the first fixture.
However, we found that our fixture code breaks in Angular, which always transpiles away async/await when Zone.js is used.
When looking at the output code of esbuild, the destructure gets kind of preserved:
gets transpiled to:
So, it might be possible to improve the regex to cover to extract the fixture dependency information reliably.
My general feeling is that it might be just to fragile, but I am wondering what you here think about this.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-tdu2jo?file=test%2Fbasic.test.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: