-
-
Notifications
You must be signed in to change notification settings - Fork 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
Expose resolved viteConfig for 3rd party libraries #4329
Comments
for vite config, You can use env or mode to control whether the cypress plugin is active That's not to say this is ideal, but you can make it work today. See also https://github.com/nickbreaton/vitest-svelte-kit @brillout: you recently mentioned that telefunc + sveltekit could happen soon. Is there a pattern you can share here? |
Can you elaborate on which bits of config you need access to? The problem with Exposing programmatic control is totally doable though. Would that unblock you? |
It'd be cool to consider this in conjunction with Vitest. There was quite a bit of discussion about that in the Vitest #svelte Discord channel on Jan 7, 2022: https://discord.com/channels/917386801235247114/918804871333945394/929824676014854174 The difficulty for Vitest is that SvelteKit can't do SSR with Vite's HTML plugin present, but Vitest relies on it to serve the Vitest UI. For Vitest, @dominikg had suggested splitting |
Thanks for the response, both. The general theme is that Cypress's Component Testing architecture is a meta-website, ingesting the user's app and spitting out something that works the same way, but with different pages. We're trying to take the user's compilation options and create a new "website" where each spec file is its own entry point/page. This is identical to Storybook btw. Depending on the bundler, we do different things, but the TLDR is that the output of Config needs: // someFile.js
import coolWasmThing from './foo.wasm' // If the user has a plugin that handles wasm configured
import Todo from './Todo.svelte' // To grab the Svelte plugin that the SvelteKit uses under the hood
if (import.meta.MY_ENV_VAR === 'dev') {
// change an API URL or something
myRequestClient.baseUrl = 'http://localhost:3001'
}
We also intend to run
Yes. So long as I have something that will allow me to give SvelteKit a new custom index file or let me intercept all requests by acting as middleware 😄 What I don't need: Anything that's related to making multiple pages
What I do need: Anything that's related to correctness of the code being compiled.
|
Yikes — we're talking about some fairly invasive changes to SvelteKit's internals. Candidly, it's unlikely to happen. That's the bad news. The good news is I think you can solve this entirely in userland. By default, SvelteKit generates pages from // svelte.config.js
export default {
kit: {
files: {
routes: process.env.CYPRESS ? '.cypress-component-tests' : 'src/routes'
}
}
}; ...and generated routes for each of the You could even abstract this behind a function that read from the user's configuration, in case they had configured // svelte.config.js
import { config } from 'cypress-svelte-whatever';
export default config({
kit: {
files: {
routes: 'src/pages'
}
}
}); Does that seem workable? |
Ahhh. I'm surprised the changes are invasive. This seems like a common problem for tools like Storybook, Cypress, and Vitest. Our goal is to avoid users having to touch anything on their side. Our current API with all other frameworks in Cypress 10 is to use a single string in a e.g. export default defineConfig({
component: {
framework: 'svelte'
}
}) ... and that's it. I think based on what I'm hearing, you're suggesting two things:
// node_modules/@cypress/sveltekit-dev-server/svelte.config.js
const userConfig = await findUp('svelte.config.js')
export default {
// ...userConfig (do deep merging here)
viteConfig: {
plugins: [ Cypress() ],
rollupConfig: {
/* spec files here */
},
optimizeDeps: {
entries: [ /* spec files here */ ]
}
}
}
// node_modules/@cypress/sveltekit-dev-server/index.js
import { startDev } from 'sveltekit'
const configFilePath = resolve('./svelte.config.js')
const server = startDev({ configFile: configFilePath })
// I need server.close from here so I can cleanly tear down the process,
// but if there's no module API I guess I can figure it out another way. It sounds like in the worst case I can get comfortable executing from the CLI and tearing down the process from the outside-in. |
Describe the problem
Tools like Vitest, Cypress, and Storybook want to support SvelteKit. These projects need to bundle components that users write in their SvelteKit apps and need a programmatic API to kick off static bundling or serving the app's dev server. To ensure that the code that's being tested and rendered behaves like it will in production, it's critical to use the user's resolved build configuration instead of making them "eject" and re-define all of the compilation options.
Describe the proposed solution
Meta build-tools like CRACO, CRA, Vue CLI, Next.js, and Nuxt.js all provide ways to access the underlying, "compiled" Webpack configurations used to build and bundle the application's source code. These APIs allow 3rd party libraries like Vitest and Cypress to ingest the user's build configuration and then compile their code in a different context than that of the SvelteKit (or Nuxt, etc) framework.
Getting the Config and Merging it in w/ Vite
Static API
Merging w/ vite
Alternatives considered
You could also re-export/otherwise wrap Vite's
createServer
andmergeConfig
methods. This would make dependency management less of a pain, but I'm not asking for it because I think it's possible to meet the needs for Cy and Vitest without this API.Dev Server API
Importance
i cannot use SvelteKit without it
Additional Information
This is critical for Cypress to release official Svelte support for Component Testing Svelte apps. We could hardcode build configurations for users, but we don't feel comfortable doing that because they will diverge from the user's production setup and may allow for prod-only bugs to be released.
The text was updated successfully, but these errors were encountered: