1
1
#!/usr/bin/env node
2
2
3
3
import fastGlob from "fast-glob"
4
- import { Option , program } from "commander"
5
-
6
- import tapReporter from "../lib/reporters/tap.js"
7
- import fancyReporter from "../lib/reporters/fancy.js"
4
+ import { program } from "commander"
8
5
6
+ import tapReporter from "../lib/run-one.tap-reporter.js"
9
7
import { getNodeVersion , getPackageInfo } from "../lib/utils/node.js"
10
- import { green , red } from "../lib/utils/colors .js"
11
- import { runSuite } from "../lib/runSuite .js"
8
+ import { green , red } from "../lib/utils/terminal-text .js"
9
+ import { runSuite } from "../lib/run-many .js"
12
10
13
11
/**
14
12
* Node.js version guard
@@ -33,36 +31,42 @@ if (major < required) {
33
31
34
32
const { description, version } = await getPackageInfo ( )
35
33
const processStartAt = process . hrtime ( )
34
+ const isCI = process . env [ "CI" ] === "true"
36
35
37
36
program
38
37
. name ( "tsd-lite" )
39
38
. description ( description )
40
39
. version ( version , "-v, --version" , "Print version number" )
41
40
. helpOption ( "-h, --help" , "Print this help guide" )
42
41
. showSuggestionAfterError ( )
43
- . addOption (
44
- new Option ( "-r, --reporter <name>" , "Print test results using reporter" )
45
- . default ( "tap" )
46
- . choices ( [ "tap" , "fancy" ] )
42
+ . option (
43
+ "-c, --color" ,
44
+ "Output colored TAP for better human consumption. Disabled in CI environments if not explicitly set." ,
45
+ ! isCI
46
+ )
47
+ . option (
48
+ "--no-color" ,
49
+ "Dont output colored TAP, usefull when piping to other tools"
47
50
)
48
- . argument ( "patterns..." , "Glob patterns for matching test files" )
49
- . action ( async ( patterns , { reporter : reporterName } ) => {
50
- const reporter = reporterName === "tap" ? tapReporter : fancyReporter
51
+ . argument ( "<patterns...>" , "Glob patterns for matching test files" )
52
+ . action ( async ( patterns , { color : hasColor } ) => {
51
53
const files = fastGlob . sync ( patterns , { absolute : true } )
52
54
53
55
process . stdout . write (
54
- `${ reporter . formatIntro ( {
56
+ `${ tapReporter . formatIntro ( {
55
57
count : files . length ,
56
58
patterns,
59
+ hasColor,
57
60
} ) } \n`
58
61
)
59
62
60
63
runSuite ( files , {
61
64
onTestFinish : ( result , index ) => {
62
65
process . stdout . write (
63
- `${ reporter . formatTest ( {
66
+ `${ tapReporter . formatTest ( {
64
67
index,
65
68
result,
69
+ hasColor,
66
70
} ) } \n`
67
71
)
68
72
} ,
@@ -82,10 +86,11 @@ program
82
86
)
83
87
84
88
process . stdout . write (
85
- `\n${ reporter . formatSuite ( {
89
+ `\n${ tapReporter . formatSuite ( {
86
90
passCount,
87
91
failCount,
88
92
duration : process . hrtime ( processStartAt ) ,
93
+ hasColor,
89
94
} ) } \n`
90
95
)
91
96
0 commit comments