Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ec226a2

Browse filesBrowse files
TrottItalo A. Casas
authored andcommitted
doc: add test naming information to guide
The guide for writing tests is missing information on how tests are named. This adds that information. There is also some copy-editing done on the first paragraph of the guide. PR-URL: #10584 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
1 parent b73e98b commit ec226a2
Copy full SHA for ec226a2

File tree

Expand file treeCollapse file tree

1 file changed

+16
-5
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-5
lines changed
Open diff view settings
Collapse file

‎doc/guides/writing-tests.md‎

Copy file name to clipboardExpand all lines: doc/guides/writing-tests.md
+16-5Lines changed: 16 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
## What is a test?
44

5-
A test must be a node script that exercises a specific functionality provided
6-
by node and checks that it behaves as expected. It should exit with code `0` on success,
7-
otherwise it will fail. A test will fail if:
5+
Most tests in Node.js core are JavaScript programs that exercise a functionality
6+
provided by Node.js and check that it behaves as expected. Tests should exit
7+
with code `0` on success. A test will fail if:
88

99
- It exits by setting `process.exitCode` to a non-zero number.
10-
- This is most often done by having an assertion throw an uncaught
11-
Error.
10+
- This is usually done by having an assertion throw an uncaught Error.
1211
- Occasionally, using `process.exit(code)` may be appropriate.
1312
- It never exits. In this case, the test runner will terminate the test because
1413
it sets a maximum time limit.
@@ -205,3 +204,15 @@ require('../common');
205204
const assert = require('assert');
206205
const freelist = require('internal/freelist');
207206
```
207+
208+
## Naming Test Files
209+
210+
Test files are named using kebab casing. The first component of the name is
211+
`test`. The second is the module or subsystem being tested. The third is usually
212+
the method or event name being tested. Subsequent components of the name add
213+
more information about what is being tested.
214+
215+
For example, a test for the `beforeExit` event on the `process` object might be
216+
named `test-process-before-exit.js`. If the test specifically checked that arrow
217+
functions worked correctly with the `beforeExit` event, then it might be named
218+
`test-process-before-exit-arrow-functions.js`.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.