qunitx 1.1.5 → 1.2.0

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.
@@ -29,7 +29,12 @@ export type { HookFn, HooksObject, PushResultInfo } from '../types.d.ts';
29
29
  * });
30
30
  * ```
31
31
  */
32
- export default function module(moduleName: string, runtimeOptions: object | ((hooks: HooksObject<Assert>) => void), moduleContent?: (hooks: HooksObject<Assert>, meta: {
32
+ export default function module(moduleName: string, moduleContent: (hooks: HooksObject<Assert>, meta: {
33
+ moduleName: string;
34
+ options: unknown;
35
+ }) => void): void;
36
+ /** Defines a test module (suite) with optional Deno BDD runtime options forwarded to `describe()`. */
37
+ export default function module(moduleName: string, runtimeOptions: object, moduleContent: (hooks: HooksObject<Assert>, meta: {
33
38
  moduleName: string;
34
39
  options: unknown;
35
40
  }) => void): void;
@@ -1,76 +1,50 @@
1
1
  import { describe, beforeAll, afterAll } from "jsr:@std/testing/bdd";
2
2
  import ModuleContext from "../shared/module-context.js";
3
- /**
4
- * Defines a test module (suite) for Deno's BDD test runner.
5
- *
6
- * Wraps `describe()` from `@std/testing/bdd` and sets up the QUnit lifecycle
7
- * (before/beforeEach/afterEach/after hooks, assertion counting, steps tracking).
8
- *
9
- * @param {string} moduleName - Name of the test suite
10
- * @param {object} [runtimeOptions] - Optional Deno BDD options forwarded to `describe()`
11
- * (e.g. `{ concurrency: false }`, `{ permissions: { read: true } }`)
12
- * @param {function} moduleContent - Callback that defines tests and hooks via `hooks.before`,
13
- * `hooks.beforeEach`, `hooks.afterEach`, `hooks.after`
14
- * @returns {void}
15
- * @example
16
- * ```js ignore
17
- * import { module, test } from "qunitx";
18
- *
19
- * module("Math", (hooks) => {
20
- * hooks.before((assert) => {
21
- * assert.step("before hook ran");
22
- * });
23
- *
24
- * test("addition", (assert) => {
25
- * assert.equal(2 + 2, 4);
26
- * });
27
- * });
28
- * ```
29
- */
30
- export default function module(moduleName, runtimeOptions, moduleContent) {
31
- const targetRuntimeOptions = moduleContent ? runtimeOptions : {};
32
- const targetModuleContent = (moduleContent ? moduleContent : runtimeOptions);
33
- const moduleContext = new ModuleContext(moduleName);
34
- describe(moduleName, { ...targetRuntimeOptions }, function () {
35
- const beforeHooks = [];
36
- const afterHooks = [];
37
- beforeAll(async function () {
38
- // before() assertions are attributed to the first direct test only (matching QUnit's model).
39
- // Tests inherit parent context via prototype chain, so no Object.assign needed.
40
- const firstTest = moduleContext.tests[0];
41
- const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
42
- for (const hook of beforeHooks) {
43
- await hook.call(moduleContext.userContext, beforeAssert);
44
- }
45
- });
46
- afterAll(async () => {
47
- for (const testContext of moduleContext.tests) {
48
- await testContext.assert.waitForAsyncOps();
49
- }
50
- const lastTest = moduleContext.tests[moduleContext.tests.length - 1];
51
- if (lastTest) {
52
- for (let j = afterHooks.length - 1; j >= 0; j--) {
53
- await afterHooks[j].call(lastTest.userContext, lastTest.assert);
54
- }
55
- }
56
- for (let i = 0, len = moduleContext.tests.length; i < len; i++) {
57
- moduleContext.tests[i].finish();
58
- }
59
- });
60
- targetModuleContent.call(moduleContext.userContext, {
61
- before(beforeFn) {
62
- beforeHooks.push(beforeFn);
63
- },
64
- beforeEach(beforeEachFn) {
65
- moduleContext.beforeEachHooks.push(beforeEachFn);
66
- },
67
- afterEach(afterEachFn) {
68
- moduleContext.afterEachHooks.push(afterEachFn);
69
- },
70
- after(afterFn) {
71
- afterHooks.push(afterFn);
72
- }
73
- }, { moduleName, options: runtimeOptions });
74
- ModuleContext.currentModuleChain.pop();
3
+ function module(moduleName, runtimeOptions, moduleContent) {
4
+ const targetRuntimeOptions = moduleContent ? runtimeOptions : {};
5
+ const targetModuleContent = moduleContent ? moduleContent : runtimeOptions;
6
+ const moduleContext = new ModuleContext(moduleName);
7
+ describe(moduleName, { ...targetRuntimeOptions }, function() {
8
+ const beforeHooks = [];
9
+ const afterHooks = [];
10
+ beforeAll(async function() {
11
+ const firstTest = moduleContext.tests[0];
12
+ const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
13
+ for (const hook of beforeHooks) {
14
+ await hook.call(moduleContext.userContext, beforeAssert);
15
+ }
75
16
  });
17
+ afterAll(async () => {
18
+ for (const testContext of moduleContext.tests) {
19
+ await testContext.assert.waitForAsyncOps();
20
+ }
21
+ const lastTest = moduleContext.tests[moduleContext.tests.length - 1];
22
+ if (lastTest) {
23
+ for (let j = afterHooks.length - 1; j >= 0; j--) {
24
+ await afterHooks[j].call(lastTest.userContext, lastTest.assert);
25
+ }
26
+ }
27
+ for (let i = 0, len = moduleContext.tests.length; i < len; i++) {
28
+ moduleContext.tests[i].finish();
29
+ }
30
+ });
31
+ targetModuleContent.call(moduleContext.userContext, {
32
+ before(beforeFn) {
33
+ beforeHooks.push(beforeFn);
34
+ },
35
+ beforeEach(beforeEachFn) {
36
+ moduleContext.beforeEachHooks.push(beforeEachFn);
37
+ },
38
+ afterEach(afterEachFn) {
39
+ moduleContext.afterEachHooks.push(afterEachFn);
40
+ },
41
+ after(afterFn) {
42
+ afterHooks.push(afterFn);
43
+ }
44
+ }, { moduleName, options: runtimeOptions });
45
+ ModuleContext.currentModuleChain.pop();
46
+ });
76
47
  }
48
+ export {
49
+ module as default
50
+ };
@@ -30,10 +30,12 @@ export type { PushResultInfo } from '../types.d.ts';
30
30
  * });
31
31
  * ```
