Skip to content

Commit

Permalink
doc: add test naming information to guide
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Italo A. Casas <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Reviewed-By: Sam Roberts <[email protected]>
  • Loading branch information
Trott authored and MylesBorins committed Mar 9, 2017
1 parent 56b779d commit 8f0e31b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions doc/guides/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

## What is a test?

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

- It exits by setting `process.exitCode` to a non-zero number.
- This is most often done by having an assertion throw an uncaught
Error.
- This is usually done by having an assertion throw an uncaught Error.
- Occasionally, using `process.exit(code)` may be appropriate.
- It never exits. In this case, the test runner will terminate the test because
it sets a maximum time limit.
Expand Down Expand Up @@ -186,3 +185,15 @@ require('../common');
const assert = require('assert');
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`.

0 comments on commit 8f0e31b

Please sign in to comment.