@@ -37,13 +37,21 @@ describe('integrations', () => {
37
37
} ) ;
38
38
39
39
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 ( ( ) => {
43
43
$ ( '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 ) , {
45
53
shell : true ,
46
- cwd : viteLocation ,
54
+ cwd,
47
55
stdio : 'pipe' ,
48
56
} ) ;
49
57
const waitForServer = async ( url : string , timeout : number ) => {
@@ -59,14 +67,38 @@ describe('integrations', () => {
59
67
throw new Error ( `Server at ${ url } did not respond within ${ timeout } ms` ) ;
60
68
} ;
61
69
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
+ } ) ;
64
91
65
- afterAll ( ( ) => {
66
92
devServer . kill ( ) ;
67
93
} ) ;
68
94
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
+
70
102
await expect ( ( ) =>
71
103
page . waitForSelector ( '[data-testid="rendered-error"]' , {
72
104
timeout : 500 ,
@@ -75,6 +107,8 @@ describe('integrations', () => {
75
107
await page . waitForSelector ( '[data-testid="rendered-html"]' , {
76
108
timeout : 500 ,
77
109
} ) ;
110
+
111
+ devServer . kill ( ) ;
78
112
} ) ;
79
113
} ) ;
80
114
} ) ;
0 commit comments