32
32
  */
33
- export default function test(testName: string, runtimeOptions: object | ((assert: Assert, meta: {
33
+ export default function test(testName: string, testContent: (assert: Assert, meta: {
34
34
  testName: string;
35
35
  options: unknown;
36
- }) => void | Promise<void>), testContent?: (assert: Assert, meta: {
36
+ }) => void | Promise<void>): void;
37
+ /** Defines an individual test with optional Deno BDD runtime options forwarded to `it()`. */
38
+ export default function test(testName: string, runtimeOptions: object, testContent: (assert: Assert, meta: {
37
39
  testName: string;
38
40
  options: unknown;
39
41
  }) => void | Promise<void>): void;
package/dist/deno/test.js CHANGED
@@ -1,62 +1,33 @@
1
1
  import { it } from "jsr:@std/testing/bdd";
2
2
  import TestContext from "../shared/test-context.js";
3
3
  import ModuleContext from "../shared/module-context.js";
4
- /**
5
- * Defines an individual test within a module for Deno's BDD test runner.
6
- *
7
- * Wraps `it()` from `@std/testing/bdd` and handles the full QUnit lifecycle:
8
- * beforeEach/afterEach hooks, async assertion waiting, and step verification.
9
- *
10
- * Must be called inside a `module()` callback.
11
- *
12
- * @param {string} testName - Name of the test
13
- * @param {object} [runtimeOptions] - Optional Deno BDD options forwarded to `it()`
14
- * (e.g. `{ concurrency: false }`, `{ sanitizeExit: false }`)
15
- * @param {function} testContent - Test callback receiving `(assert, { testName, options })`
16
- * @returns {void}
17
- * @example
18
- * ```js ignore
19
- * import { module, test } from "qunitx";
20
- *
21
- * module("Math", () => {
22
- * test("addition", (assert) => {
23
- * assert.equal(1 + 1, 2);
24
- * });
25
- *
26
- * test("async resolves correctly", async (assert) => {
27
- * const result = await Promise.resolve(42);
28
- * assert.strictEqual(result, 42);
29
- * });
30
- * });
31
- * ```
32
- */
33
- export default function test(testName, runtimeOptions, testContent) {
34
- const moduleContext = ModuleContext.lastModule;
35
- if (!moduleContext) {
36
- throw new Error(`Test '${testName}' called outside of module context.`);
4
+ function test(testName, runtimeOptions, testContent) {
5
+ const moduleContext = ModuleContext.lastModule;
6
+ if (!moduleContext) {
7
+ throw new Error(`Test '${testName}' called outside of module context.`);
8
+ }
9
+ const targetRuntimeOptions = testContent ? runtimeOptions : {};
10
+ const targetTestContent = testContent ? testContent : runtimeOptions;
11
+ const context = new TestContext(testName, moduleContext);
12
+ const userContext = Object.create(moduleContext.userContext);
13
+ context.userContext = userContext;
14
+ it(testName, { ...targetRuntimeOptions }, async function() {
15
+ for (const module of context.module.moduleChain) {
16
+ for (const hook of module.beforeEachHooks) {
17
+ await hook.call(userContext, context.assert);
18
+ }
37
19
  }
38
- const targetRuntimeOptions = testContent ? runtimeOptions : {};
39
- const targetTestContent = (testContent ? testContent : runtimeOptions);
40
- const context = new TestContext(testName, moduleContext);
41
- // Each test gets a fresh plain object inheriting from the module's user context.
42
- // This matches QUnit's prototype-chain model: before() sets props on the module context,
43
- // tests inherit them, and each test's own writes don't pollute sibling tests.
44
- const userContext = Object.create(moduleContext.userContext);
45
- context.userContext = userContext;
46
- it(testName, { ...targetRuntimeOptions }, async function () {
47
- for (const module of context.module.moduleChain) {
48
- for (const hook of module.beforeEachHooks) {
49
- await hook.call(userContext, context.assert);
50
- }
51
- }
52
- const result = await targetTestContent.call(userContext, context.assert, { testName, options: runtimeOptions });
53
- await context.assert.waitForAsyncOps();
54
- for (let i = context.module.moduleChain.length - 1; i >= 0; i--) {
55
- const module = context.module.moduleChain[i];
56
- for (let j = module.afterEachHooks.length - 1; j >= 0; j--) {
57
- await module.afterEachHooks[j].call(userContext, context.assert);
58
- }
59
- }
60
- return result;
61
- });
20
+ const result = await targetTestContent.call(userContext, context.assert, { testName, options: runtimeOptions });
21
+ await context.assert.waitForAsyncOps();
22
+ for (let i = context.module.moduleChain.length - 1; i >= 0; i--) {
23
+ const module = context.module.moduleChain[i];
24
+ for (let j = module.afterEachHooks.length - 1; j >= 0; j--) {
25
+ await module.afterEachHooks[j].call(userContext, context.assert);
26
+ }
27
+ }
28
+ return result;
29
+ });
62
30
  }
31
+ export {
32
+ test as default
33
+ };
@@ -1,8 +1,8 @@
1
1
  import Assert from '../shared/assert.d.ts';
2
2
  import Module from './module.d.ts';
3
3
  import Test from './test.d.ts';
4
- export declare const module: typeof Module;
5
- export declare const test: typeof Test;
4
+ export { default as module } from './module.d.ts';
5
+ export { default as test } from './test.d.ts';
6
6
  export { Assert };
7
7
  declare const _default: {
8
8
  AssertionError: import("../types.d.ts").AssertionErrorConstructor;
@@ -1,6 +1,6 @@
1
- import { AssertionError } from 'node:assert';
2
- import { inspect } from 'node:util';
3
- import QUnit from '../../vendor/qunit.js';
1
+ import { AssertionError } from "node:assert";
2
+ import { inspect } from "node:util";
3
+ import QUnit from "../../vendor/qunit.js";
4
4
  import Assert from "../shared/assert.js";
5
5
  import ModuleContext from "../shared/module-context.js";
6
6
  import TestContext from "../shared/test-context.js";
@@ -14,7 +14,12 @@ TestContext.Assert = Assert;
14
14
  Object.freeze(Assert);
15
15
  Object.freeze(ModuleContext);
16
16
  Object.freeze(TestContext);
17
- export const module = Module;
18
- export const test = Test;
19
- export { Assert };
20
- export default { AssertionError: Assert.AssertionError, module, test, config: {} };
17
+ import { default as default2 } from "./module.js";
18
+ import { default as default3 } from "./test.js";
19
+ var node_default = { AssertionError: Assert.AssertionError, module: Module, test: Test, config: {} };
20
+ export {
21
+ Assert,
22
+ node_default as default,
23
+ default2 as module,
24
+ default3 as test
25
+ };
@@ -1,6 +1,10 @@
1
1
  import type Assert from '../shared/assert.d.ts';
2
2
  import type { HooksObject } from '../types.d.ts';
3
- export default function module(moduleName: string, runtimeOptions: object | ((hooks: HooksObject<Assert>) => void), moduleContent?: (hooks: HooksObject<Assert>, meta: {
3
+ export default function module(moduleName: string, moduleContent: (hooks: HooksObject<Assert>, meta: {
4
+ moduleName: string;
5
+ options: unknown;
6
+ }) => void): void;
7
+ export default function module(moduleName: string, runtimeOptions: object, moduleContent: (hooks: HooksObject<Assert>, meta: {
4
8
  moduleName: string;
5
9
  options: unknown;
6
10
  }) => void): void;
@@ -1,49 +1,50 @@
1
- import { describe, before as beforeAll, after as afterAll } from 'node:test';
1
+ import { describe, before as beforeAll, after as afterAll } from "node:test";
2
2
  import ModuleContext from "../shared/module-context.js";
3
- export default function module(moduleName, runtimeOptions, moduleContent) {
4
- const targetRuntimeOptions = moduleContent ? runtimeOptions : {};
5
- const targetModuleContent = (moduleContent ? moduleContent : runtimeOptions);
6
- const moduleContext = new ModuleContext(moduleName);
7
- describe(moduleName, { ...targetRuntimeOptions }, function () {
8
- const beforeHooks = [];
9
- const afterHooks = [];
10
- beforeAll(async function () {
11
- // before() assertions are attributed to the first direct test only (matching QUnit's model).
12
- // Tests inherit parent context via prototype chain, so no Object.assign needed.
13
- const firstTest = moduleContext.tests[0];
14
- const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
15
- for (const hook of beforeHooks) {
16
- await hook.call(moduleContext.userContext, beforeAssert);
17
- }
18
- });
19
- afterAll(async () => {
20
- for (const testContext of moduleContext.tests) {
21
- await testContext.assert.waitForAsyncOps();
22
- }
23
- const lastTest = moduleContext.tests[moduleContext.tests.length - 1];
24
- if (lastTest) {
25
- for (let j = afterHooks.length - 1; j >= 0; j--) {
26
- await afterHooks[j].call(lastTest.userContext, lastTest.assert);
27
- }
28
- }
29
- for (let i = 0, len = moduleContext.tests.length; i < len; i++) {
30
- moduleContext.tests[i].finish();
31
- }
32
- });
33
- targetModuleContent.call(moduleContext.userContext, {
34
- before(beforeFn) {
35
- beforeHooks.push(beforeFn);
36
- },
37
- beforeEach(beforeEachFn) {
38
- moduleContext.beforeEachHooks.push(beforeEachFn);
39
- },
40
- afterEach(afterEachFn) {
41
- moduleContext.afterEachHooks.push(afterEachFn);
42
- },
43
- after(afterFn) {
44
- afterHooks.push(afterFn);
45
- }
46
- }, { moduleName, options: runtimeOptions });
47
- ModuleContext.currentModuleChain.pop();
3
+ function module(moduleName, runtimeOptions, moduleContent) {
4
+ const targetRuntimeOptions = moduleContent ? runtimeOptions : {};
5
+ const targetModuleContent = moduleContent ? moduleContent : runtimeOptions;
6
+ const moduleContext = new ModuleContext(moduleName);
7
+ describe(moduleName, { ...targetRuntimeOptions }, function() {
8
+ const beforeHooks = [];
9
+ const afterHooks = [];
10
+ beforeAll(async function() {
11
+ const firstTest = moduleContext.tests[0];
12
+ const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
13
+ for (const hook of beforeHooks) {
14
+ await hook.call(moduleContext.userContext, beforeAssert);
15
+ }
48
16
  });
17
+ afterAll(async () => {
18
+ for (const testContext of moduleContext.tests) {
19
+ await testContext.assert.waitForAsyncOps();
20
+ }
21
+ const lastTest = moduleContext.tests[moduleContext.tests.length - 1];
22
+ if (lastTest) {
23
+ for (let j = afterHooks.length - 1; j >= 0; j--) {
24
+ await afterHooks[j].call(lastTest.userContext, lastTest.assert);
25
+ }
26
+ }
27
+ for (let i = 0, len = moduleContext.tests.length; i < len; i++) {
28
+ moduleContext.tests[i].finish();
29
+ }
30
+ });
31
+ targetModuleContent.call(moduleContext.userContext, {
32
+ before(beforeFn) {
33
+ beforeHooks.push(beforeFn);
34
+ },
35
+ beforeEach(beforeEachFn) {
36
+ moduleContext.beforeEachHooks.push(beforeEachFn);
37
+ },
38
+ afterEach(afterEachFn) {
39
+ moduleContext.afterEachHooks.push(afterEachFn);
40
+ },
41
+ after(afterFn) {
42
+ afterHooks.push(afterFn);
43
+ }
44
+ }, { moduleName, options: runtimeOptions });
45
+ ModuleContext.currentModuleChain.pop();
46
+ });
49
47
  }
48
+ export {
49
+ module as default
50
+ };
@@ -1,8 +1,9 @@
1
1
  import type Assert from '../shared/assert.d.ts';
2
- export default function test(testName: string, runtimeOptions: object | ((assert: Assert, meta: {
2
+ export default function test(testName: string, testContent: (assert: Assert, meta: {
3
3
  testName: string;
4
4
  options: unknown;
5
- }) => void | Promise<void>), testContent?: (assert: Assert, meta: {
5
+ }) => void | Promise<void>): void;
6
+ export default function test(testName: string, runtimeOptions: object, testContent: (assert: Assert, meta: {
6
7
  testName: string;
7
8
  options: unknown;
8
9
  }) => void | Promise<void>): void;
package/dist/node/test.js CHANGED
@@ -1,33 +1,33 @@
1
- import { it } from 'node:test';
1
+ import { it } from "node:test";
2
2
  import TestContext from "../shared/test-context.js";
3
3
  import ModuleContext from "../shared/module-context.js";
4
- export default function test(testName, runtimeOptions, testContent) {
5
- const moduleContext = ModuleContext.lastModule;
6
- if (!moduleContext) {
7
- throw new Error(`Test '${testName}' called outside of module context.`);
4
+ function test(testName, runtimeOptions, testContent) {
5
+ const moduleContext = ModuleContext.lastModule;
6
+ if (!moduleContext) {
7
+ throw new Error(`Test '${testName}' called outside of module context.`);
8
+ }
9
+ const targetRuntimeOptions = testContent ? runtimeOptions : {};
10
+ const targetTestContent = testContent ? testContent : runtimeOptions;
11
+ const context = new TestContext(testName, moduleContext);
12
+ const userContext = Object.create(moduleContext.userContext);
13
+ context.userContext = userContext;
14
+ it(testName, { ...targetRuntimeOptions }, async function() {
15
+ for (const module of context.module.moduleChain) {
16
+ for (const hook of module.beforeEachHooks) {
17
+ await hook.call(userContext, context.assert);
18
+ }
8
19
  }
9
- const targetRuntimeOptions = testContent ? runtimeOptions : {};
10
- const targetTestContent = (testContent ? testContent : runtimeOptions);
11
- const context = new TestContext(testName, moduleContext);
12
- // Each test gets a fresh plain object inheriting from the module's user context.
13
- // This matches QUnit's prototype-chain model: before() sets props on the module context,
14
- // tests inherit them, and each test's own writes don't pollute sibling tests.
15
- const userContext = Object.create(moduleContext.userContext);
16
- context.userContext = userContext;
17
- it(testName, { ...targetRuntimeOptions }, async function () {
18
- for (const module of context.module.moduleChain) {
19
- for (const hook of module.beforeEachHooks) {
20
- await hook.call(userContext, context.assert);
21
- }
22
- }
23
- const result = await targetTestContent.call(userContext, context.assert, { testName, options: runtimeOptions });
24
- await context.assert.waitForAsyncOps();
25
- for (let i = context.module.moduleChain.length - 1; i >= 0; i--) {
26
- const module = context.module.moduleChain[i];
27
- for (let j = module.afterEachHooks.length - 1; j >= 0; j--) {
28
- await module.afterEachHooks[j].call(userContext, context.assert);
29
- }
30
- }
31
- return result;
32
- });
20
+ const result = await targetTestContent.call(userContext, context.assert, { testName, options: runtimeOptions });
21
+ await context.assert.waitForAsyncOps();
22
+ for (let i = context.module.moduleChain.length - 1; i >= 0; i--) {
23
+ const module = context.module.moduleChain[i];
24
+ for (let j = module.afterEachHooks.length - 1; j >= 0; j--) {
25
+ await module.afterEachHooks[j].call(userContext, context.assert);
26
+ }
27
+ }
28
+ return result;
29
+ });
33
30
  }
31
+ export {
32
+ test as default
33
+ };