Repository navigation
test: [M3-7820] - Suppress Cypress "MODULE_LEVEL_DIRECTIVE" and "SOURCEMAP_ERROR" warnings #10239
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@linode/manager": Tests | ||
| --- | ||
|
|
||
| Suppress Rollup warnings during Cypress tests ([#10239](https://github.com/linode/manager/pull/10239)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,36 @@ | ||
| import react from '@vitejs/plugin-react-swc'; | ||
| import svgr from 'vite-plugin-svgr'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this package related?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I imported both of these plugins to mirror what we're doing in Cloud's Vite config.
|
||
| import { defineConfig } from 'vite'; | ||
| import { URL } from 'url'; | ||
|
|
||
| // ESM-friendly alternative to `__dirname`. | ||
| const DIRNAME = new URL('.', import.meta.url).pathname; | ||
|
|
||
| export default defineConfig({ | ||
| plugins: [react(), svgr({ exportAsDefault: true })], | ||
| build: { | ||
| rollupOptions: { | ||
| // Suppress "SOURCEMAP_ERROR" warnings. | ||
| // This is necessary because MUI contains React SSR "use client" module-level | ||
| // directive, and Rollup does not support module-level directives. | ||
| // `vite-plugin-react` and `vite-plugin-react-swc` both silence this warning, | ||
| // but the inability to handle module-level directives also causes Sourcemap | ||
| // output errors. The warnings for this are not suppressed by Vite plugins, | ||
| // so we need to suppress them ourselves. | ||
| // | ||
| // See also: | ||
| // - https://github.com/vitejs/vite-plugin-react/blob/7f53c63/packages/plugin-react/src/index.ts#L303 | ||
| // - https://github.com/vitejs/vite-plugin-react-swc/blob/53ecc44/src/index.ts#L262 | ||
| // - https://github.com/rollup/rollup/issues/4699#issuecomment-1299770973 | ||
| // - https://github.com/vitejs/vite/issues/15012#issuecomment-1815854072 | ||
| onwarn(warning, defaultHandler) { | ||
| if (warning.code === 'SOURCEMAP_ERROR') { | ||
| return; | ||
| } | ||
|
Comment on lines
+27
to
+29
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason not to suppress
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the I appreciate these good questions, @hkhalil-akamai! |
||
| defaultHandler(warning); | ||
| }, | ||
| }, | ||
| }, | ||
| resolve: { | ||
| alias: { | ||
| '@src': `${DIRNAME}/../src`, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any tradeoffs to using
swc-- i.e., build differences between e2e and prod?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but only because Cloud also uses
@vitejs/plugin-react-swc!I think we opted to use that for performance reasons (swc is fast), and so I used it here too, but both
@vitejs/plugin-reactand@vitejs/plugin-react-swccontain the exact same log suppression logic (so either would really work here for the purpose of this ticket).One thing to note is that this Vite config is only used when building the Cypress *.spec.ts files -- Cloud itself is always built using the Vite config in
packages/manager, so while consistency between the configs is good, we're not at risk of ending up in a situation where e.g. Cloud is built differently when running our Cypress tests, resulting in bugs being present (or absent) in our tests but not in Production or vice-versa.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh didn't know that. Thanks for the explanation.