qunitx 0.12.0 → 0.12.2
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.
- package/Makefile +4 -2
- package/README.md +170 -100
- package/package.json +4 -4
- package/shims/deno/index.js +1 -1
- package/shims/deno/module.js +2 -2
- package/shims/deno/test.js +1 -1
package/Makefile
CHANGED
|
@@ -13,9 +13,11 @@ build:
|
|
|
13
13
|
|
|
14
14
|
# Lint, bump version, update changelog, commit, tag, push, publish to npm.
|
|
15
15
|
# CI then creates the GitHub release.
|
|
16
|
-
# Usage: make release
|
|
16
|
+
# Usage: make release (defaults to patch)
|
|
17
|
+
# make release LEVEL=minor|major
|
|
18
|
+
LEVEL ?= patch
|
|
17
19
|
release:
|
|
18
|
-
@
|
|
20
|
+
@npm whoami 2>/dev/null || npm login
|
|
19
21
|
npm run lint
|
|
20
22
|
npm version $(LEVEL) --no-git-tag-version
|
|
21
23
|
npm run changelog:update
|
package/README.md
CHANGED
|
@@ -1,156 +1,226 @@
|
|
|
1
|
-
](https://github.com/izelnakri/qunitx/actions/workflows/ci.yml)
|
|
2
|
+
[](https://www.npmjs.com/package/qunitx)
|
|
3
|
+
[](https://www.npmjs.com/package/qunitx)
|
|
4
|
+
[](LICENSE)
|
|
3
5
|
[](https://github.com/izelnakri/qunitx/issues)
|
|
6
|
+
[](https://github.com/sponsors/izelnakri)
|
|
4
7
|
|
|
5
8
|
# QUnitX
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
**The oldest, most battle-tested JavaScript test API — now universal.**
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
Run the **same test file** in Node.js, Deno, and the browser without changes.
|
|
13
|
+
Zero dependencies. No config needed for Node. TypeScript works out of the box.
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
the default test runner of node.js or deno, or with a browser runner of your
|
|
14
|
-
choice!
|
|
15
|
+
---
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
## Why QUnit?
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
QUnit was created in 2008 by the jQuery team. While newer frameworks come and go,
|
|
20
|
+
QUnit has quietly accumulated 16+ years of real-world edge-case handling that younger
|
|
21
|
+
tools are still catching up to. Its assertion API is the most mature in the JavaScript
|
|
22
|
+
ecosystem:
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
- **`assert.deepEqual`** — handles circular references, prototype chains, Sets, Maps,
|
|
25
|
+
typed arrays, Dates, RegExps, and getters correctly
|
|
26
|
+
- **`assert.throws` / `assert.rejects`** — match errors by constructor, regex, or custom validator
|
|
27
|
+
- **`assert.step` / `assert.verifySteps`** — declarative execution-order verification;
|
|
28
|
+
catches missing async callbacks that other frameworks silently swallow
|
|
29
|
+
- **`assert.expect(n)`** — fails the test if exactly _n_ assertions didn't run;
|
|
30
|
+
invaluable for async code where missing assertions would otherwise pass silently
|
|
31
|
+
- **Hooks** — `before`, `beforeEach`, `afterEach`, `after` with correct FIFO/LIFO ordering,
|
|
32
|
+
properly scoped across nested modules
|
|
33
|
+
- **Shareable browser URLs** — the QUnit browser UI filters tests via query params, so you can
|
|
34
|
+
share `https://yourapp.test/?moduleId=abc123` with a colleague and they see exactly the same view
|
|
23
35
|
|
|
24
|
-
|
|
36
|
+
QUnitX wraps this API to work with **Node.js's built-in `node:test` runner** and
|
|
37
|
+
**Deno's native test runner** — no Jest, Vitest, or other framework needed.
|
|
25
38
|
|
|
26
|
-
|
|
39
|
+
---
|
|
27
40
|
|
|
28
|
-
|
|
41
|
+
## Demo
|
|
29
42
|
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
> Left window: `node --test` and `deno test` running the same file.
|
|
44
|
+
> Right window: QUnit browser UI with filterable, shareable test results.
|
|
32
45
|
|
|
33
|
-
|
|
46
|
+
<!-- Demo GIF: see docs/demo.tape (VHS script) for terminal portion.
|
|
47
|
+
For the combined terminal + browser recording, see "Recording the demo" below. -->
|
|
48
|
+

|
|
34
49
|
|
|
35
|
-
|
|
36
|
-
import { module, test } from 'qunit';
|
|
50
|
+
Live browser UI example (click to see filterable QUnit test suite):
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
52
|
+
[objectmodel.js.org/test/?moduleId=6e15ed5f](https://objectmodel.js.org/test/?moduleId=6e15ed5f&moduleId=950ec9c5)
|
|
53
|
+
|
|
54
|
+

|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
npm install qunitx
|
|
40
62
|
```
|
|
41
63
|
|
|
42
|
-
|
|
64
|
+
Requires **Node.js >= 22** (LTS) or **Deno >= 2**.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
43
69
|
|
|
44
70
|
```js
|
|
45
|
-
//
|
|
71
|
+
// math-test.js (works in Node, Deno, and browser unchanged)
|
|
46
72
|
import { module, test } from 'qunitx';
|
|
47
|
-
import $ from 'jquery';
|
|
48
73
|
|
|
49
|
-
module('
|
|
50
|
-
|
|
51
|
-
assert.
|
|
74
|
+
module('Math utilities', (hooks) => {
|
|
75
|
+
hooks.before((assert) => {
|
|
76
|
+
assert.step('setup complete');
|
|
52
77
|
});
|
|
53
78
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
79
|
+
test('addition', (assert) => {
|
|
80
|
+
assert.equal(2 + 2, 4);
|
|
81
|
+
assert.notEqual(2 + 2, 5);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('deepEqual', (assert) => {
|
|
85
|
+
assert.deepEqual({ a: 1, b: [2, 3] }, { a: 1, b: [2, 3] });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
module('Async', () => {
|
|
89
|
+
test('resolves correctly', async (assert) => {
|
|
90
|
+
const result = await Promise.resolve(42);
|
|
91
|
+
assert.strictEqual(result, 42);
|
|
60
92
|
});
|
|
61
93
|
});
|
|
62
94
|
});
|
|
63
95
|
```
|
|
64
96
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
97
|
+
### Node.js
|
|
98
|
+
|
|
99
|
+
```sh
|
|
100
|
+
# No extra dependencies — uses the Node built-in test runner
|
|
101
|
+
node --test math-test.js
|
|
102
|
+
|
|
103
|
+
# Watch mode (re-runs on save)
|
|
104
|
+
node --test --watch math-test.js
|
|
105
|
+
|
|
106
|
+
# Glob pattern
|
|
107
|
+
node --test --watch 'test/**/*.js'
|
|
108
|
+
|
|
109
|
+
# TypeScript (tsconfig.json with moduleResolution: NodeNext required)
|
|
110
|
+
node --import=tsx/esm --test math-test.ts
|
|
111
|
+
|
|
112
|
+
# Code coverage
|
|
113
|
+
npx c8 node --test math-test.js
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Deno
|
|
68
117
|
|
|
69
|
-
|
|
70
|
-
|
|
118
|
+
```sh
|
|
119
|
+
# One-time: create a deno.json import map
|
|
120
|
+
echo '{"imports": {"qunitx": "https://esm.sh/qunitx/shims/deno/index.js"}}' > deno.json
|
|
71
121
|
|
|
72
|
-
#
|
|
73
|
-
|
|
122
|
+
# Run
|
|
123
|
+
deno test math-test.js
|
|
74
124
|
|
|
75
|
-
#
|
|
76
|
-
|
|
125
|
+
# With explicit permissions
|
|
126
|
+
deno test --allow-read --allow-env math-test.js
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Browser
|
|
130
|
+
|
|
131
|
+
Use [qunitx-cli](https://github.com/izelnakri/qunitx-cli) to get browser test output
|
|
132
|
+
in your terminal / CI, or to open the live QUnit UI during development:
|
|
77
133
|
|
|
78
|
-
|
|
79
|
-
|
|
134
|
+
```sh
|
|
135
|
+
npm install -g qunitx-cli
|
|
136
|
+
|
|
137
|
+
# Headless (CI-friendly — outputs TAP to stdout)
|
|
138
|
+
qunitx math-test.js
|
|
139
|
+
|
|
140
|
+
# Open QUnit browser UI alongside terminal output
|
|
141
|
+
qunitx math-test.js --debug
|
|
80
142
|
```
|
|
81
143
|
|
|
82
|
-
|
|
144
|
+
The browser UI lets you:
|
|
145
|
+
- Filter by module or test name (filter state is preserved in the URL)
|
|
146
|
+
- Share a link that reproduces the exact filtered view with a colleague
|
|
147
|
+
- Re-run individual tests by clicking them
|
|
148
|
+
- See full assertion diffs inline
|
|
83
149
|
|
|
84
|
-
|
|
85
|
-
API](https://api.qunitjs.com/QUnit/module/#hooks-on-nested-modules) in browser.
|
|
86
|
-
You can use [QUnitX CLI](https://github.com/izelnakri/qunitx-cli) to get your
|
|
87
|
-
browser tests to stdout/CI or use the watch mode during the development.
|
|
150
|
+
---
|
|
88
151
|
|
|
89
|
-
|
|
90
|
-
# Install QUnitX browser runner/cli:
|
|
91
|
-
$ npm install -g qunitx-cli
|
|
92
|
-
$ qunitx
|
|
93
|
-
$ qunitx some-test.js
|
|
152
|
+
## Migrating from QUnit
|
|
94
153
|
|
|
95
|
-
|
|
96
|
-
$ qunitx some-test.js --debug
|
|
154
|
+
One import line is all that changes:
|
|
97
155
|
|
|
156
|
+
```js
|
|
157
|
+
// Before:
|
|
158
|
+
import { module, test } from 'qunit';
|
|
159
|
+
|
|
160
|
+
// After:
|
|
161
|
+
import { module, test } from 'qunitx';
|
|
98
162
|
```
|
|
99
163
|
|
|
100
|
-
|
|
164
|
+
---
|
|
101
165
|
|
|
102
|
-
|
|
103
|
-
- `QUnit.module(testName, optionsOrHandler?, handler?)`
|
|
104
|
-
- `QUnit.test(testName, optionsOrHandler?, handler?)`
|
|
166
|
+
## Concurrency options
|
|
105
167
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
api](https://nodejs.org/api/test.html#runoptions):
|
|
168
|
+
`module()` and `test()` accept an optional options object forwarded directly to the underlying
|
|
169
|
+
Node / Deno test runner:
|
|
109
170
|
|
|
110
171
|
```js
|
|
111
|
-
// in some-test.js: (typescript also works)
|
|
112
172
|
import { module, test } from 'qunitx';
|
|
113
|
-
import $ from 'jquery';
|
|
114
173
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
174
|
+
// Run tests in this module serially
|
|
175
|
+
module('Serial suite', { concurrency: false }, (hooks) => {
|
|
176
|
+
test('first', (assert) => { assert.ok(true); });
|
|
177
|
+
test('second', (assert) => { assert.ok(true); });
|
|
178
|
+
});
|
|
119
179
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
assert.ok(Object.keys($));
|
|
126
|
-
});
|
|
180
|
+
// Deno-specific: permissions, sanitizeExit, etc.
|
|
181
|
+
module('Deno file access', { permissions: { read: true }, sanitizeExit: false }, (hooks) => {
|
|
182
|
+
test('reads a file', async (assert) => {
|
|
183
|
+
const text = await Deno.readTextFile('./README.md');
|
|
184
|
+
assert.ok(text.length > 0);
|
|
127
185
|
});
|
|
128
186
|
});
|
|
129
187
|
```
|
|
130
188
|
|
|
131
|
-
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## How it works
|
|
192
|
+
|
|
193
|
+
| Runtime | Adapter |
|
|
194
|
+
|---------|---------|
|
|
195
|
+
| Node.js | Wraps `node:test` `describe` / `it` with QUnit lifecycle |
|
|
196
|
+
| Deno | Wraps Deno BDD helpers with the same QUnit lifecycle |
|
|
197
|
+
| Browser | Thin re-export of QUnit's native browser API |
|
|
198
|
+
|
|
199
|
+
The browser path is literally QUnit itself, so you get full QUnit compatibility:
|
|
200
|
+
plugins, custom reporters, the event API (`QUnit.on`, `QUnit.done`, etc.), and the
|
|
201
|
+
familiar browser UI with zero extra layers.
|
|
132
202
|
|
|
133
|
-
|
|
134
|
-
you can use any code coverage tool you like. When running the tests in
|
|
135
|
-
`qunit`(the browser mode) code coverage support is limited.
|
|
203
|
+
---
|
|
136
204
|
|
|
137
|
-
|
|
138
|
-
|
|
205
|
+
## Code coverage
|
|
206
|
+
|
|
207
|
+
```sh
|
|
208
|
+
# Node (any c8-compatible reporter)
|
|
209
|
+
npx c8 node --test test/
|
|
210
|
+
|
|
211
|
+
# View HTML report
|
|
212
|
+
npx c8 --reporter=html node --test test/ && open coverage/index.html
|
|
139
213
|
```
|
|
140
214
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
Esbuild plugin interface is an ongoing development, we might be able to figure
|
|
155
|
-
out a way to generate this instrumentation with esbuild in the future, which
|
|
156
|
-
could allow code coverage for --browser mode.
|
|
215
|
+
Browser-mode coverage is limited because qunitx-cli bundles test files with esbuild.
|
|
216
|
+
Native ES import maps support in Puppeteer/Chrome would eliminate the bundling step
|
|
217
|
+
and unlock v8 instrumentation for browser coverage.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Links
|
|
222
|
+
|
|
223
|
+
- [QUnit API reference](https://api.qunitjs.com)
|
|
224
|
+
- [qunitx-cli](https://github.com/izelnakri/qunitx-cli) — browser runner / CI reporter
|
|
225
|
+
- [Node.js test runner docs](https://nodejs.org/api/test.html)
|
|
226
|
+
- [Deno testing docs](https://docs.deno.com/runtime/fundamentals/testing/)
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qunitx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.12.
|
|
4
|
+
"version": "0.12.2",
|
|
5
5
|
"description": "A universal test framework for testing any js file on node.js, browser or deno with QUnit API",
|
|
6
6
|
"author": "Izel Nakri",
|
|
7
7
|
"license": "MIT",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"browser"
|
|
45
45
|
],
|
|
46
46
|
"engines": {
|
|
47
|
-
"node": ">=
|
|
47
|
+
"node": ">=22.0.0"
|
|
48
48
|
},
|
|
49
49
|
"imports": {
|
|
50
50
|
"qunitx": {
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"repository": {
|
|
62
62
|
"type": "git",
|
|
63
|
-
"url": "https://github.com/izelnakri/qunitx.git"
|
|
63
|
+
"url": "git+https://github.com/izelnakri/qunitx.git"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"lint": "prettier --check \"test/**/*.js\" \"*.js\" \"package.json\"",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"prepack": "npm run build",
|
|
76
76
|
"test": "npm run test:browser && npm run test:node && npm run test:deno",
|
|
77
77
|
"test:dev": "npm run test | tee test-output.log",
|
|
78
|
-
"test:browser": "
|
|
78
|
+
"test:browser": "qunitx test/index.js --debug",
|
|
79
79
|
"test:deno": "deno test --allow-read --allow-env --allow-run test/index.js",
|
|
80
80
|
"test:node": "node --test test/index.js"
|
|
81
81
|
},
|
package/shims/deno/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AssertionError as DenoAssertionError } from "
|
|
1
|
+
import { AssertionError as DenoAssertionError } from "jsr:@std/assert";
|
|
2
2
|
import '../../vendor/qunit.js';
|
|
3
3
|
import Assert from '../shared/assert.js';
|
|
4
4
|
import ModuleContext from '../shared/module-context.js';
|
package/shims/deno/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { describe, beforeAll, afterAll } from "
|
|
1
|
+
import { describe, beforeAll, afterAll } from "jsr:@std/testing/bdd";
|
|
2
2
|
import ModuleContext from '../shared/module-context.js';
|
|
3
3
|
|
|
4
4
|
// NOTE: node.js beforeEach & afterEach is buggy because the TestContext it has is NOT correct reference when called, it gets the last context
|
|
@@ -10,7 +10,7 @@ export default function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
10
10
|
let targetModuleContent = moduleContent ? moduleContent : runtimeOptions;
|
|
11
11
|
let moduleContext = new ModuleContext(moduleName);
|
|
12
12
|
|
|
13
|
-
return describe(moduleName, { concurrency: true, ...targetRuntimeOptions },
|
|
13
|
+
return describe(moduleName, { concurrency: true, ...targetRuntimeOptions }, function () {
|
|
14
14
|
let beforeHooks = [];
|
|
15
15
|
let afterHooks = [];
|
|
16
16
|
|
package/shims/deno/test.js
CHANGED