-
Notifications
You must be signed in to change notification settings - Fork 16
/
node_test.node_cli.txt
185 lines (139 loc) · 9.53 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
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 #'TITLE > ...' including parent describe()
T.plan(NUM) 20.15.0*#Must use T.assert.* instead of node:assert
/=+===============================+=\
/ : : \
)==: ORCHESTRATION :==(
\ :_______________________________: /
\=+===============================+=/
[T.]before|after
(FUNC()[->PROMISE]
[, OPTS]) #Run in beginning|end of file or of current describe|test()
[T.]before|afterEach
(FUNC()[->PROMISE]
[, OPTS]) #Run in beginning|end of each test() of current describe|test()
/=+===============================+=\
/ : : \
)==: SELECTION :==(
\ :_______________________________: /
\=+===============================+=/
node GLOB... #File selection
ROPTS.files 'GLOB'_ARR #Def:
# - *.test.js *-test.js *_test.js
# - test[-*].js
# - test/**/*.js
#Searched in **
# .js can be .cjs|mjs too
<21.0.0*#Could not use GLOB, and default value was different
--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
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 :==(
\ :_______________________________: /
\=+===============================+=/
PARALLELISM ==> #Each file is executed in its own child process, in parallel
--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()
--test-coverage
-include|exclude=GLOB 22.5.0*#
/* node:coverage
disable|enable */ 18.17.0*#
/* node:coverage
ignore next [NUM] */ 18.17.0*#