qunitx 1.2.5 → 1.2.7
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/README.md +104 -20
- package/dist/.build-hash +1 -1
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser/index.d.ts +21 -20
- package/dist/browser/index.js +55 -52
- package/dist/deno/index.d.ts +20 -19
- package/dist/deno/index.js +135 -153
- package/dist/deno/module.d.ts +3 -2
- package/dist/deno/module.js +15 -12
- package/dist/deno/test.d.ts +2 -2
- package/dist/deno/test.js +26 -16
- package/dist/node/index.d.ts +3 -2
- package/dist/node/index.js +1 -1
- package/dist/node/module.d.ts +1 -0
- package/dist/node/module.js +15 -12
- package/dist/node/test.js +25 -15
- package/dist/shared/assert.d.ts +2 -2
- package/dist/shared/assert.js +27 -32
- package/dist/shared/index.d.ts +1 -13
- package/dist/shared/index.js +11 -13
- package/dist/shared/module-context.d.ts +3 -3
- package/dist/shared/module-context.js +4 -4
- package/dist/shared/test-context.d.ts +11 -16
- package/dist/shared/test-context.js +38 -65
- package/dist/types.d.ts +2 -1
- package/package.json +2 -2
- package/shims/deno/index.ts +21 -21
- package/shims/deno/module.ts +37 -15
- package/shims/deno/test.ts +32 -19
- package/shims/shared/assert.ts +38 -33
- package/shims/shared/index.ts +14 -27
- package/shims/shared/module-context.ts +5 -5
- package/shims/shared/test-context.ts +41 -74
- package/shims/types.ts +2 -1
package/dist/deno/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { afterAll, beforeAll, describe } from "jsr:@std/testing/bdd";
|
|
2
2
|
import ModuleContext from "../shared/module-context.js";
|
|
3
3
|
function module(moduleName, runtimeOptions, moduleContent) {
|
|
4
4
|
const targetRuntimeOptions = moduleContent ? runtimeOptions : {};
|
|
@@ -8,12 +8,12 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
8
8
|
});
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const targetModuleContent = moduleContent
|
|
11
|
+
const targetModuleContent = moduleContent ?? runtimeOptions;
|
|
12
12
|
const moduleContext = new ModuleContext(moduleName);
|
|
13
13
|
describe(moduleName, { ...targetRuntimeOptions }, function() {
|
|
14
14
|
const beforeHooks = [];
|
|
15
15
|
const afterHooks = [];
|
|
16
|
-
beforeAll(async
|
|
16
|
+
beforeAll(async () => {
|
|
17
17
|
const firstTest = moduleContext.tests[0];
|
|
18
18
|
const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
|
|
19
19
|
for (const hook of beforeHooks) {
|
|
@@ -21,17 +21,16 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
afterAll(async () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const lastTest = moduleContext.tests[moduleContext.tests.length - 1];
|
|
24
|
+
const allAsyncOps = moduleContext.tests.flatMap((t) => t.asyncOps);
|
|
25
|
+
if (allAsyncOps.length > 0) await Promise.all(allAsyncOps);
|
|
26
|
+
const lastTest = moduleContext.tests.at(-1);
|
|
28
27
|
if (lastTest) {
|
|
29
|
-
for (
|
|
30
|
-
await
|
|
28
|
+
for (const hook of afterHooks.toReversed()) {
|
|
29
|
+
await hook.call(lastTest.userContext, lastTest.assert, { context: lastTest.userContext });
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
for (
|
|
34
|
-
|
|
32
|
+
for (const testCtx of moduleContext.tests) {
|
|
33
|
+
testCtx.finish();
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
36
|
targetModuleContent.call(moduleContext.userContext, {
|
|
@@ -47,7 +46,7 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
47
46
|
after(afterFn) {
|
|
48
47
|
afterHooks.push(afterFn);
|
|
49
48
|
}
|
|
50
|
-
}, { moduleName, options:
|
|
49
|
+
}, { moduleName, options: targetRuntimeOptions, context: moduleContext.userContext });
|
|
51
50
|
ModuleContext.currentModuleChain.pop();
|
|
52
51
|
});
|
|
53
52
|
}
|
|
@@ -55,6 +54,10 @@ module.skip = function skipModule(moduleName, _moduleContent) {
|
|
|
55
54
|
describe(moduleName, { ignore: true }, function() {
|
|
56
55
|
});
|
|
57
56
|
};
|
|
57
|
+
module.todo = function todoModule(moduleName, _moduleContent) {
|
|
58
|
+
describe(moduleName, { ignore: true }, function() {
|
|
59
|
+
});
|
|
60
|
+
};
|
|
58
61
|
export {
|
|
59
62
|
module as default
|
|
60
63
|
};
|
package/dist/deno/test.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import type Assert from '../shared/assert.d.ts';
|
|
2
|
-
export type { Assert };
|
|
3
|
-
export type { PushResultInfo } from '../types.d.ts';
|
|
4
2
|
/**
|
|
5
3
|
* Defines an individual test within a module for Deno's BDD test runner.
|
|
6
4
|
*
|
|
@@ -48,3 +46,5 @@ declare namespace test {
|
|
|
48
46
|
var todo: (testName: string, _testContent?: unknown) => void;
|
|
49
47
|
}
|
|
50
48
|
export default test;
|
|
49
|
+
export type { Assert };
|
|
50
|
+
export type { PushResultInfo } from '../types.d.ts';
|
package/dist/deno/test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { it } from "jsr:@std/testing/bdd";
|
|
2
|
-
import TestContext from "../shared/test-context.js";
|
|
3
2
|
import ModuleContext from "../shared/module-context.js";
|
|
3
|
+
import TestContext from "../shared/test-context.js";
|
|
4
4
|
function test(testName, runtimeOptions, testContent) {
|
|
5
5
|
const moduleContext = ModuleContext.lastModule;
|
|
6
6
|
if (!moduleContext) {
|
|
@@ -13,26 +13,36 @@ function test(testName, runtimeOptions, testContent) {
|
|
|
13
13
|
});
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
|
-
const targetTestContent = testContent
|
|
16
|
+
const targetTestContent = testContent ?? runtimeOptions;
|
|
17
17
|
const context = new TestContext(testName, moduleContext);
|
|
18
18
|
const userContext = Object.create(moduleContext.userContext);
|
|
19
19
|
context.userContext = userContext;
|
|
20
|
-
it(testName, { ...targetRuntimeOptions },
|
|
20
|
+
it(testName, { ...targetRuntimeOptions }, function() {
|
|
21
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
22
|
+
context.rejectTimeout = reject;
|
|
21
23
|
const hookMeta = { context: userContext };
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
24
|
+
(async () => {
|
|
25
|
+
try {
|
|
26
|
+
for (const mod of context.module.moduleChain) {
|
|
27
|
+
for (const hook of mod.beforeEachHooks) {
|
|
28
|
+
await hook.call(userContext, context.assert, hookMeta);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await targetTestContent.call(userContext, context.assert, { testName, options: targetRuntimeOptions, context: userContext });
|
|
32
|
+
await context.assert.waitForAsyncOps();
|
|
33
|
+
for (const mod of context.module.moduleChain.toReversed()) {
|
|
34
|
+
for (const hook of mod.afterEachHooks.toReversed()) {
|
|
35
|
+
await hook.call(userContext, context.assert, hookMeta);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
resolve();
|
|
39
|
+
} catch (err) {
|
|
40
|
+
reject(err);
|
|
41
|
+
} finally {
|
|
42
|
+
context.clearTimeoutHandle();
|
|
33
43
|
}
|
|
34
|
-
}
|
|
35
|
-
return
|
|
44
|
+
})();
|
|
45
|
+
return promise;
|
|
36
46
|
});
|
|
37
47
|
}
|
|
38
48
|
test.skip = function skipTest(testName, _testContent) {
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
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 { default as module } from './module.d.ts';
|
|
5
|
-
export { default as test } from './test.d.ts';
|
|
6
4
|
export { Assert };
|
|
5
|
+
export { default as module } from './module.d.ts';
|
|
7
6
|
export declare const skip: (testName: string, _testContent?: unknown) => void;
|
|
7
|
+
export { default as test } from './test.d.ts';
|
|
8
8
|
export declare const todo: (testName: string, testContent?: (assert: Assert, meta: {
|
|
9
9
|
testName: string;
|
|
10
10
|
options: unknown;
|
|
11
11
|
}) => void | Promise<void>) => void;
|
|
12
|
+
export type { HookFn, HooksObject, PushResultInfo, TestFn } from '../types.d.ts';
|
|
12
13
|
declare const _default: {
|
|
13
14
|
AssertionError: import("../types.d.ts").AssertionErrorConstructor;
|
|
14
15
|
module: typeof Module;
|
package/dist/node/index.js
CHANGED
|
@@ -15,8 +15,8 @@ Object.freeze(Assert);
|
|
|
15
15
|
Object.freeze(ModuleContext);
|
|
16
16
|
Object.freeze(TestContext);
|
|
17
17
|
import { default as default2 } from "./module.js";
|
|
18
|
-
import { default as default3 } from "./test.js";
|
|
19
18
|
const skip = Test.skip;
|
|
19
|
+
import { default as default3 } from "./test.js";
|
|
20
20
|
const todo = Test.todo;
|
|
21
21
|
var node_default = { AssertionError: Assert.AssertionError, module: Module, test: Test, config: {} };
|
|
22
22
|
export {
|
package/dist/node/module.d.ts
CHANGED
|
@@ -46,5 +46,6 @@ declare function module(moduleName: string, runtimeOptions: object, moduleConten
|
|
|
46
46
|
}) => void): void;
|
|
47
47
|
declare namespace module {
|
|
48
48
|
var skip: (moduleName: string, _moduleContent?: unknown) => void;
|
|
49
|
+
var todo: (moduleName: string, _moduleContent?: unknown) => void;
|
|
49
50
|
}
|
|
50
51
|
export default module;
|
package/dist/node/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { after as afterAll, before as beforeAll, describe } from "node:test";
|
|
2
2
|
import ModuleContext from "../shared/module-context.js";
|
|
3
3
|
function module(moduleName, runtimeOptions, moduleContent) {
|
|
4
4
|
const targetRuntimeOptions = moduleContent ? runtimeOptions : {};
|
|
@@ -8,12 +8,12 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
8
8
|
});
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
|
-
const targetModuleContent = moduleContent
|
|
11
|
+
const targetModuleContent = moduleContent ?? runtimeOptions;
|
|
12
12
|
const moduleContext = new ModuleContext(moduleName);
|
|
13
13
|
describe(moduleName, { ...targetRuntimeOptions }, function() {
|
|
14
14
|
const beforeHooks = [];
|
|
15
15
|
const afterHooks = [];
|
|
16
|
-
beforeAll(async
|
|
16
|
+
beforeAll(async () => {
|
|
17
17
|
const firstTest = moduleContext.tests[0];
|
|
18
18
|
const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
|
|
19
19
|
for (const hook of beforeHooks) {
|
|
@@ -21,17 +21,16 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
afterAll(async () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const lastTest = moduleContext.tests[moduleContext.tests.length - 1];
|
|
24
|
+
const allAsyncOps = moduleContext.tests.flatMap((t) => t.asyncOps);
|
|
25
|
+
if (allAsyncOps.length > 0) await Promise.all(allAsyncOps);
|
|
26
|
+
const lastTest = moduleContext.tests.at(-1);
|
|
28
27
|
if (lastTest) {
|
|
29
|
-
for (
|
|
30
|
-
await
|
|
28
|
+
for (const hook of afterHooks.toReversed()) {
|
|
29
|
+
await hook.call(lastTest.userContext, lastTest.assert, { context: lastTest.userContext });
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
for (
|
|
34
|
-
|
|
32
|
+
for (const testCtx of moduleContext.tests) {
|
|
33
|
+
testCtx.finish();
|
|
35
34
|
}
|
|
36
35
|
});
|
|
37
36
|
targetModuleContent.call(moduleContext.userContext, {
|
|
@@ -47,7 +46,7 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
47
46
|
after(afterFn) {
|
|
48
47
|
afterHooks.push(afterFn);
|
|
49
48
|
}
|
|
50
|
-
}, { moduleName, options:
|
|
49
|
+
}, { moduleName, options: targetRuntimeOptions, context: moduleContext.userContext });
|
|
51
50
|
ModuleContext.currentModuleChain.pop();
|
|
52
51
|
});
|
|
53
52
|
}
|
|
@@ -55,6 +54,10 @@ module.skip = function skipModule(moduleName, _moduleContent) {
|
|
|
55
54
|
describe(moduleName, { skip: true }, function() {
|
|
56
55
|
});
|
|
57
56
|
};
|
|
57
|
+
module.todo = function todoModule(moduleName, _moduleContent) {
|
|
58
|
+
describe(moduleName, { skip: true }, function() {
|
|
59
|
+
});
|
|
60
|
+
};
|
|
58
61
|
export {
|
|
59
62
|
module as default
|
|
60
63
|
};
|
package/dist/node/test.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { it } from "node:test";
|
|
2
|
-
import TestContext from "../shared/test-context.js";
|
|
3
2
|
import ModuleContext from "../shared/module-context.js";
|
|
3
|
+
import TestContext from "../shared/test-context.js";
|
|
4
4
|
function test(testName, runtimeOptions, testContent) {
|
|
5
5
|
const moduleContext = ModuleContext.lastModule;
|
|
6
6
|
if (!moduleContext) {
|
|
@@ -18,22 +18,32 @@ function test(testName, runtimeOptions, testContent) {
|
|
|
18
18
|
const userContext = Object.create(moduleContext.userContext);
|
|
19
19
|
context.userContext = userContext;
|
|
20
20
|
if (todo) moduleContext.tests.pop();
|
|
21
|
-
it(testName, { ...targetRuntimeOptions },
|
|
21
|
+
it(testName, { ...targetRuntimeOptions }, function() {
|
|
22
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
23
|
+
context.rejectTimeout = reject;
|
|
22
24
|
const hookMeta = { context: userContext };
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
(async () => {
|
|
26
|
+
try {
|
|
27
|
+
for (const mod of context.module.moduleChain) {
|
|
28
|
+
for (const hook of mod.beforeEachHooks) {
|
|
29
|
+
await hook.call(userContext, context.assert, hookMeta);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
await targetTestContent.call(userContext, context.assert, { testName, options: targetRuntimeOptions, context: userContext });
|
|
33
|
+
await context.assert.waitForAsyncOps();
|
|
34
|
+
for (const mod of context.module.moduleChain.toReversed()) {
|
|
35
|
+
for (const hook of mod.afterEachHooks.toReversed()) {
|
|
36
|
+
await hook.call(userContext, context.assert, hookMeta);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
resolve();
|
|
40
|
+
} catch (err) {
|
|
41
|
+
reject(err);
|
|
42
|
+
} finally {
|
|
43
|
+
context.clearTimeoutHandle();
|
|
34
44
|
}
|
|
35
|
-
}
|
|
36
|
-
return
|
|
45
|
+
})();
|
|
46
|
+
return promise;
|
|
37
47
|
});
|
|
38
48
|
}
|
|
39
49
|
test.skip = function skipTest(testName, _testContent) {
|
package/dist/shared/assert.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../../vendor/qunit.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AssertionErrorConstructor, InspectFn, ModuleState, PushResultInfo, QUnitObject, TestState } from '../types.d.ts';
|
|
3
3
|
/**
|
|
4
4
|
* The assertion object passed to every test callback and lifecycle hook.
|
|
5
5
|
*
|
|
@@ -31,7 +31,7 @@ export default class Assert {
|
|
|
31
31
|
/** @internal */
|
|
32
32
|
constructor(module: ModuleState | null, test?: TestState);
|
|
33
33
|
/** @internal */
|
|
34
|
-
_incrementAssertionCount
|
|
34
|
+
private _incrementAssertionCount;
|
|
35
35
|
/**
|
|
36
36
|
* Sets the number of milliseconds after which the current test will fail if not yet complete.
|
|
37
37
|
*
|
package/dist/shared/assert.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "../../vendor/qunit.js";
|
|
2
|
-
import { objectValues, objectValuesSubset,
|
|
2
|
+
import { objectValues, objectValuesSubset, validateException, validateExpectedExceptionArgs } from "./index.js";
|
|
3
|
+
const PENDING = /* @__PURE__ */ Symbol("pending");
|
|
3
4
|
class Assert {
|
|
4
5
|
/** @internal Set by each runtime shim before tests run. */
|
|
5
6
|
static QUnit;
|
|
@@ -11,7 +12,7 @@ class Assert {
|
|
|
11
12
|
test;
|
|
12
13
|
/** @internal */
|
|
13
14
|
constructor(module, test) {
|
|
14
|
-
this.test = test || module.
|
|
15
|
+
this.test = test || module.testContext;
|
|
15
16
|
}
|
|
16
17
|
/** @internal */
|
|
17
18
|
_incrementAssertionCount() {
|
|
@@ -35,6 +36,7 @@ class Assert {
|
|
|
35
36
|
throw new Error("assert.timeout() expects a positive integer.");
|
|
36
37
|
}
|
|
37
38
|
this.test.timeout = number;
|
|
39
|
+
this.test.setTimeoutDuration(number);
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Records a named step. Use with {@linkcode Assert.prototype.verifySteps} to assert that
|
|
@@ -52,19 +54,10 @@ class Assert {
|
|
|
52
54
|
* ```
|
|
53
55
|
*/
|
|
54
56
|
step(message) {
|
|
55
|
-
let assertionMessage = message;
|
|
56
|
-
let result = !!message;
|
|
57
57
|
this.test.steps.push(message);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
assertionMessage = "You must provide a string value to assert.step";
|
|
62
|
-
result = false;
|
|
63
|
-
}
|
|
64
|
-
this.pushResult({
|
|
65
|
-
result,
|
|
66
|
-
message: assertionMessage
|
|
67
|
-
});
|
|
58
|
+
const result = typeof message === "string" && message.length > 0;
|
|
59
|
+
const assertionMessage = result ? message : message === void 0 || message === "" ? "You must provide a message to assert.step" : "You must provide a string value to assert.step";
|
|
60
|
+
this.pushResult({ result, message: assertionMessage });
|
|
68
61
|
}
|
|
69
62
|
/**
|
|
70
63
|
* Asserts that the steps recorded via {@linkcode Assert.prototype.step} match the given array,
|
|
@@ -124,14 +117,9 @@ class Assert {
|
|
|
124
117
|
* ```
|
|
125
118
|
*/
|
|
126
119
|
async() {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
this.test.asyncOps.push(done);
|
|
132
|
-
return () => {
|
|
133
|
-
resolveFn();
|
|
134
|
-
};
|
|
120
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
121
|
+
this.test.asyncOps.push(promise);
|
|
122
|
+
return resolve;
|
|
135
123
|
}
|
|
136
124
|
/** @internal Used by the test runner to wait for all async operations to complete. */
|
|
137
125
|
waitForAsyncOps() {
|
|
@@ -529,7 +517,7 @@ class Assert {
|
|
|
529
517
|
* ```
|
|
530
518
|
*/
|
|
531
519
|
throws(blockFn, expectedInput, assertionMessage) {
|
|
532
|
-
this
|
|
520
|
+
this._incrementAssertionCount();
|
|
533
521
|
const [expected, message] = validateExpectedExceptionArgs(expectedInput, assertionMessage, "throws");
|
|
534
522
|
if (typeof blockFn !== "function") {
|
|
535
523
|
throw new Assert.AssertionError({
|
|
@@ -539,8 +527,9 @@ class Assert {
|
|
|
539
527
|
stackStartFn: this.throws
|
|
540
528
|
});
|
|
541
529
|
}
|
|
530
|
+
let returnValue;
|
|
542
531
|
try {
|
|
543
|
-
blockFn();
|
|
532
|
+
returnValue = blockFn();
|
|
544
533
|
} catch (error) {
|
|
545
534
|
const [result, validatedExpected, validatedMessage] = validateException(error, expected, message);
|
|
546
535
|
if (result === false) {
|
|
@@ -553,6 +542,14 @@ class Assert {
|
|
|
553
542
|
}
|
|
554
543
|
return;
|
|
555
544
|
}
|
|
545
|
+
if (returnValue !== null && typeof returnValue === "object" && typeof returnValue.then === "function") {
|
|
546
|
+
throw new Assert.AssertionError({
|
|
547
|
+
actual: returnValue,
|
|
548
|
+
expected,
|
|
549
|
+
message: "Function passed to `assert.throws` returned a Promise \u2014 did you mean to use `assert.rejects`?",
|
|
550
|
+
stackStartFn: this.throws
|
|
551
|
+
});
|
|
552
|
+
}
|
|
556
553
|
throw new Assert.AssertionError({
|
|
557
554
|
actual: blockFn,
|
|
558
555
|
expected,
|
|
@@ -587,15 +584,13 @@ class Assert {
|
|
|
587
584
|
stackStartFn: this.rejects
|
|
588
585
|
});
|
|
589
586
|
}
|
|
590
|
-
let
|
|
591
|
-
let rejectionError;
|
|
587
|
+
let caught = PENDING;
|
|
592
588
|
try {
|
|
593
589
|
await promise;
|
|
594
590
|
} catch (error) {
|
|
595
|
-
|
|
596
|
-
rejectionError = error;
|
|
591
|
+
caught = error;
|
|
597
592
|
}
|
|
598
|
-
if (
|
|
593
|
+
if (caught === PENDING) {
|
|
599
594
|
throw new Assert.AssertionError({
|
|
600
595
|
actual: promise,
|
|
601
596
|
expected,
|
|
@@ -603,7 +598,7 @@ class Assert {
|
|
|
603
598
|
stackStartFn: this.rejects
|
|
604
599
|
});
|
|
605
600
|
}
|
|
606
|
-
const [result, validatedExpected, validatedMessage] = validateException(
|
|
601
|
+
const [result, validatedExpected, validatedMessage] = validateException(caught, expected, message);
|
|
607
602
|
if (result === false) {
|
|
608
603
|
throw new Assert.AssertionError({
|
|
609
604
|
actual: result,
|
|
@@ -614,7 +609,6 @@ class Assert {
|
|
|
614
609
|
}
|
|
615
610
|
}
|
|
616
611
|
}
|
|
617
|
-
;
|
|
618
612
|
function defaultMessage(actual, description, expected) {
|
|
619
613
|
return `
|
|
620
614
|
|
|
@@ -624,8 +618,9 @@ ${description}
|
|
|
624
618
|
|
|
625
619
|
${inspect(expected)}`;
|
|
626
620
|
}
|
|
621
|
+
const INSPECT_OPTIONS = { depth: 10, colors: true, compact: false };
|
|
627
622
|
function inspect(value) {
|
|
628
|
-
return Assert.inspect(value,
|
|
623
|
+
return Assert.inspect(value, INSPECT_OPTIONS);
|
|
629
624
|
}
|
|
630
625
|
export {
|
|
631
626
|
Assert as default
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
export declare function objectType(obj: unknown): string;
|
|
2
2
|
export declare function objectValues(obj: unknown, allowArray?: boolean): unknown;
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
4
|
* Recursively clone an object into a plain object, taking only the
|
|
6
|
-
* subset of own enumerable properties that exist a given model.
|
|
7
|
-
*
|
|
8
|
-
* @param {any} obj
|
|
9
|
-
* @param {any} model
|
|
10
|
-
* @return {Object}
|
|
5
|
+
* subset of own enumerable properties that exist in a given model.
|
|
11
6
|
*/
|
|
12
7
|
export declare function objectValuesSubset(obj: unknown, model: unknown): unknown;
|
|
13
8
|
export declare function validateExpectedExceptionArgs(expected: unknown, message: string | undefined, assertionMethod: string): [unknown, string | undefined];
|
|
14
9
|
export declare function validateException(actual: unknown, expected: unknown, message: string | undefined): [boolean, unknown, string | undefined];
|
|
15
|
-
declare const _default: {
|
|
16
|
-
objectValues: typeof objectValues;
|
|
17
|
-
objectValuesSubset: typeof objectValuesSubset;
|
|
18
|
-
validateExpectedExceptionArgs: typeof validateExpectedExceptionArgs;
|
|
19
|
-
validateException: typeof validateException;
|
|
20
|
-
};
|
|
21
|
-
export default _default;
|
package/dist/shared/index.js
CHANGED
|
@@ -27,11 +27,8 @@ function objectType(obj) {
|
|
|
27
27
|
return typeof obj;
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
function is(type, obj) {
|
|
31
|
-
return objectType(obj) === type;
|
|
32
|
-
}
|
|
33
30
|
function objectValues(obj, allowArray = true) {
|
|
34
|
-
const vals = allowArray &&
|
|
31
|
+
const vals = allowArray && objectType(obj) === "array" ? [] : {};
|
|
35
32
|
for (const key in obj) {
|
|
36
33
|
if (hasOwn.call(obj, key)) {
|
|
37
34
|
const val = obj[key];
|
|
@@ -63,13 +60,15 @@ function validateExpectedExceptionArgs(expected, message, assertionMethod) {
|
|
|
63
60
|
expected = void 0;
|
|
64
61
|
return [expected, message];
|
|
65
62
|
} else {
|
|
66
|
-
throw new Error(
|
|
63
|
+
throw new Error(
|
|
64
|
+
`assert.${assertionMethod} does not accept a string value for the expected argument.
|
|
65
|
+
Use a non-string object value (e.g. RegExp or validator function) instead if necessary.`
|
|
66
|
+
);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
const valid = !expected ||
|
|
70
|
-
expectedType === "regexp" || expectedType === "function" || expectedType === "object";
|
|
69
|
+
const valid = !expected || expectedType === "regexp" || expectedType === "function" || expectedType === "object";
|
|
71
70
|
if (!valid) {
|
|
72
|
-
throw new Error(
|
|
71
|
+
throw new Error(`Invalid expected value type (${expectedType}) provided to assert.${assertionMethod}.`);
|
|
73
72
|
}
|
|
74
73
|
return [expected, message];
|
|
75
74
|
}
|
|
@@ -99,14 +98,13 @@ function validateException(actual, expected, message) {
|
|
|
99
98
|
function errorString(error) {
|
|
100
99
|
const resultErrorString = String(error);
|
|
101
100
|
if (resultErrorString.slice(0, 7) === "[object") {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return
|
|
101
|
+
const name = error.name || "Error";
|
|
102
|
+
const msg = error.message;
|
|
103
|
+
return msg ? `${name}: ${msg}` : name;
|
|
105
104
|
}
|
|
105
|
+
return resultErrorString;
|
|
106
106
|
}
|
|
107
|
-
var shared_default = { objectValues, objectValuesSubset, validateExpectedExceptionArgs, validateException };
|
|
108
107
|
export {
|
|
109
|
-
shared_default as default,
|
|
110
108
|
objectType,
|
|
111
109
|
objectValues,
|
|
112
110
|
objectValuesSubset,
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type Assert from './assert.d.ts';
|
|
2
1
|
import type { HookFn } from '../types.d.ts';
|
|
2
|
+
import type Assert from './assert.d.ts';
|
|
3
3
|
import TestContext from './test-context.d.ts';
|
|
4
4
|
export default class ModuleContext {
|
|
5
5
|
static Assert: typeof Assert;
|
|
6
6
|
static currentModuleChain: ModuleContext[];
|
|
7
|
-
static get lastModule(): ModuleContext;
|
|
7
|
+
static get lastModule(): ModuleContext | undefined;
|
|
8
8
|
name: string;
|
|
9
9
|
assert: Assert;
|
|
10
10
|
userContext: Record<string, unknown>;
|
|
11
|
-
|
|
11
|
+
testContext: TestContext;
|
|
12
12
|
moduleChain: ModuleContext[];
|
|
13
13
|
beforeEachHooks: HookFn<Assert>[];
|
|
14
14
|
afterEachHooks: HookFn<Assert>[];
|
|
@@ -3,21 +3,21 @@ class ModuleContext {
|
|
|
3
3
|
static Assert;
|
|
4
4
|
static currentModuleChain = [];
|
|
5
5
|
static get lastModule() {
|
|
6
|
-
return this.currentModuleChain
|
|
6
|
+
return this.currentModuleChain.at(-1);
|
|
7
7
|
}
|
|
8
8
|
name;
|
|
9
9
|
assert;
|
|
10
10
|
userContext;
|
|
11
11
|
// Internal fallback assert for modules with no direct tests
|
|
12
|
-
|
|
12
|
+
testContext = new TestContext();
|
|
13
13
|
moduleChain = [];
|
|
14
14
|
beforeEachHooks = [];
|
|
15
15
|
afterEachHooks = [];
|
|
16
16
|
tests = [];
|
|
17
17
|
constructor(name) {
|
|
18
|
-
const parentModule = ModuleContext.currentModuleChain
|
|
18
|
+
const parentModule = ModuleContext.currentModuleChain.at(-1);
|
|
19
19
|
ModuleContext.currentModuleChain.push(this);
|
|
20
|
-
this.moduleChain = ModuleContext.currentModuleChain
|
|
20
|
+
this.moduleChain = [...ModuleContext.currentModuleChain];
|
|
21
21
|
this.name = parentModule ? `${parentModule.name} > ${name}` : name;
|
|
22
22
|
this.assert = new ModuleContext.Assert(this);
|
|
23
23
|
this.userContext = parentModule ? Object.create(parentModule.userContext) : /* @__PURE__ */ Object.create(null);
|
|
@@ -3,23 +3,18 @@ import type ModuleContext from './module-context.d.ts';
|
|
|
3
3
|
export default class TestContext {
|
|
4
4
|
#private;
|
|
5
5
|
static Assert: typeof Assert;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
get timeout(): number | undefined;
|
|
15
|
-
set timeout(value: number | undefined);
|
|
16
|
-
get steps(): string[];
|
|
17
|
-
set steps(value: string[]);
|
|
18
|
-
get expectedAssertionCount(): number | undefined;
|
|
19
|
-
set expectedAssertionCount(value: number | undefined);
|
|
20
|
-
get totalExecutedAssertions(): number;
|
|
21
|
-
set totalExecutedAssertions(value: number);
|
|
6
|
+
name: string | undefined;
|
|
7
|
+
module: ModuleContext | undefined;
|
|
8
|
+
asyncOps: Promise<void>[];
|
|
9
|
+
assert: Assert | undefined;
|
|
10
|
+
timeout: number | undefined;
|
|
11
|
+
steps: string[];
|
|
12
|
+
expectedAssertionCount: number | undefined;
|
|
13
|
+
totalExecutedAssertions: number;
|
|
22
14
|
userContext: Record<string, unknown>;
|
|
15
|
+
rejectTimeout: ((err: Error) => void) | undefined;
|
|
23
16
|
constructor(name?: string, moduleContext?: ModuleContext);
|
|
17
|
+
setTimeoutDuration(ms: number): void;
|
|
18
|
+
clearTimeoutHandle(): void;
|
|
24
19
|
finish(): void;
|
|
25
20
|
}
|