-
Notifications
You must be signed in to change notification settings - Fork 3.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
🐛 dev server vite 2.2.3 dynamic import are not using path aliases #22390
Comments
Hi, thanks for the bug report. Quasar is super nice to work with. Just to clarify, you want to do something like: export default defineConfig({
plugins: [vue()],
resolve: {
alias: {
'@': 'src'
}
}
}) And then type |
The path alias yes but the spec files are found by cypress itself, it is about spec files |
Adding a bit more context: @hinogi is trying to add support for Cypress 10 into our Cypress App Extension |
Hello @IlCallo! Long time no talk. I looked at the draft PR but I think I'm still missing something.
Can you point me some code that doesn't work (or even make a minimal reproduction)? I looked at the draft PR but I do not see any obvious
What should I do to "and a path alias for src pointing to src"? I think I am missing something. |
That problem also covers imports in spec files because those paths get used in dynamic imports as is disregarding present path aliases. |
I understand now. A minimal reproduction would be very useful for starting debugging. |
Seems this is also documented as a Vite problem: vitejs/vite#7611 (comment) |
From what's written there, they fixed it into Vite 3 branch, but Quasar is still on Vite 2 🤔 |
As far as I can see it, the issue is not fixed in vite 3. |
I'm taking a shot with the Cypress 10 migration and I can understand why @hinogi got stuck Quasar did quite some stuff behind the curtains to provide the best DX possible, and this involved using many packages which version has been bumped and are now included into cypress binary ( He forgot to bump those, so that's probably the problem here, but that's understandable: I saw there are A LOT of things we'll need to change/automate for our users during the migration, I barely lost myself too into all of them I think I almost got to a working repo, after adapting to the new quasarframework/quasar-testing@ @lmiller1990 any hints?
If you don't know right away, no problem, I can somehow dig into Cypress code and find it out by myself |
Looks like you should pass in an object, so the result: https://github.com/cypress-io/cypress/blob/develop/system-tests/project-fixtures/next/cypress.config.js#L9-L14
Good question, I actually have no idea, but why would you want to declare
I think this should work just fine. Eg: import { devServer } from '@cypress/webpack-dev-server'
export default defineConfig({
component: {
devServer: async (devServerOptions) => devServer({
...devServerOptions,
framework: 'vue',
}),
}
}) If any of these things don't work how you expect, we can definitely and quickly make non-breaking changes to support frameworks like Quasar. Making it easy to add Cypress to frameworks is important. |
We extract the webpack and Vite config from Quasar, but to detect which bundler we're using we need to import the package.json via an async call Would it be too much of an effort to support an async config for cypress, or at least to support a promise for |
I made some progress with the suggestions of @lmiller1990 This seems to work so far, now @IlCallo has to figure out some stuff for me I guess :D import { defineConfig } from 'cypress';
import { quasarWebpackConfig } from '@quasar/quasar-app-extension-testing-e2e-cypress/cct-dev-server';
import { devServer } from '@cypress/webpack-dev-server';
export default defineConfig({
fixturesFolder: 'test/cypress/fixtures',
screenshotsFolder: 'test/cypress/screenshots',
videosFolder: 'test/cypress/videos',
video: true,
e2e: {
baseUrl: 'http://localhost:8080/',
specPattern: 'test/cypress/integration/**/*.cy.{js,jsx,ts,tsx}',
supportFile: 'test/cypress/support/e2e.ts',
},
component: {
supportFile: 'test/cypress/support/component.ts',
specPattern: 'src/**/*.spec.{js,jsx,ts,tsx}',
devServer: async (devServerOptions) => {
return devServer({
...devServerOptions,
framework: 'vue',
webpackConfig: await quasarWebpackConfig(),
});
},
indexHtmlFile: 'test/cypress/support/component-index.html',
},
}); |
Nice, lmk if you need anything on my end. |
This would help us, as we wouldn't need to add |
I am not sure about an defineConfig({
component: {
devServer: {
viteConfig: async () => {
const newConfig = await something()
return newConfig
})
}
}
}) Would this be useful @IlCallo @hinogi? We could also include an argument to the async function, that would be our base config, potentially, if that would be useful. So it would be: viteConfig: async (baseConfig) => {
const overrides = await something()
return {...baseConfig, ...overrides }
}) |
That was pretty much my first attempt, without async/await, with the then quasar implementation. |
Yep, that would be pretty useful as we wouldn't have to manage At that point we would just expose 2 distinct functions returing a promise for webpack/vite config and setting up Cypress would be cleaner and easier for the user :) |
Ok, will look at doing this one. I will track it here: #23302 |
Some info on We are trying to resolve this, it's a little messy, if you want to hack into this more than happy to facilitate a fast review and release! Don't be hesitant to make a change if you need it, if CI is failing we can pick things up internally to help get it over the line. |
I think the problem is that Quasar needs Unluckily we won't be able to make Quasar "yarn 2-friendly" and drop yarn 1 support before Quasar 3 major version, which will probably happen late next year 😅 Not sure I have the bandwidth to work on it right now, but I'll try as soon as I free up a bit |
Going to carry on discussion in #23334 |
I am working on something in this area: #23605 |
#23605 landed, it'll be in the next release, I hope this helps! We can keep working on this, I want to enable third parties as much as possible. |
Nice, we'll try this out as soon as new version is released! |
I'm back at it 😁 |
Current behavior
importsToLoad
dynamic import of the spec file fails because it does not replace the path alias given by vite in the dynamic import.cypress/npm/vite-dev-server/client/initCypressTests.js
Line 9 in e5385fe
This results in a TypeError when it resolves.
Desired behavior
When vite is used and path aliases are given, check all kinds of imports or references to files with the according path alias.
Test code to reproduce
src/components/QuasarButton.vue
src/components/__test__/QuasarButton.spec.ts
and a path alias for
src
pointing to srcCypress Version
10.1.0
Other
The content does not really matter because cypress will not reach any of it because vite has found spec files and is providing the paths with knowing the path alias for it but not resolving it but initCypresssTests is blind to it and will fail trying to dynamically import from the path given by vite.
The text was updated successfully, but these errors were encountered: