Skip to content

Commit 950cee0

Browse files
committed
docs: add tests docs in DEVELOPMENT.md
1 parent 5d9bf10 commit 950cee0

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

DEVELOPMENT.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,59 @@ In order to create a new release you have two options:
88

99
1. Locally run `npm run release` and follow the interactive CLI
1010
2. Manually trigger the GitHub Action `release` workflow specifyin the type of release you want to create
11+
12+
## Tests
13+
14+
To run the tests, you can use the following command:
15+
16+
```sh
17+
npm test
18+
```
19+
20+
This will run both `browser` and `node` tests.
21+
22+
### Browser
23+
24+
Browser tests use [`wtr`](https://modern-web.dev/docs/test-runner/overview/) as the test runner. To build browser bundle using [esbuild](https://esbuild.github.io/) and run browser tests, you can use the following command:
25+
26+
```sh
27+
npm run test:browser
28+
```
29+
30+
The configuration file is [web-test-runner.config.msj](./web-test-runner.config.mjs). It starts a local broker using [aedes-cli](https://github.com/moscajs/aedes-cli) with `ws` and `wss` support and then runs the tests in 3 different browsers: `chrome`, `firefox` and `safari`.
31+
32+
The tests are located in the `test/browser` directory and there are also tests for service workers in the `test/browser/worker.js` directory.
33+
34+
When developing/debugging tests it's useful to run the tests in a single browser, for example:
35+
36+
```sh
37+
npx wtr --manual --open
38+
```
39+
40+
This will open the browser on `localhost:8001` and lets you choose the test to run by clicking on the link with the test name. By opening the DevTools you will be able to see the tests output and put debugger in both worker and main tests files.
41+
42+
Be aware that tests will use the bundled version of the library, so you need to run `npm run build` before running the tests. If you need to debug issues in the code it could be useful to enable source maps when building, in order to do this just set `sourcemap: true` in [esbuild.js](./esbuild.js) file and run `npm run build`.
43+
44+
### Node
45+
46+
For NodeJS tests we use the NodeJS [Test Runner](https://nodejs.org/api/test.html). To run the tests, you can use the following command:
47+
48+
```sh
49+
npm run test:node
50+
```
51+
52+
The tests are located in the `test` directory. The entrypoint of tests is `runTests.ts` file. It is used to filter the tests to run, set concurrency and create a nice looking tests summary (see reason [here](https://github.com/nodejs/help/issues/3902#issuecomment-1726033310))
53+
54+
When developing/debugging tests it's useful to run the tests for a single file/test, for example:
55+
56+
```sh
57+
node -r esbuild-register --test --inspect test/client.ts
58+
```
59+
60+
If you want to run tests using a filter, you can use the `--test-name-pattern` flag:
61+
62+
```sh
63+
node -r esbuild-register --test --test-name-pattern="should resend in-flight QoS" --inspect test/client.ts
64+
```
65+
66+
You can also run tests in watch mode using the `--watch` flag.

0 commit comments

Comments
 (0)