@@ -4,7 +4,7 @@ import { ProjectTypesList } from './create-project';
4
4
import { runTests } from './test' ;
5
5
import { uid } from 'uid' ;
6
6
import { startDevServer , stopDevServer } from './dev-server' ;
7
- import { startBrowser , stopBrowser } from './browser-control' ;
7
+ import { openPage , startBrowser , stopBrowser } from './browser-control' ;
8
8
import {
9
9
getTemplatesDirectory ,
10
10
installDependencies ,
@@ -58,7 +58,7 @@ export function generateTestCases(adders: AdderWithoutExplicitArgs[]) {
58
58
return testCases ;
59
59
}
60
60
61
- export async function runAdderTests (
61
+ export async function setupAdder (
62
62
template : string ,
63
63
adder : AdderWithoutExplicitArgs ,
64
64
options : OptionValues < Record < string , Question > > ,
@@ -81,10 +81,17 @@ export async function runAdderTests(
81
81
82
82
await runAdder ( adder , workingDirectory , options ) ;
83
83
84
- await installDependencies ( workingDirectory ) ;
84
+ return workingDirectory ;
85
+ }
85
86
86
- const { url, devServer } = await startDevServer ( workingDirectory , adder . tests . command ?? 'dev' ) ;
87
- const { browser, page } = await startBrowser ( url , testOptions . headless ) ;
87
+ export async function executeAdderTests (
88
+ workingDirectory : string ,
89
+ adder : AdderWithoutExplicitArgs ,
90
+ options : OptionValues < Record < string , Question > > ,
91
+ testOptions : TestOptions ,
92
+ ) {
93
+ const { url, devServer } = await startDevServer ( workingDirectory , adder . tests ?. command ?? 'dev' ) ;
94
+ const page = await openPage ( url ) ;
88
95
89
96
try {
90
97
const errorOcurred = await page . $ ( 'vite-error-overlay' ) ;
@@ -96,7 +103,7 @@ export async function runAdderTests(
96
103
97
104
await runTests ( page , adder , options ) ;
98
105
} finally {
99
- await stopBrowser ( browser , page ) ;
106
+ await page . close ( ) ;
100
107
await stopDevServer ( devServer ) ;
101
108
}
102
109
}
@@ -112,30 +119,50 @@ export async function runTestCases(testCases: Map<string, TestCase[]>, testOptio
112
119
const syncTasks : Array < ( ) => Promise < void > > = [ ] ;
113
120
const asyncTestCaseInputs : TestCase [ ] = [ ] ;
114
121
const syncTestCaseInputs : TestCase [ ] = [ ] ;
122
+ const tests : { testCase : TestCase ; cwd : string } [ ] = [ ] ;
123
+
124
+ console . log ( 'executing adders' ) ;
115
125
for ( const values of testCases . values ( ) ) {
116
126
for ( const testCase of values ) {
117
- const taskExecutor = async ( ) => {
118
- try {
119
- await runAdderTests ( testCase . template , testCase . adder , testCase . options , testOptions ) ;
120
- } catch ( e ) {
121
- const error = e as Error ;
122
- const adderError : AdderError = {
123
- name : 'AdderError' ,
124
- adder : testCase . adder . config . metadata . id ,
125
- template : testCase . template ,
126
- message : error . message ,
127
- } ;
128
- throw adderError ;
129
- }
130
- } ;
127
+ const cwd = await setupAdder (
128
+ testCase . template ,
129
+ testCase . adder ,
130
+ testCase . options ,
131
+ testOptions ,
132
+ ) ;
131
133
132
- if ( testCase . runSynchronously ) {
133
- syncTasks . push ( taskExecutor ) ;
134
- syncTestCaseInputs . push ( testCase ) ;
135
- } else {
136
- asyncTasks . push ( taskExecutor ) ;
137
- asyncTestCaseInputs . push ( testCase ) ;
134
+ tests . push ( { testCase, cwd } ) ;
135
+ }
136
+ }
137
+
138
+ console . log ( 'installing dependencies' ) ;
139
+ await installDependencies ( testOptions . outputDirectory ) ;
140
+
141
+ await startBrowser ( testOptions . headless ) ;
142
+
143
+ console . log ( 'running tests' ) ;
144
+ for ( const { cwd, testCase } of tests ) {
145
+ const taskExecutor = async ( ) => {
146
+ try {
147
+ await executeAdderTests ( cwd , testCase . adder , testCase . options , testOptions ) ;
148
+ } catch ( e ) {
149
+ const error = e as Error ;
150
+ const adderError : AdderError = {
151
+ name : 'AdderError' ,
152
+ adder : testCase . adder . config . metadata . id ,
153
+ template : testCase . template ,
154
+ message : error . message ,
155
+ } ;
156
+ throw adderError ;
138
157
}
158
+ } ;
159
+
160
+ if ( testCase . runSynchronously ) {
161
+ syncTasks . push ( taskExecutor ) ;
162
+ syncTestCaseInputs . push ( testCase ) ;
163
+ } else {
164
+ asyncTasks . push ( taskExecutor ) ;
165
+ asyncTestCaseInputs . push ( testCase ) ;
139
166
}
140
167
}
141
168
@@ -173,6 +200,8 @@ export async function runTestCases(testCases: Map<string, TestCase[]>, testOptio
173
200
} ,
174
201
} ) ;
175
202
203
+ await stopBrowser ( ) ;
204
+
176
205
const rejectedAsyncPromisesResult = allAsyncResults . rejectedIndexes . map < AdderError > (
177
206
( x ) => allAsyncResults . taskResults [ x ] as unknown as AdderError ,
178
207
) ;
0 commit comments