@@ -9,7 +9,6 @@ import type { CoverageMap } from 'istanbul-lib-coverage'
9
9
import libCoverage from 'istanbul-lib-coverage'
10
10
import libSourceMaps from 'istanbul-lib-source-maps'
11
11
import MagicString from 'magic-string'
12
- import type { ProxifiedModule } from 'magicast'
13
12
import { parseModule } from 'magicast'
14
13
import remapping from '@ampproject/remapping'
15
14
import { normalize , resolve } from 'pathe'
@@ -162,7 +161,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
162
161
for ( const [ transformMode , filenames ] of Object . entries ( coveragePerProject ) as [ AfterSuiteRunMeta [ 'transformMode' ] , Filename [ ] ] [ ] ) {
163
162
let merged : RawCoverage = { result : [ ] }
164
163
165
- for ( const chunk of toSlices ( filenames , this . options . processingConcurrency ) ) {
164
+ for ( const chunk of this . toSlices ( filenames , this . options . processingConcurrency ) ) {
166
165
if ( debug . enabled ) {
167
166
index += chunk . length
168
167
debug ( 'Covered files %d/%d' , index , total )
@@ -198,7 +197,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
198
197
watermarks : this . options . watermarks ,
199
198
} )
200
199
201
- if ( hasTerminalReporter ( this . options . reporter ) )
200
+ if ( this . hasTerminalReporter ( this . options . reporter ) )
202
201
this . ctx . logger . log ( c . blue ( ' % ' ) + c . dim ( 'Coverage report from ' ) + c . yellow ( this . name ) )
203
202
204
203
for ( const reporter of this . options . reporter ) {
@@ -232,10 +231,8 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
232
231
this . updateThresholds ( {
233
232
thresholds : resolvedThresholds ,
234
233
perFile : this . options . thresholds . perFile ,
235
- configurationFile : {
236
- write : ( ) => writeFileSync ( configFilePath , configModule . generate ( ) . code , 'utf-8' ) ,
237
- read : ( ) => resolveConfig ( configModule ) ,
238
- } ,
234
+ configurationFile : configModule ,
235
+ onUpdate : ( ) => writeFileSync ( configFilePath , configModule . generate ( ) . code , 'utf-8' ) ,
239
236
} )
240
237
}
241
238
}
@@ -255,7 +252,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
255
252
let merged : RawCoverage = { result : [ ] }
256
253
let index = 0
257
254
258
- for ( const chunk of toSlices ( uncoveredFiles , this . options . processingConcurrency ) ) {
255
+ for ( const chunk of this . toSlices ( uncoveredFiles , this . options . processingConcurrency ) ) {
259
256
if ( debug . enabled ) {
260
257
index += chunk . length
261
258
debug ( 'Uncovered files %d/%d' , index , uncoveredFiles . length )
@@ -334,7 +331,7 @@ export class V8CoverageProvider extends BaseCoverageProvider implements Coverage
334
331
const coverageMap = libCoverage . createCoverageMap ( { } )
335
332
let index = 0
336
333
337
- for ( const chunk of toSlices ( scriptCoverages , this . options . processingConcurrency ) ) {
334
+ for ( const chunk of this . toSlices ( scriptCoverages , this . options . processingConcurrency ) ) {
338
335
if ( debug . enabled ) {
339
336
index += chunk . length
340
337
debug ( 'Converting %d/%d' , index , scriptCoverages . length )
@@ -410,53 +407,3 @@ function normalizeTransformResults(fetchCache: Map<string, { result: FetchResult
410
407
411
408
return normalized
412
409
}
413
-
414
- function hasTerminalReporter ( reporters : Options [ 'reporter' ] ) {
415
- return reporters . some ( ( [ reporter ] ) =>
416
- reporter === 'text'
417
- || reporter === 'text-summary'
418
- || reporter === 'text-lcov'
419
- || reporter === 'teamcity' )
420
- }
421
-
422
- function toSlices < T > ( array : T [ ] , size : number ) : T [ ] [ ] {
423
- return array . reduce < T [ ] [ ] > ( ( chunks , item ) => {
424
- const index = Math . max ( 0 , chunks . length - 1 )
425
- const lastChunk = chunks [ index ] || [ ]
426
- chunks [ index ] = lastChunk
427
-
428
- if ( lastChunk . length >= size )
429
- chunks . push ( [ item ] )
430
-
431
- else
432
- lastChunk . push ( item )
433
-
434
- return chunks
435
- } , [ ] )
436
- }
437
-
438
- function resolveConfig ( configModule : ProxifiedModule < any > ) {
439
- const mod = configModule . exports . default
440
-
441
- try {
442
- // Check for "export default { test: {...} }"
443
- if ( mod . $type === 'object' )
444
- return mod
445
-
446
- if ( mod . $type === 'function-call' ) {
447
- // "export default defineConfig({ test: {...} })"
448
- if ( mod . $args [ 0 ] . $type === 'object' )
449
- return mod . $args [ 0 ]
450
-
451
- // "export default defineConfig(() => ({ test: {...} }))"
452
- if ( mod . $args [ 0 ] . $type === 'arrow-function-expression' && mod . $args [ 0 ] . $body . $type === 'object' )
453
- return mod . $args [ 0 ] . $body
454
- }
455
- }
456
- catch ( error ) {
457
- // Reduce magicast's verbose errors to readable ones
458
- throw new Error ( error instanceof Error ? error . message : String ( error ) )
459
- }
460
-
461
- throw new Error ( 'Failed to update coverage thresholds. Configuration file is too complex.' )
462
- }
0 commit comments