1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169 |
x1
x1
x1
x1
x1
x1
x1
x1
x1
x67
x67
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1
x1 |
|
/**
* QUnitX — universal test library that runs the same test file in Node.js, Deno, and browser.
*
* Wraps QUnit's assertion API over each runtime's native BDD test runner so you only
* write your tests once.
*
* @example
* ```js
* import { module, test } from "qunitx";
*
* module("Math", (hooks) => {
* hooks.before((assert) => assert.step("setup"));
*
* test("addition", (assert) => {
* assert.equal(1 + 1, 2);
* });
*
* test("async", async (assert) => {
* const n = await Promise.resolve(42);
* assert.strictEqual(n, 42);
* });
* });
* ```
*
* @module
*/
import { AssertionError as DenoAssertionError } from "jsr:@std/assert";
import type { AssertionErrorOptions } from "../types.ts";
import '../../vendor/qunit.js';
import Assert from '../shared/assert.ts';
import ModuleContext from '../shared/module-context.ts';
import TestContext from '../shared/test-context.ts';
import Module from './module.ts';
import Test from './test.ts';
/**
* Thrown when an assertion fails. Extends Deno's built-in `AssertionError`
* so it integrates cleanly with Deno's test runner output.
*
* You rarely construct this directly — assertion methods on {@linkcode Assert}
* throw it automatically on failure.
*
* @example
* ```js
* import { AssertionError } from "qunitx";
*
* try {
* throw new AssertionError({ message: "something went wrong" });
* } catch (e) {
* console.log(e instanceof AssertionError); // true
* }
* ```
*/
export class AssertionError extends DenoAssertionError {
constructor(object: AssertionErrorOptions) {
super(object.message ?? 'Assertion failed');
}
}
Assert.QUnit = (globalThis as typeof globalThis & { QUnit: typeof Assert.QUnit }).QUnit;
Assert.AssertionError = AssertionError;
Assert.inspect = Deno.inspect;
ModuleContext.Assert = Assert;
TestContext.Assert = Assert;
Object.freeze(Assert);
Object.freeze(ModuleContext);
Object.freeze(TestContext);
export { Assert };
/**
* Defines a test module (suite). Wraps Deno's `describe()` and sets up the
* QUnit lifecycle — `before`, `beforeEach`, `afterEach`, and `after` hooks,
* assertion counting, and step tracking.
*
* Each {@linkcode test} inside the callback receives an {@linkcode Assert} instance.
* Modules can be nested by calling `module()` inside another module's callback.
*
* @param {string} moduleName - Name of the test suite.
* @param {object} [runtimeOptions] - Optional Deno BDD options forwarded to `describe()`
* (e.g. `{ concurrency: false }`, `{ permissions: { read: true } }`).
* @param {function} moduleContent - Callback that defines tests and hooks.
* Receives `(hooks, { moduleName, options })` where `hooks` exposes
* `before`, `beforeEach`, `afterEach`, and `after`.
* @example
* ```js
* import { module, test } from "qunitx";
*
* module("Math", (hooks) => {
* hooks.before((assert) => {
* assert.step("before hook ran");
* });
*
* test("addition", (assert) => {
* assert.equal(2 + 2, 4);
* });
* });
* ```
* @example
* ```js
* // Nested modules
* module("Outer", () => {
* module("Inner", () => {
* test("nested test", (assert) => {
* assert.ok(true);
* });
* });
* });
* ```
*/
export { default as module } from './module.ts';
/**
* Defines an individual test. Wraps Deno's `it()` and handles the full QUnit
* lifecycle: `beforeEach`/`afterEach` hooks, async assertion waiting, and step
* verification. Must be called inside a {@linkcode module} callback.
*
* The test callback receives `(assert, { testName, options })` where `assert`
* is an {@linkcode Assert} instance.
*
* @param {string} testName - Name of the test.
* @param {object} [runtimeOptions] - Optional Deno BDD options forwarded to `it()`
* (e.g. `{ concurrency: false }`, `{ sanitizeExit: false }`).
* @param {function} testContent - Test callback receiving `(assert, { testName, options })`.
* @example
* ```js
* import { module, test } from "qunitx";
*
* module("Math", () => {
* test("addition", (assert) => {
* assert.equal(1 + 1, 2);
* });
*
* test("async resolves correctly", async (assert) => {
* const result = await Promise.resolve(42);
* assert.strictEqual(result, 42);
* });
* });
* ```
*/
export { default as test } from './test.ts';
/**
* The default export provides the full QUnitX API as a single object.
*
* @example
* ```js
* import qunitx from "qunitx";
*
* qunitx.module("Math", () => {
* qunitx.test("addition", (assert) => {
* assert.equal(1 + 1, 2);
* });
* });
* ```
*
* @property {Function} module - Defines a test suite. Wraps Deno's `describe()` with
* QUnit lifecycle hooks (`before`, `beforeEach`, `afterEach`, `after`).
* See the named {@linkcode module} export for full parameter documentation.
* @property {Function} test - Defines an individual test inside a `module()` callback.
* Receives an {@linkcode Assert} instance as its first argument.
* See the named {@linkcode test} export for full parameter documentation.
* @property {typeof AssertionError} AssertionError - The error class thrown when an
* assertion fails. Extends Deno's built-in `AssertionError`.
* @property {object} config - Runtime configuration object (currently unused; reserved
* for future QUnit config compatibility).
*/
export default { AssertionError: Assert.AssertionError, module: Module, test: Test, config: {} };
|