Skip to content

Commit 3b40365

Browse files
authored
Add info about tests to CONTRIBUTING.md (#1520)
1 parent 1cc91d9 commit 3b40365

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

CONTRIBUTING.md

+26
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@ compiled code in `dist`.
1919

2020
`dist-raw` is for larger chunks of code which are not compiled nor linted because they have been copy-pasted from `node`'s source code.
2121

22+
## Tests
23+
24+
Test cases are declared in `src/test/*.spec.ts`, and test fixtures live in `./tests`. They can be run with `npm run test-local`.
25+
26+
Tests are run with AVA, but using a custom wrapper API to enable some TS-friendly features and grouped test suites.
27+
28+
The tests `npm pack` ts-node into a tarball and `npm install` it into `./tests/node_modules`. This makes `./tests` a better testing environment
29+
because it more closely matches the end-user's environment. Complex `require()` / `import` / `--require` / `--loader` invocations behave
30+
the way they would in a users's project.
31+
32+
Historically, it has been difficult to test ts-node in-process because it mutates the node environment: installing require hooks, stack trace formatters, etc.
33+
`nyc`, `ava`, and `ts-node` all mutate the node environment, so it is tricky to setup and teardown individual tests in isolation, because ts-node's hooks need to be
34+
reset without disturbing `nyc` or `ava` hooks. For this reason, many tests are integration style, spawning ts-node's CLI in an external process, asking it to
35+
execute one of the fixture projects in `./tests`.
36+
37+
Over time, I've gradually added setup and teardown logic so that more components can be tested in-process.
38+
39+
We have a debug configuration for VSCode.
40+
41+
1. Open a `*.spec.ts` so it is the active/focused file.
42+
2. (optional) set breakpoints.
43+
3. Invoke debugger with F5.
44+
45+
Note that some tests might misbehave in the debugger. REPL tests in particular. I'm not sure why, but I think it is related to how `console` does not write to
46+
stdout when in a debug session.
47+
2248
## Documentation
2349

2450
Documentation is written in markdown in `website/docs` and rendered into a website by Docusaurus. The README is also generated from these markdown files.

0 commit comments

Comments
 (0)