Skip to content

Commit 1ab6646

Browse files
feat: support local handling + cleanup
1 parent ee0c3b7 commit 1ab6646

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ssr-plugin.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ const renderSSRCommand: ComponentFormat = async (
4747
const absoluteComponentPath = resolve(projectRoot, componentPath);
4848
const viteServer = ctx.project.vite;
4949

50+
// it does not replace env vars in the test file, so we need to do it manually
5051
if (!viteServer.config.define) return;
5152
for (const [key, value] of Object.entries(viteServer.config.env)) {
5253
viteServer.config.define[`__vite_ssr_import_meta__.env.${key}`] =
@@ -74,6 +75,7 @@ const renderSSRLocalCommand: LocalComponentFormat = async (
7475
) => {
7576
const viteServer = ctx.project.vite;
7677

78+
// it does not replace env vars in the test file, so we need to do it manually
7779
if (!viteServer.config.define) return;
7880
for (const [key, value] of Object.entries(viteServer.config.env)) {
7981
viteServer.config.define[`__vite_ssr_import_meta__.env.${key}`] =
@@ -84,6 +86,7 @@ const renderSSRLocalCommand: LocalComponentFormat = async (
8486
const { dirname, join } = await import("node:path");
8587

8688
const tempFileName = `ssr-test-${Date.now()}-${Math.random().toString(36).slice(2, 11)}.tsx`;
89+
// temp file inthe same folder to support relative imports
8790
const testFileDir = dirname(testFilePath);
8891
const tempFilePath = join(testFileDir, tempFileName);
8992

@@ -136,7 +139,7 @@ const renderSSRLocalCommand: LocalComponentFormat = async (
136139

137140
if (!Component) {
138141
throw new Error(
139-
`Local component "${componentName}" not found in ${testFilePath}. Available exports: ${Object.keys(componentModule).join(", ")}`,
142+
`[vitest-browser-qwik]: Local component "${componentName}" not found in ${testFilePath}. Available exports: ${Object.keys(componentModule).join(", ")}`,
140143
);
141144
}
142145

@@ -315,7 +318,6 @@ export function testSSR(): Plugin {
315318

316319
return null;
317320
},
318-
319321
configResolved(config) {
320322
globalThis.qwikSymbolMapper = symbolMapper;
321323

0 commit comments

Comments
 (0)