1
1
import type { Code } from '../../@types/code.js' ;
2
2
import type { Configs } from '../../@types/poku.js' ;
3
+ import { join } from 'node:path' ;
3
4
import process from 'node:process' ;
4
5
import { GLOBAL , results , timespan } from '../../configs/poku.js' ;
5
6
import { reporter } from '../../services/reporter.js' ;
6
7
import { runTests } from '../../services/run-tests.js' ;
7
8
import { exit } from '../helpers/exit.js' ;
9
+ import { listFiles } from '../helpers/list-files.js' ;
8
10
9
11
/* c8 ignore next 1 */ // Process-based
10
12
export const onSigint = ( ) => process . stdout . write ( '\u001B[?25h' ) ;
@@ -23,8 +25,6 @@ export async function poku(
23
25
targetPaths : string | string [ ] ,
24
26
configs ?: Configs
25
27
) : Promise < Code | undefined > {
26
- let code : Code = 0 ;
27
-
28
28
if ( configs ) GLOBAL . configs = { ...GLOBAL . configs , ...configs } ;
29
29
30
30
timespan . started = new Date ( ) ;
@@ -33,24 +33,26 @@ export async function poku(
33
33
const paths : string [ ] = Array . prototype . concat ( targetPaths ) ;
34
34
const showLogs = ! GLOBAL . configs . quiet ;
35
35
const { reporter : plugin } = GLOBAL . configs ;
36
+ const { cwd } = GLOBAL ;
37
+
38
+ const testFiles = (
39
+ await Promise . all (
40
+ paths . map ( ( dir ) => listFiles ( join ( cwd , dir ) , GLOBAL . configs ) )
41
+ )
42
+ ) . flat ( 1 ) ;
36
43
37
44
if ( typeof plugin === 'string' && plugin !== 'poku' )
38
45
GLOBAL . reporter = reporter [ plugin ] ( ) ;
39
46
40
47
if ( showLogs ) GLOBAL . reporter . onRunStart ( ) ;
41
48
42
- try {
43
- const promises = paths . map ( async ( dir ) => await runTests ( dir ) ) ;
44
- const concurrency = await Promise . all ( promises ) ;
45
-
46
- if ( concurrency . some ( ( result ) => ! result ) ) code = 1 ;
47
- } finally {
48
- const end = process . hrtime ( start ) ;
49
- const total = end [ 0 ] * 1e3 + end [ 1 ] / 1e6 ;
49
+ const result = await runTests ( testFiles ) ;
50
+ const code : Code = result ? 0 : 1 ;
51
+ const end = process . hrtime ( start ) ;
52
+ const total = end [ 0 ] * 1e3 + end [ 1 ] / 1e6 ;
50
53
51
- timespan . duration = total ;
52
- timespan . finished = new Date ( ) ;
53
- }
54
+ timespan . duration = total ;
55
+ timespan . finished = new Date ( ) ;
54
56
55
57
if ( showLogs ) GLOBAL . reporter . onRunResult ( { code, timespan, results } ) ;
56
58
if ( GLOBAL . configs . noExit ) return code ;
0 commit comments