Skip to content

Commit 2b24343

Browse files
authored
test: pass context to config hook for Vite 7 (#7647)
test: pass context to config hook
1 parent 415f6ae commit 2b24343

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

packages/qwik/src/optimizer/src/plugins/vite.unit.ts

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,19 @@ const excludeDeps = [
6969
const getPlugin = (opts: QwikVitePluginOptions | undefined) =>
7070
(qwikVite(opts) as any)[0] as QwikVitePlugin;
7171

72+
// undefined for Vite 5 - 6, an object for Vite 7
73+
const configHookPluginContext = undefined as any;
74+
7275
test('command: serve, mode: development', async () => {
7376
const initOpts = {
7477
optimizerOptions: mockOptimizerOptions(),
7578
};
7679
const plugin = getPlugin(initOpts);
77-
const c = (await plugin.config({}, { command: 'serve', mode: 'development' }))!;
80+
const c = (await plugin.config.call(
81+
configHookPluginContext,
82+
{},
83+
{ command: 'serve', mode: 'development' }
84+
))!;
7885
const opts = await plugin.api?.getOptions();
7986
const build = c.build!;
8087
const rollupOptions = build!.rollupOptions!;
@@ -117,7 +124,11 @@ test('command: serve, mode: production', async () => {
117124
optimizerOptions: mockOptimizerOptions(),
118125
};
119126
const plugin = getPlugin(initOpts);
120-
const c = (await plugin.config({}, { command: 'serve', mode: 'production' }))!;
127+
const c = (await plugin.config.call(
128+
configHookPluginContext,
129+
{},
130+
{ command: 'serve', mode: 'production' }
131+
))!;
121132
const opts = await plugin.api?.getOptions();
122133
const build = c.build!;
123134
const rollupOptions = build!.rollupOptions!;
@@ -152,7 +163,11 @@ test('command: build, mode: development', async () => {
152163
optimizerOptions: mockOptimizerOptions(),
153164
};
154165
const plugin = getPlugin(initOpts);
155-
const c = (await plugin.config({}, { command: 'build', mode: 'development' }))!;
166+
const c = (await plugin.config.call(
167+
configHookPluginContext,
168+
{},
169+
{ command: 'build', mode: 'development' }
170+
))!;
156171
const opts = await plugin.api?.getOptions();
157172
const build = c.build!;
158173
const rollupOptions = build!.rollupOptions!;
@@ -199,7 +214,11 @@ test('command: build, mode: production', async () => {
199214
optimizerOptions: mockOptimizerOptions(),
200215
};
201216
const plugin = getPlugin(initOpts);
202-
const c = (await plugin.config({}, { command: 'build', mode: 'production' }))!;
217+
const c = (await plugin.config.call(
218+
configHookPluginContext,
219+
{},
220+
{ command: 'build', mode: 'production' }
221+
))!;
203222
const opts = await plugin.api?.getOptions();
204223
const build = c.build!;
205224
const rollupOptions = build!.rollupOptions!;
@@ -244,7 +263,11 @@ test('command: build, --mode production (client)', async () => {
244263
};
245264

246265
const plugin = getPlugin(initOpts);
247-
const c: any = (await plugin.config({}, { command: 'build', mode: 'production' }))!;
266+
const c: any = (await plugin.config.call(
267+
configHookPluginContext,
268+
{},
269+
{ command: 'build', mode: 'production' }
270+
))!;
248271
const opts = await plugin.api?.getOptions();
249272
const build = c.build!;
250273
const rollupOptions = build!.rollupOptions!;
@@ -262,7 +285,8 @@ test('command: build, --ssr entry.server.tsx', async () => {
262285
optimizerOptions: mockOptimizerOptions(),
263286
};
264287
const plugin = getPlugin(initOpts);
265-
const c = (await plugin.config(
288+
const c = (await plugin.config.call(
289+
configHookPluginContext,
266290
{ build: { ssr: resolve(cwd, 'src', 'entry.server.tsx') } },
267291
{ command: 'build', mode: '' }
268292
))!;
@@ -307,7 +331,8 @@ test('command: serve, --mode ssr', async () => {
307331
},
308332
};
309333
const plugin = getPlugin(initOpts);
310-
const c: any = (await plugin.config(
334+
const c: any = (await plugin.config.call(
335+
configHookPluginContext,
311336
{ build: { emptyOutDir: true } },
312337
{ command: 'serve', mode: 'ssr' }
313338
))!;
@@ -335,7 +360,8 @@ test('command: serve, --mode ssr with build.assetsDir', async () => {
335360
},
336361
};
337362
const plugin = getPlugin(initOpts);
338-
const c: any = (await plugin.config(
363+
const c: any = (await plugin.config.call(
364+
configHookPluginContext,
339365
{ build: { emptyOutDir: true, assetsDir: 'my-assets-dir' } },
340366
{ command: 'serve', mode: 'ssr' }
341367
))!;
@@ -359,7 +385,8 @@ test('should use the dist/ fallback with client target', async () => {
359385
optimizerOptions: mockOptimizerOptions(),
360386
};
361387
const plugin = getPlugin(initOpts);
362-
const c: any = (await plugin.config(
388+
const c: any = (await plugin.config.call(
389+
configHookPluginContext,
363390
{ build: { assetsDir: 'my-assets-dir/' } },
364391
{ command: 'serve', mode: 'development' }
365392
))!;
@@ -372,7 +399,8 @@ test('should use build.outDir config with client target', async () => {
372399
optimizerOptions: mockOptimizerOptions(),
373400
};
374401
const plugin = getPlugin(initOpts);
375-
const c: any = (await plugin.config(
402+
const c: any = (await plugin.config.call(
403+
configHookPluginContext,
376404
{ build: { outDir: 'my-dist/', assetsDir: 'my-assets-dir' } },
377405
{ command: 'serve', mode: 'development' }
378406
))!;
@@ -388,7 +416,8 @@ test('should use build.outDir config when assetsDir is _astro', async () => {
388416
const plugin = getPlugin(initOpts);
389417

390418
// Astro sets a build.assetsDir of _astro, but we don't want to change that
391-
const c: any = (await plugin.config(
419+
const c: any = (await plugin.config.call(
420+
configHookPluginContext,
392421
{ build: { assetsDir: '_astro' } },
393422
{ command: 'serve', mode: 'development' }
394423
))!;
@@ -401,7 +430,8 @@ test('command: build, --mode lib', async () => {
401430
optimizerOptions: mockOptimizerOptions(),
402431
};
403432
const plugin = getPlugin(initOpts);
404-
const c: any = (await plugin.config(
433+
const c: any = (await plugin.config.call(
434+
configHookPluginContext,
405435
{
406436
build: {
407437
lib: {
@@ -436,7 +466,8 @@ test('command: build, --mode lib with multiple outputs', async () => {
436466
optimizerOptions: mockOptimizerOptions(),
437467
};
438468
const plugin = getPlugin(initOpts);
439-
const c: any = (await plugin.config(
469+
const c: any = (await plugin.config.call(
470+
configHookPluginContext,
440471
{
441472
build: {
442473
lib: {

0 commit comments

Comments
 (0)