@@ -94,7 +94,6 @@ export function execute(
94
94
} ) ;
95
95
}
96
96
97
- // eslint-disable-next-line max-lines-per-function
98
97
async function initializeApplication (
99
98
options : NormalizedKarmaBuilderOptions ,
100
99
context : BuilderContext ,
@@ -103,14 +102,41 @@ async function initializeApplication(
103
102
) : Promise <
104
103
[ typeof import ( 'karma' ) , Config & ConfigOptions , BuildOptions , AsyncIterator < Result > | null ]
105
104
> {
106
- const outputPath = path . join ( context . workspaceRoot , 'dist/test-out' , randomUUID ( ) ) ;
105
+ const karma = await import ( 'karma' ) ;
107
106
const projectSourceRoot = await getProjectSourceRoot ( context ) ;
107
+ const outputPath = path . join ( context . workspaceRoot , 'dist/test-out' , randomUUID ( ) ) ;
108
+ await fs . rm ( outputPath , { recursive : true , force : true } ) ;
109
+
110
+ const { buildOptions, mainName } = await setupBuildOptions (
111
+ options ,
112
+ context ,
113
+ projectSourceRoot ,
114
+ outputPath ,
115
+ ) ;
108
116
109
- const [ karma , entryPoints ] = await Promise . all ( [
110
- import ( 'karma' ) ,
111
- collectEntrypoints ( options , context , projectSourceRoot ) ,
112
- fs . rm ( outputPath , { recursive : true , force : true } ) ,
113
- ] ) ;
117
+ const [ buildOutput , buildIterator ] = await runEsbuild ( buildOptions , context , projectSourceRoot ) ;
118
+
119
+ const karmaConfig = await configureKarma (
120
+ karma ,
121
+ context ,
122
+ karmaOptions ,
123
+ options ,
124
+ buildOptions ,
125
+ buildOutput ,
126
+ mainName ,
127
+ transforms ,
128
+ ) ;
129
+
130
+ return [ karma , karmaConfig , buildOptions , buildIterator ] ;
131
+ }
132
+
133
+ async function setupBuildOptions (
134
+ options : NormalizedKarmaBuilderOptions ,
135
+ context : BuilderContext ,
136
+ projectSourceRoot : string ,
137
+ outputPath : string ,
138
+ ) : Promise < { buildOptions : BuildOptions ; mainName : string } > {
139
+ const entryPoints = await collectEntrypoints ( options , context , projectSourceRoot ) ;
114
140
115
141
const mainName = 'test_main' ;
116
142
if ( options . main ) {
@@ -156,6 +182,14 @@ async function initializeApplication(
156
182
externalDependencies : options . externalDependencies ,
157
183
} ;
158
184
185
+ return { buildOptions, mainName } ;
186
+ }
187
+
188
+ async function runEsbuild (
189
+ buildOptions : BuildOptions ,
190
+ context : BuilderContext ,
191
+ projectSourceRoot : string ,
192
+ ) : Promise < [ Result & { kind : ResultKind . Full } , AsyncIterator < Result > | null ] > {
159
193
const virtualTestBedInit = createVirtualModulePlugin ( {
160
194
namespace : 'angular:test-bed-init' ,
161
195
loadContent : async ( ) => {
@@ -166,7 +200,7 @@ async function initializeApplication(
166
200
`getTestBed().initTestEnvironment(BrowserTestingModule, platformBrowserTesting(), {` ,
167
201
` errorOnUnknownElements: true,` ,
168
202
` errorOnUnknownProperties: true,` ,
169
- ' });' ,
203
+ ` });` ,
170
204
] ;
171
205
172
206
return {
@@ -193,6 +227,21 @@ async function initializeApplication(
193
227
// Write test files
194
228
await writeTestFiles ( buildOutput . files , buildOptions . outputPath ) ;
195
229
230
+ return [ buildOutput , buildIterator ] ;
231
+ }
232
+
233
+ async function configureKarma (
234
+ karma : typeof import ( 'karma' ) ,
235
+ context : BuilderContext ,
236
+ karmaOptions : ConfigOptions ,
237
+ options : NormalizedKarmaBuilderOptions ,
238
+ buildOptions : BuildOptions ,
239
+ buildOutput : Result & { kind : ResultKind . Full } ,
240
+ mainName : string ,
241
+ transforms ?: KarmaBuilderTransformsOptions ,
242
+ ) : Promise < Config & ConfigOptions > {
243
+ const outputPath = buildOptions . outputPath ;
244
+
196
245
// We need to add this to the beginning *after* the testing framework has
197
246
// prepended its files. The output path is required for each since they are
198
247
// added later in the test process via a plugin.
@@ -352,5 +401,5 @@ async function initializeApplication(
352
401
parsedKarmaConfig . reporters = ( parsedKarmaConfig . reporters ?? [ ] ) . concat ( [ 'coverage' ] ) ;
353
402
}
354
403
355
- return [ karma , parsedKarmaConfig , buildOptions , buildIterator ] ;
404
+ return parsedKarmaConfig ;
356
405
}
0 commit comments