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
|
@@ -4,72 +4,20 @@ import type ModuleContext from './module-context.ts';
|
|
|
4
4
|
export default class TestContext {
|
|
5
5
|
static Assert: typeof Assert;
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
#module: ModuleContext | undefined;
|
|
16
|
-
get module() {
|
|
17
|
-
return this.#module;
|
|
18
|
-
}
|
|
19
|
-
set module(value) {
|
|
20
|
-
this.#module = value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#asyncOps: Promise<void>[] = [];
|
|
24
|
-
get asyncOps() {
|
|
25
|
-
return this.#asyncOps;
|
|
26
|
-
}
|
|
27
|
-
set asyncOps(value) {
|
|
28
|
-
this.#asyncOps = value;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
#assert: Assert | undefined;
|
|
32
|
-
get assert() {
|
|
33
|
-
return this.#assert;
|
|
34
|
-
}
|
|
35
|
-
set assert(value) {
|
|
36
|
-
this.#assert = value;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
#timeout: number | undefined;
|
|
40
|
-
get timeout() {
|
|
41
|
-
return this.#timeout;
|
|
42
|
-
}
|
|
43
|
-
set timeout(value) {
|
|
44
|
-
this.#timeout = value;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
#steps: string[] = [];
|
|
48
|
-
get steps() {
|
|
49
|
-
return this.#steps;
|
|
50
|
-
}
|
|
51
|
-
set steps(value) {
|
|
52
|
-
this.#steps = value;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
#expectedAssertionCount: number | undefined;
|
|
56
|
-
get expectedAssertionCount() {
|
|
57
|
-
return this.#expectedAssertionCount;
|
|
58
|
-
}
|
|
59
|
-
set expectedAssertionCount(value) {
|
|
60
|
-
this.#expectedAssertionCount = value;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
#totalExecutedAssertions = 0;
|
|
64
|
-
get totalExecutedAssertions() {
|
|
65
|
-
return this.#totalExecutedAssertions;
|
|
66
|
-
}
|
|
67
|
-
set totalExecutedAssertions(value) {
|
|
68
|
-
this.#totalExecutedAssertions = value;
|
|
69
|
-
}
|
|
70
|
-
|
|
7
|
+
name: string | undefined;
|
|
8
|
+
module: ModuleContext | undefined;
|
|
9
|
+
asyncOps: Promise<void>[] = [];
|
|
10
|
+
assert: Assert | undefined;
|
|
11
|
+
timeout: number | undefined;
|
|
12
|
+
steps: string[] = [];
|
|
13
|
+
expectedAssertionCount: number | undefined;
|
|
14
|
+
totalExecutedAssertions = 0;
|
|
71
15
|
userContext: Record<string, unknown> = {};
|
|
72
16
|
|
|
17
|
+
rejectTimeout: ((err: Error) => void) | undefined;
|
|
18
|
+
#timeoutHandle: ReturnType<typeof setTimeout> | undefined;
|
|
19
|
+
#timedOut = false;
|
|
20
|
+
|
|
73
21
|
constructor(name?: string, moduleContext?: ModuleContext) {
|
|
74
22
|
if (moduleContext) {
|
|
75
23
|
this.name = `${moduleContext.name} | ${name}`;
|
|
@@ -79,29 +27,48 @@ export default class TestContext {
|
|
|
79
27
|
}
|
|
80
28
|
}
|
|
81
29
|
|
|
30
|
+
setTimeoutDuration(ms: number) {
|
|
31
|
+
if (this.#timeoutHandle !== undefined) {
|
|
32
|
+
clearTimeout(this.#timeoutHandle);
|
|
33
|
+
this.#timeoutHandle = undefined;
|
|
34
|
+
}
|
|
35
|
+
if (!this.rejectTimeout) return;
|
|
36
|
+
this.#timeoutHandle = setTimeout(() => {
|
|
37
|
+
this.#timedOut = true;
|
|
38
|
+
this.rejectTimeout!(new Error(`Test timed out after ${ms}ms`));
|
|
39
|
+
}, ms);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
clearTimeoutHandle() {
|
|
43
|
+
if (this.#timeoutHandle !== undefined) {
|
|
44
|
+
clearTimeout(this.#timeoutHandle);
|
|
45
|
+
this.#timeoutHandle = undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
82
49
|
finish() {
|
|
83
|
-
if (this
|
|
84
|
-
|
|
85
|
-
result: false,
|
|
86
|
-
actual: this.totalExecutedAssertions,
|
|
87
|
-
expected: '> 0',
|
|
88
|
-
message: `Expected at least one assertion to be run for test: ${this.name}`,
|
|
89
|
-
});
|
|
90
|
-
} else if (this.steps.length > 0) {
|
|
50
|
+
if (this.#timedOut) return;
|
|
51
|
+
if (this.steps.length > 0) {
|
|
91
52
|
this.assert!.pushResult({
|
|
92
53
|
result: false,
|
|
93
54
|
actual: this.steps,
|
|
94
55
|
expected: [],
|
|
95
56
|
message: `Expected assert.verifySteps() to be called before end of test after using assert.step(). Unverified steps: ${this.steps.join(', ')}`,
|
|
96
57
|
});
|
|
97
|
-
} else if (this.expectedAssertionCount && this.expectedAssertionCount !== this.totalExecutedAssertions) {
|
|
58
|
+
} else if (this.expectedAssertionCount !== undefined && this.expectedAssertionCount !== this.totalExecutedAssertions) {
|
|
98
59
|
this.assert!.pushResult({
|
|
99
60
|
result: false,
|
|
100
61
|
actual: this.totalExecutedAssertions,
|
|
101
62
|
expected: this.expectedAssertionCount,
|
|
102
63
|
message: `Expected ${this.expectedAssertionCount} assertions, but ${this.totalExecutedAssertions} were run for test: ${this.name}`,
|
|
103
64
|
});
|
|
65
|
+
} else if (this.expectedAssertionCount === undefined && this.totalExecutedAssertions === 0) {
|
|
66
|
+
this.assert!.pushResult({
|
|
67
|
+
result: false,
|
|
68
|
+
actual: this.totalExecutedAssertions,
|
|
69
|
+
expected: '> 0',
|
|
70
|
+
message: `Expected at least one assertion to be run for test: ${this.name}`,
|
|
71
|
+
});
|
|
104
72
|
}
|
|
105
73
|
}
|
|
106
74
|
}
|
|
107
|
-
|
package/shims/types.ts
CHANGED
|
@@ -39,11 +39,12 @@ export interface TestState {
|
|
|
39
39
|
expectedAssertionCount?: number;
|
|
40
40
|
userContext?: Record<string, unknown>;
|
|
41
41
|
module?: { name: string };
|
|
42
|
+
setTimeoutDuration(ms: number): void;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
/** Minimal module shape that Assert needs to resolve a fallback test context. */
|
|
45
46
|
export interface ModuleState {
|
|
46
|
-
|
|
47
|
+
testContext: TestState;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
/** A lifecycle hook callback that receives an {@linkcode Assert} instance and a meta object with the shared context. */
|