@exodus/test 1.0.0-rc.6 → 1.0.0-rc.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +94 -43
  3. package/bin/inband.js +11 -0
  4. package/bin/index.js +466 -70
  5. package/bin/jest.js +4 -8
  6. package/bin/reporter.js +201 -0
  7. package/bundler/babel-worker.cjs +62 -0
  8. package/bundler/bundle.js +331 -0
  9. package/bundler/modules/ansi-styles.cjs +49 -0
  10. package/bundler/modules/assert-strict.cjs +1 -0
  11. package/bundler/modules/child_process.cjs +10 -0
  12. package/bundler/modules/cluster.cjs +27 -0
  13. package/bundler/modules/crypto.cjs +5 -0
  14. package/bundler/modules/empty/function-throw.cjs +4 -0
  15. package/bundler/modules/empty/module-throw.cjs +1 -0
  16. package/bundler/modules/fs-promises.cjs +1 -0
  17. package/bundler/modules/fs.cjs +110 -0
  18. package/bundler/modules/globals.cjs +187 -0
  19. package/bundler/modules/http.cjs +119 -0
  20. package/bundler/modules/https.cjs +11 -0
  21. package/bundler/modules/jest-message-util.js +5 -0
  22. package/bundler/modules/jest-util.js +22 -0
  23. package/bundler/modules/node-buffer.cjs +3 -0
  24. package/bundler/modules/url.cjs +28 -0
  25. package/bundler/modules/util-format.cjs +41 -0
  26. package/bundler/modules/ws.cjs +20 -0
  27. package/loaders/esbuild.js +1 -0
  28. package/loaders/typescript.js +3 -0
  29. package/loaders/typescript.loader.js +24 -0
  30. package/package.json +107 -11
  31. package/src/dark.cjs +146 -0
  32. package/src/engine.js +22 -0
  33. package/src/engine.node.cjs +41 -0
  34. package/src/engine.pure.cjs +528 -0
  35. package/src/engine.pure.snapshot.cjs +35 -0
  36. package/src/engine.select.cjs +5 -0
  37. package/src/expect.cjs +125 -0
  38. package/src/jest.config.fs.js +54 -0
  39. package/src/jest.config.js +138 -0
  40. package/src/jest.environment.js +33 -0
  41. package/src/jest.fn.js +21 -20
  42. package/src/jest.js +234 -46
  43. package/src/jest.mock.js +215 -52
  44. package/src/jest.snapshot.js +97 -35
  45. package/src/jest.timers.js +48 -14
  46. package/src/node.js +10 -0
  47. package/src/replay.js +103 -0
  48. package/src/tape.cjs +15 -0
  49. package/src/tape.js +38 -10
  50. package/src/version.js +18 -0
  51. /package/{bin → loaders}/babel.cjs +0 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Exodus Movement, Inc
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,50 +1,95 @@
1
1
  # @exodus/test
2
2
 
