You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+26
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,32 @@ compiled code in `dist`.
19
19
20
20
`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.
21
21
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
+
22
48
## Documentation
23
49
24
50
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