Browse Source

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: https://github.com/nodejs/node/pull/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>
v6.x
Rich Trott 8 years ago
committed by Myles Borins
parent
commit
af991c7a98
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 21
      doc/guides/writing-tests.md

21
doc/guides/writing-tests.md

@ -2,13 +2,12 @@
## What is a test? ## What is a test?
A test must be a node script that exercises a specific functionality provided Most tests in Node.js core are JavaScript programs that exercise a functionality
by node and checks that it behaves as expected. It should exit with code `0` on success, provided by Node.js and check that it behaves as expected. Tests should exit
otherwise it will fail. A test will fail if: with code `0` on success. A test will fail if:
- It exits by setting `process.exitCode` to a non-zero number. - It exits by setting `process.exitCode` to a non-zero number.
- This is most often done by having an assertion throw an uncaught - This is usually done by having an assertion throw an uncaught Error.
Error.
- Occasionally, using `process.exit(code)` may be appropriate. - Occasionally, using `process.exit(code)` may be appropriate.
- It never exits. In this case, the test runner will terminate the test because - It never exits. In this case, the test runner will terminate the test because
it sets a maximum time limit. it sets a maximum time limit.
@ -205,3 +204,15 @@ require('../common');
const assert = require('assert'); const assert = require('assert');
const freelist = require('internal/freelist'); const freelist = require('internal/freelist');
``` ```
## Naming Test Files
Test files are named using kebab casing. The first component of the name is
`test`. The second is the module or subsystem being tested. The third is usually
the method or event name being tested. Subsequent components of the name add
more information about what is being tested.
For example, a test for the `beforeExit` event on the `process` object might be
named `test-process-before-exit.js`. If the test specifically checked that arrow
functions worked correctly with the `beforeExit` event, then it might be named
`test-process-before-exit-arrow-functions.js`.

Loading…
Cancel
Save