3
- A runner for `node:test`, `jest`, and `tape` test suites on top of `node:test`
4
-
5
- Most likely it will just work on your simple jest tests as as drop-in replacement
6
-
7
- Comes with typescript support, optional esm/cjs interop, and also loading babel transforms!
8
-
9
- Use `--coverage` to generate coverage output
10
-
11
- ## Library
12
-
13
- ### Using with `node:test` natively
14
-
15
- You can just use pure [`node:test`](https://nodejs.org/api/test.html) in your tests,
16
- this runner is fully compatible with that (and will set version-specific options for you)!
17
-
18
- ### Moving from jest
19
-
20
- ```js
21
- import {
22
- jest,
23
- expect,
24
- describe,
25
- it,
26
- beforeEach,
27
- afterEach,
28
- beforeAll,
29
- afterAll,
30
- } from '@exodus/test/jest'
31
- ```
32
-
33
- Or, run with [`--jest` option](#options) to register jest globals
34
-
35
- ### Moving from tap/tape
36
-
37
- ```js
38
- import test from '@exodus/test/tap'
3
+ A runner for `node:test`, `jest`, and `tape` test suites on top of `node:test` (and any runtime)
4
+
5
+ ## Features
6
+
7
+ - Native ESM, including in Jest tests
8
+ - Esbuild on the fly for babelified ESM interop (enable via `--esbuild`)
9
+ - TypeScript support in both transform (through [tsx](https://tsx.is/), enable via `--esbuild`)
10
+ and typestrip (via `--typescript`) modes
11
+ - Runs on [node:test](https://nodejs.org/api/test.html), and (experimental) on bun, deno, d8, JSC and
12
+ [Hermes](https://hermesengine.dev)
13
+ - Testsuite-agnostic -- can run any file as long as it sets exit code based on test results
14
+ - Built-in [Jest](https://jestjs.io) compatibility (with `--jest`), including `jest.*` global
15
+ - Up to ~10x faster depending on the original setup
16
+ - Actual `expect` module, also `jest-extended` and `jest-when` just work on top
17
+ - Snapshots, including snapshot matchers
18
+ - Function and timer mocks
19
+ - [test.concurrent]()
20
+ - Module mocks (on top of Node.js runtime only), including for ESM modules
21
+ - Loads Jest configuration
22
+ - It works on Hermes too!
23
+ - Built-in network record/replay for offline tests, mocking `fetch` and `WebSocket` sessions
24
+ - `--drop-network` support for guaranteed offline testing
25
+ - Native code coverage via v8 (Node.js or [c8](https://github.com/bcoe/c8)), with istanbul reporters
26
+ - GitHub reporter (auto-enabled by default)
27
+ - JSDOM env support
28
+ - Hanging tests error by default (unlike `jest`)
29
+ - Babel support, picks up your Babel config (enable via `--babel`)
30
+ - Unlike `bun:test`, it runs test files in isolated contexts \
31
+ Bun leaks globals / side effects between test files ([ref](https://github.com/oven-sh/bun/issues/6024)),
32
+ and has incompatible `test()` lifecycle / order
33
+ - Also features a tape API for drop-in replacement
34
+
35
+ ## Reporter samples
36
+
37
+ #### CLI (but uses colors when output supports them, e.g. in terminal):
38
+
39
+ ```console
40
+ # tests/jest/expect.mock.test.js
41
+ ✔ PASS drinkAll > drinks something lemon-flavoured (1.300417ms)
42
+ ✔ PASS drinkAll > does not drink something octopus-flavoured (0.191791ms)
43
+ ✔ PASS drinkAll (1.842959ms)
44
+ ✔ PASS drinkEach > drinkEach drinks each drink (0.360625ms)
45
+ ✔ PASS drinkEach (0.463416ms)
46
+ ✔ PASS toHaveBeenCalledWith > registration applies correctly to orange La Croix (0.53325ms)
47
+ ✔ PASS toHaveBeenCalledWith (0.564166ms)
48
+ ✔ PASS toHaveBeenLastCalledWith > applying to all flavors does mango last (0.380375ms)
49
+ ✔ PASS toHaveBeenLastCalledWith (0.473417ms)
50
+ # tests/jest/fn.invocationCallOrder.test.js
51
+ ✔ PASS mock.invocationCallOrder (4.221042ms)
39
52
  ```
40
53
 
41
- ### Running tests asynchronously
54
+ #### GitHub Actions collapses test results per-file, like this:
55
+
56
+ <details>
57
+ <summary>✅ <strong>tests/jest/lifecycle.test.js</strong></summary>
58
+ <pre>
59
+ ✔ PASS A > B > C (3.26166ms)
60
+ ✔ PASS A > B > D (1.699463ms)
61
+ ✔ PASS A > B (6.72719ms)
62
+ ✔ PASS A > E > F (1.117997ms)
63
+ ✔ PASS A > E > G > H (1.330904ms)
64
+ ✔ PASS A > E > G (1.94971ms)
65
+ ✔ PASS A > E (3.821825ms)
66
+ ✔ PASS A > I (0.533096ms)
67
+ ✔ PASS A (13.887889ms)
68
+ ✔ PASS J (0.373187ms)
69
+ ✔ PASS K > L (0.659852ms)
70
+ ✔ PASS K (1.143195ms)
71
+ </pre>
72
+ </details><details>
73
+ <summary>✅ <strong>tests/jest/timers.async.test.js</strong></summary>
74
+ <pre>
75
+ ✔ PASS advanceTimersByTime() does not let microtasks to pass (5.326604ms)
76
+ ✔ PASS advanceTimersByTime() does not let microtasks to pass even with await (1.336064ms)
77
+ ✔ PASS advanceTimersByTimeAsync() lets microtasks to pass (6.99526ms)
78
+ ✔ PASS advanceTimersByTimeAsync() lets microtasks to pass, chained (10.131664ms)
79
+ ✔ PASS advanceTimersByTimeAsync() lets microtasks to pass, longer chained (8.635472ms)
80
+ ✔ PASS advanceTimersByTimeAsync() lets microtasks to pass, async chain (56.937983ms)
81
+ </pre>
82
+ </details>
83
+
84
+ See live output in [CI](https://github.com/ExodusMovement/test/actions/workflows/checks.yaml)
42
85
 
43
- Add `{ concurrency: true }`, like this: `describe('my testsuite', { concurrency: true }, () => {`
86
+ ## Library
44
87
 
45
88
  ### List of exports
46
89
 
47
- - `@exodus/test/jest` -- `jest` mock
90
+ - `@exodus/test/node` -- `node:test` API, working under non-Node.js platforms
91
+
92
+ - `@exodus/test/jest` -- `jest` implementation
48
93
 
49
94
  - `@exodus/test/tape` -- `tape` mock (can also be helpful when moving from `tap`)
50
95
 
@@ -54,11 +99,9 @@ Just use `"test": "exodus-test"`
54
99
 
55
100
  ### Options
56
101
 
57
- - `--jest` -- register jest test helpers as global variables
102
+ - `--jest` -- register jest test helpers as global variables, also load `jest.config.*` configuration options
58
103
 
59
- - `--typescript` -- use typescript loader (which also compiles esm to cjs where needed)
60
-
61
- - `--esbuild` -- use esbuild loader (currently an alias for `--typescript`)
104
+ - `--esbuild` -- use esbuild loader, also enables Typescript support
62
105
 
63
106
  - `--babel` -- use babel loader (slower than `--esbuild`, makes sense if you have a special config)
64
107
 
@@ -68,8 +111,16 @@ Just use `"test": "exodus-test"`
68
111
 
69
112
  - `--coverage-engine node` -- use Node.js builtint coverage engine
70
113
 
114
+ - `--watch` -- operate in watch mode and re-run tests on file changes
115
+
116
+ - `--only` -- only run the tests marked with `test.only`
117
+
71
118
  - `--passWithNoTests` -- do not error when no test files were found
72
119
 
73
120
  - `--write-snapshots` -- write snapshots instead of verifying them (has `--test-update-snapshots` alias)
74
121
 
75
122
  - `--test-force-exit` -- force exit after tests are done (useful in integration tests where it could be unfeasible to resolve all open handles)
123
+
124
+ ## License
125
+
126
+ [MIT](./LICENSE)
package/bin/inband.js ADDED
@@ -0,0 +1,11 @@
1
+ import { resolve } from 'node:path'
2
+ import { describe } from '../src/engine.js'
3
+
4
+ const files = JSON.parse(process.env.EXODUS_TEST_INBAND)
5
+ if (!Array.isArray(files)) throw new Error('Unexpected')
6
+
7
+ for (const file of files.sort()) {
8
+ await describe(`EXODUS_TEST_INBAND:${file}`, async () => {
9
+ await import(resolve(file))
10
+ })
11
+ }