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

Option to turn off strict mode #2198

Closed
4 tasks done
Charuru opened this issue Oct 23, 2022 · 8 comments · May be fixed by #3995
Closed
4 tasks done

Option to turn off strict mode #2198

Charuru opened this issue Oct 23, 2022 · 8 comments · May be fixed by #3995

Comments

@Charuru
Copy link

Charuru commented Oct 23, 2022

Clear and concise description of the problem

Currently, strict mode is forced on instead of being an option, making it not usable for certain types of codebases.

Suggested solution

config toggle to turn off strict mode.

Alternative

No response

Additional context

No response

Validations

@sheremet-va
Copy link
Member

Your code is treated as ESM. You cannot disable strict mode in ESM.

@Charuru
Copy link
Author

Charuru commented Oct 24, 2022

What do you think about having alternative options to include setupFiles?

@sheremet-va
Copy link
Member

What do you mean?

@Charuru
Copy link
Author

Charuru commented Oct 24, 2022

Copy the setup files code on top of the test files without it being a module.

@sheremet-va
Copy link
Member

Test files are also treated as modules. Every file is treated as a module

@Charuru
Copy link
Author

Charuru commented Oct 25, 2022

@sheremet-va I guess what I'm asking is how difficult would it be to have an option to not do that?

For example karma puts setup files in <script> tags. But karma is very slow.

Or maybe it's easier to copy the contents of setup files to into the same module as the test file? I feel like this should definitely be possible.

@ncoder
Copy link

ncoder commented Jun 16, 2023

Yes please. want this.

I had to patch my client.mjs:

-    const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
+    const codeDefinition = `async (${Object.keys(context).join(",")})=>{{`;

@sheremet-va
Copy link
Member

Vitest runs code in strict mode by default because it assumes the file follows ESM spec. We won't add an escape hatch for non-strict mode because we don't support CJS tests.

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants