Skip to content

test: pass context to config hook for Vite 7 #7647

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

Merged
merged 1 commit into from
May 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 44 additions & 13 deletions packages/qwik/src/optimizer/src/plugins/vite.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ const excludeDeps = [
const getPlugin = (opts: QwikVitePluginOptions | undefined) =>
(qwikVite(opts) as any)[0] as QwikVitePlugin;

// undefined for Vite 5 - 6, an object for Vite 7
const configHookPluginContext = undefined as any;

test('command: serve, mode: development', async () => {
const initOpts = {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c = (await plugin.config({}, { command: 'serve', mode: 'development' }))!;
const c = (await plugin.config.call(
configHookPluginContext,
{},
{ command: 'serve', mode: 'development' }
))!;
const opts = await plugin.api?.getOptions();
const build = c.build!;
const rollupOptions = build!.rollupOptions!;
Expand Down Expand Up @@ -117,7 +124,11 @@ test('command: serve, mode: production', async () => {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c = (await plugin.config({}, { command: 'serve', mode: 'production' }))!;
const c = (await plugin.config.call(
configHookPluginContext,
{},
{ command: 'serve', mode: 'production' }
))!;
const opts = await plugin.api?.getOptions();
const build = c.build!;
const rollupOptions = build!.rollupOptions!;
Expand Down Expand Up @@ -152,7 +163,11 @@ test('command: build, mode: development', async () => {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c = (await plugin.config({}, { command: 'build', mode: 'development' }))!;
const c = (await plugin.config.call(
configHookPluginContext,
{},
{ command: 'build', mode: 'development' }
))!;
const opts = await plugin.api?.getOptions();
const build = c.build!;
const rollupOptions = build!.rollupOptions!;
Expand Down Expand Up @@ -199,7 +214,11 @@ test('command: build, mode: production', async () => {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c = (await plugin.config({}, { command: 'build', mode: 'production' }))!;
const c = (await plugin.config.call(
configHookPluginContext,
{},
{ command: 'build', mode: 'production' }
))!;
const opts = await plugin.api?.getOptions();
const build = c.build!;
const rollupOptions = build!.rollupOptions!;
Expand Down Expand Up @@ -244,7 +263,11 @@ test('command: build, --mode production (client)', async () => {
};

const plugin = getPlugin(initOpts);
const c: any = (await plugin.config({}, { command: 'build', mode: 'production' }))!;
const c: any = (await plugin.config.call(
configHookPluginContext,
{},
{ command: 'build', mode: 'production' }
))!;
const opts = await plugin.api?.getOptions();
const build = c.build!;
const rollupOptions = build!.rollupOptions!;
Expand All @@ -262,7 +285,8 @@ test('command: build, --ssr entry.server.tsx', async () => {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c = (await plugin.config(
const c = (await plugin.config.call(
configHookPluginContext,
{ build: { ssr: resolve(cwd, 'src', 'entry.server.tsx') } },
{ command: 'build', mode: '' }
))!;
Expand Down Expand Up @@ -307,7 +331,8 @@ test('command: serve, --mode ssr', async () => {
},
};
const plugin = getPlugin(initOpts);
const c: any = (await plugin.config(
const c: any = (await plugin.config.call(
configHookPluginContext,
{ build: { emptyOutDir: true } },
{ command: 'serve', mode: 'ssr' }
))!;
Expand Down Expand Up @@ -335,7 +360,8 @@ test('command: serve, --mode ssr with build.assetsDir', async () => {
},
};
const plugin = getPlugin(initOpts);
const c: any = (await plugin.config(
const c: any = (await plugin.config.call(
configHookPluginContext,
{ build: { emptyOutDir: true, assetsDir: 'my-assets-dir' } },
{ command: 'serve', mode: 'ssr' }
))!;
Expand All @@ -359,7 +385,8 @@ test('should use the dist/ fallback with client target', async () => {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c: any = (await plugin.config(
const c: any = (await plugin.config.call(
configHookPluginContext,
{ build: { assetsDir: 'my-assets-dir/' } },
{ command: 'serve', mode: 'development' }
))!;
Expand All @@ -372,7 +399,8 @@ test('should use build.outDir config with client target', async () => {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c: any = (await plugin.config(
const c: any = (await plugin.config.call(
configHookPluginContext,
{ build: { outDir: 'my-dist/', assetsDir: 'my-assets-dir' } },
{ command: 'serve', mode: 'development' }
))!;
Expand All @@ -388,7 +416,8 @@ test('should use build.outDir config when assetsDir is _astro', async () => {
const plugin = getPlugin(initOpts);

// Astro sets a build.assetsDir of _astro, but we don't want to change that
const c: any = (await plugin.config(
const c: any = (await plugin.config.call(
configHookPluginContext,
{ build: { assetsDir: '_astro' } },
{ command: 'serve', mode: 'development' }
))!;
Expand All @@ -401,7 +430,8 @@ test('command: build, --mode lib', async () => {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c: any = (await plugin.config(
const c: any = (await plugin.config.call(
configHookPluginContext,
{
build: {
lib: {
Expand Down Expand Up @@ -436,7 +466,8 @@ test('command: build, --mode lib with multiple outputs', async () => {
optimizerOptions: mockOptimizerOptions(),
};
const plugin = getPlugin(initOpts);
const c: any = (await plugin.config(
const c: any = (await plugin.config.call(
configHookPluginContext,
{
build: {
lib: {
Expand Down