-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnode_test.node_cli.txt
190 lines (155 loc) · 8.86 KB
/
node_test.node_cli.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
┏━━━━━━━━━━━━━━━┓
┃ NODE_TEST ┃
┗━━━━━━━━━━━━━━━┛
VERSION ==> #Part of Node.js core
ASSERTIONS ==> #See Node.js assertion doc
#Can also use any assertion library that throws
DIFF TESTING ==> #See Node.js snapshots doc
GENERIC MOCKING ==> #See Node.js tests mocks doc
DEPENDENCIES MOCKING ==> #See Node.js module mock doc
TIMERS MOCKING ==> #See Node.js mocktimers doc
REPORTING ==> #See Node.js reporting doc
┌───────────┐
│ TESTS │
└───────────┘
it|test(['TITLE'][, OPTS],FUNC(T))#Test fails when throwing
->PROMISE #FUNC can be async by using a PROMISE or callback FUNC(ERROR)
#Def 'TITLE': FUNC.name or '<anonymous>'
#PROMISE resolves once test has completed.
T.test(...)->PROMISE #Sub-test.
#Inherits all OPTS
#PROMISE should be awaited
describe[.skip|todo|only](...) #Like [T.]test[.skip|...](...) except:
# - sync
# - ST is passed as argument instead of T
suite[.skip|todo|only]
(...) 20.13.0*#Alias
[S]T.name #'TITLE'
T.fullName 20.16.0*#'TITLE > ...' including parent describe()
[S]T.filePath 22.6.0*#'PATH' to root import.meta.url
T.plan(NUM[, OPTS]) 20.15.0*#Must use T.assert.* instead of node:assert
OPTS.wait 23.9.0*#When test ends, if pending asserts:
23.9.0*# - false (def): do not wait
23.9.0*# - true: wait
23.9.0*# - NUM: wait NUMms, then fail
┌───────────────────┐
│ ORCHESTRATION │
└───────────────────┘
[T.]before|after
(FUNC()[->>][, OPTS]) #Run in beginning|end of file or of current describe|test()
[T.]before|afterEach
(FUNC()[->>][, OPTS]) #Run in beginning|end of each test() of current describe|test()
T.waitFor
(FUNC()[->[>]VAL][,OPTS])
->>VAL 22.14.0*#Repeats FUNC() if it throws
OPTS.interval 22.14.0*#NUM (in ms, def: 50) of repetition
OPTS.timeout 22.14.0*#After NUM (in ms, def: 1s), stops repeating and throw ERROR
┌───────────────┐
│ SELECTION │
└───────────────┘
node GLOB... #File selection
ROPTS.globPatterns 'GLOB'_ARR #Def:
ROPTS.files 'PATH'_ARR # - *.test.js *-test.js *_test.js
# - test[-*].js
# - test/**/*.js
23.10.0*# - test/**/*.test.ts|mts|cts
23.10.0*# - test/**/*-test.ts|mts|cts
23.10.0*# - test/**/*_test.ts|mts|cts
#Searched in **
# .js can be .cjs|mjs too
<21.0.0*#Could not use GLOB, and default value was different
<22.6.0*#Could not use ROPTS.globPatterns
--test-name-pattern REGXP 18.11.0*#Only run tests with matching 'TITLE'
ROPTS.testNamePatterns 20.1.0*#STR|REGEXP[_ARR]
--test-skip-pattern REGEXP 21.1.0*#Inverse
ROPTS.cwd 23.0.0*#'DIR' (def: '.')
ROPTS.execArgv 22.10.0*#STR_ARR. Node CLI flags
ROPTS.argv 22.10.0*#STR_ARR. process.argv in subprocess
OPTS.skip #BOOL|'MESSAGE'
#Skip the test
T.skip(['MESSAGE']) #Same
test.skip(...) 18.17.0*#Same
OPTS.todo #BOOL|'MESSAGE'
#Mark test as TODO
T.todo(['MESSAGE']) #Same
test.todo(...) 18.17.0*#Same
OPTS.only #BOOL
#Only run this test, providing node --test-only is used
ROPTS.only 18.19.0*#Same
T.only(['MESSAGE']) 18.15.0*#
T.runOnly(BOOL) #Same
test.only(...) 18.17.0*#Same
┌───────────────┐
│ EXECUTION │
└───────────────┘
node --test 16.17.0*#Must be used
WATCH MODE ==> 19.2.0*#See core Node.js flag --watch*
run(ROPTS)->TAP_STREAM 18.9.0*#Run a test file programmatically
ROPTS.inspectPort 18.9.0*#NUM[()] or null (incremented from process.debugPort) (def: undefined)
TAP_STREAM 18.9.0*#RSTREAM outputting TAP
TAP_STREAM.on
('test:diagnostic',
FUNC('MESSAGE')) 18.9.0*#Called on T.diagnostic('MESSAGE')
TAP_STREAM.on 18.9.0*#Called on T.test()
('test:pass|fail', 18.9.0*#OBJ:
FUNC(OBJ)) 18.9.0*# - name 'NAME'
18.9.0*# - testNumber NUM
18.9.0*# - skip STR|undefined
18.9.0*# - todo STR|undefined
19.2.0*# - details OBJ
18.9.0*# (if fail)
18.9.0*# - error ERROR
19.1.0*# - expected|actual VAL
19.1.0*# - operator STR
TEST RUN ==> #Test functions are run as they are defined (i.e. synchronously)
#Top-level tests are performed serially, i.e. each test wait for previous one to end.
PROCESS EXIT ==> #On process exit (including SIGINT|SIGTERM):
# - make tests still running fail ("cancelled")
# - exit code 1 if one test failed
#'uncaughtException|unhandledRejection' make top test fail
ROPTS.forceExit
--test-force-exit 20.14.0*#Exit once all tests ended, even if still something running in the event loop
[S]T.signal #ABORT_SIGNAL
[R]OPTS.signal #ABORT_SIGNAL
┌───────────┐
│ SPEED │
└───────────┘
[R]OPTS.timeout #NUMms, per test
--test-timeout 20.11.0*#Default value (def: Infinity)
┌─────────────────┐
│ PARALLELISM │
└─────────────────┘
ROPTS.isolation
--test-isolation 23.6.0*#If 'process' (def), each file is executed in its own child process
#If 'none', opposite
--experimental
-test-isolation 22.9.0-23.5.0*#Previous name
--test-concurrency 18.19.0*#Max NUM of concurrent test files
18.19.0*#Def: OS.availableParallelism() - 1
[R]OPTS.concurrency #NUM (def: 1)
#or BOOL (number of CPU cores - 1)
#Run sub-tests in parallel, providing Promise.all() is used
--test-shard=NUM/NUM2 18.19.0*#Run only NUM/NUM2% of tests
18.19.0*#Meant to distribute tests between multiple machines
┌──────────────┐
│ COVERAGE │
└──────────────┘
--experimental
-test-coverage 18.17.0*#Automatically calls V8.takeCoverage|stopCoverage()
ROPTS.coverage 22.10.0*#BOOL (def: false)
--test-coverage
-include|exclude=GLOB 22.5.0*#
ROPTS.coverageIncludeGlobs
ROPTS.coverageExcludeGlobs22.10.0*#'GLOB'[_ARR]
--test-coverage-functions
=NUM
--test-coverage-branches
=NUM
--test-coverage-lines=NUM 22.8.0*#0-100 (def: 0). Minimum percentage. If fails, exit code 1
ROPTS.functionCoverage
ROPTS.branchCoverage
ROPTS.lineCoverage 22.10.0*#
/* node:coverage
disable|enable */ 18.17.0*#
/* node:coverage
ignore next [NUM] */ 18.17.0*#