Skip to content

Commit 4c469af

Browse files
committed
add test on vite build; vite preview
1 parent 1191e27 commit 4c469af

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

packages/render/integrations/integrations.spec.ts

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,21 @@ describe('integrations', () => {
3737
});
3838

3939
describe('vite', () => {
40-
let devServer: child_process.ChildProcess;
41-
beforeAll(async () => {
42-
const viteLocation = path.resolve(import.meta.dirname, './vite/');
40+
const viteLocation = path.resolve(import.meta.dirname, './vite/');
41+
42+
beforeAll(() => {
4343
$('npm install', viteLocation);
44-
devServer = child_process.spawn('npm', ['run', 'dev'], {
44+
});
45+
46+
const startWebServer = async (
47+
command: string,
48+
url: string,
49+
cwd: string,
50+
) => {
51+
const argsv = command.split(' ');
52+
const devServer = child_process.spawn(argsv[0], argsv.slice(1), {
4553
shell: true,
46-
cwd: viteLocation,
54+
cwd,
4755
stdio: 'pipe',
4856
});
4957
const waitForServer = async (url: string, timeout: number) => {
@@ -59,14 +67,38 @@ describe('integrations', () => {
5967
throw new Error(`Server at ${url} did not respond within ${timeout}ms`);
6068
};
6169

62-
await waitForServer('http://localhost:5173', 1000);
63-
});
70+
await waitForServer(url, 1000);
71+
return devServer;
72+
};
73+
74+
// The code being run after build has been modified by Vite and might run differently
75+
it('should not error when rendering in vite preview', async () => {
76+
$('npm run build', viteLocation);
77+
const devServer = await startWebServer(
78+
'npm run preview',
79+
'http://localhost:4173',
80+
viteLocation,
81+
);
82+
83+
await expect(() =>
84+
page.waitForSelector('[data-testid="rendered-error"]', {
85+
timeout: 500,
86+
}),
87+
).rejects.toThrow();
88+
await page.waitForSelector('[data-testid="rendered-html"]', {
89+
timeout: 500,
90+
});
6491

65-
afterAll(() => {
6692
devServer.kill();
6793
});
6894

69-
it('should not error when rendering', async () => {
95+
it('should not error when rendering in vite dev', async () => {
96+
const devServer = await startWebServer(
97+
'npm run dev',
98+
'http://localhost:5173',
99+
viteLocation,
100+
);
101+
70102
await expect(() =>
71103
page.waitForSelector('[data-testid="rendered-error"]', {
72104
timeout: 500,
@@ -75,6 +107,8 @@ describe('integrations', () => {
75107
await page.waitForSelector('[data-testid="rendered-html"]', {
76108
timeout: 500,
77109
});
110+
111+
devServer.kill();
78112
});
79113
});
80114
});

0 commit comments

Comments
 (0)