|
2 | 2 |
|
3 | 3 | ## What is a test?
|
4 | 4 |
|
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: |
8 | 8 |
|
9 | 9 | - 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. |
12 | 11 | - Occasionally, using `process.exit(code)` may be appropriate.
|
13 | 12 | - It never exits. In this case, the test runner will terminate the test because
|
14 | 13 | it sets a maximum time limit.
|
@@ -205,3 +204,15 @@ require('../common');
|
205 | 204 | const assert = require('assert');
|
206 | 205 | const freelist = require('internal/freelist');
|
207 | 206 | ```
|
| 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