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/index.d.ts
CHANGED
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
*
|
|
25
25
|
* @module
|
|
26
26
|
*/
|
|
27
|
-
import type { AssertionErrorOptions } from "../types.d.ts";
|
|
28
27
|
import '../../vendor/qunit.js';
|
|
28
|
+
import { AssertionError as DenoAssertionError } from 'jsr:@std/assert';
|
|
29
29
|
import Assert from '../shared/assert.d.ts';
|
|
30
|
+
import type { AssertionErrorOptions } from '../types.d.ts';
|
|
30
31
|
import Module from './module.d.ts';
|
|
31
32
|
import Test from './test.d.ts';
|
|
32
33
|
/**
|
|
@@ -92,6 +93,24 @@ export { Assert };
|
|
|
92
93
|
* ```
|
|
93
94
|
*/
|
|
94
95
|
export { default as module } from './module.d.ts';
|
|
96
|
+
/**
|
|
97
|
+
* Registers a skipped test. Equivalent to `test.skip`. The test body is never
|
|
98
|
+
* executed and the test is reported as ignored by Deno's runner.
|
|
99
|
+
*
|
|
100
|
+
* @param {string} testName - Name of the test to skip.
|
|
101
|
+
* @param {function} [_testContent] - Optional body (ignored — the test will not run).
|
|
102
|
+
* @example
|
|
103
|
+
* ```js
|
|
104
|
+
* import { module, skip } from "qunitx";
|
|
105
|
+
*
|
|
106
|
+
* module("Math", () => {
|
|
107
|
+
* skip("addition is not yet implemented", (assert) => {
|
|
108
|
+
* assert.equal(1 + 1, 2);
|
|
109
|
+
* });
|
|
110
|
+
* });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
export declare const skip: (testName: string, _testContent?: unknown) => void;
|
|
95
114
|
/**
|
|
96
115
|
* Defines an individual test. Wraps Deno's `it()` and handles the full QUnit
|
|
97
116
|
* lifecycle: `beforeEach`/`afterEach` hooks, async assertion waiting, and step
|
|
@@ -123,24 +142,6 @@ export { default as module } from './module.d.ts';
|
|
|
123
142
|
* ```
|
|
124
143
|
*/
|
|
125
144
|
export { default as test } from './test.d.ts';
|
|
126
|
-
/**
|
|
127
|
-
* Registers a skipped test. Equivalent to `test.skip`. The test body is never
|
|
128
|
-
* executed and the test is reported as ignored by Deno's runner.
|
|
129
|
-
*
|
|
130
|
-
* @param {string} testName - Name of the test to skip.
|
|
131
|
-
* @param {function} [_testContent] - Optional body (ignored — the test will not run).
|
|
132
|
-
* @example
|
|
133
|
-
* ```js
|
|
134
|
-
* import { module, skip } from "qunitx";
|
|
135
|
-
*
|
|
136
|
-
* module("Math", () => {
|
|
137
|
-
* skip("addition is not yet implemented", (assert) => {
|
|
138
|
-
* assert.equal(1 + 1, 2);
|
|
139
|
-
* });
|
|
140
|
-
* });
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
export declare const skip: (testName: string, _testContent?: unknown) => void;
|
|
144
145
|
export declare const todo: (testName: string, _testContent?: unknown) => void;
|
|
145
146
|
/**
|
|
146
147
|
* The default export provides the full QUnitX API as a single object.
|
package/dist/deno/index.js
CHANGED
|
@@ -150,7 +150,7 @@ var require_qunit = __commonJS({
|
|
|
150
150
|
var g = getGlobalThis();
|
|
151
151
|
var console$1 = g.console;
|
|
152
152
|
var setTimeout$1 = g.setTimeout;
|
|
153
|
-
var
|
|
153
|
+
var clearTimeout2 = g.clearTimeout;
|
|
154
154
|
var process$1 = g.process;
|
|
155
155
|
var window$1 = g.window;
|
|
156
156
|
var document = window$1 && window$1.document;
|
|
@@ -244,7 +244,7 @@ var require_qunit = __commonJS({
|
|
|
244
244
|
};
|
|
245
245
|
function objectValues2(obj) {
|
|
246
246
|
var allowArray = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
|
|
247
|
-
var vals = allowArray &&
|
|
247
|
+
var vals = allowArray && is("array", obj) ? [] : {};
|
|
248
248
|
for (var key in obj) {
|
|
249
249
|
if (hasOwn$1.call(obj, key)) {
|
|
250
250
|
var val = obj[key];
|
|
@@ -306,7 +306,7 @@ var require_qunit = __commonJS({
|
|
|
306
306
|
return _typeof(obj);
|
|
307
307
|
}
|
|
308
308
|
}
|
|
309
|
-
function
|
|
309
|
+
function is(type, obj) {
|
|
310
310
|
return objectType2(obj) === type;
|
|
311
311
|
}
|
|
312
312
|
function generateHash(module3, testName) {
|
|
@@ -791,11 +791,11 @@ var require_qunit = __commonJS({
|
|
|
791
791
|
type = "null";
|
|
792
792
|
} else if (typeof obj === "undefined") {
|
|
793
793
|
type = "undefined";
|
|
794
|
-
} else if (
|
|
794
|
+
} else if (is("regexp", obj)) {
|
|
795
795
|
type = "regexp";
|
|
796
|
-
} else if (
|
|
796
|
+
} else if (is("date", obj)) {
|
|
797
797
|
type = "date";
|
|
798
|
-
} else if (
|
|
798
|
+
} else if (is("function", obj)) {
|
|
799
799
|
type = "function";
|
|
800
800
|
} else if (obj.setInterval !== void 0 && obj.document !== void 0 && obj.nodeType === void 0) {
|
|
801
801
|
type = "window";
|
|
@@ -1317,7 +1317,7 @@ var require_qunit = __commonJS({
|
|
|
1317
1317
|
}
|
|
1318
1318
|
this.test.timeout = duration;
|
|
1319
1319
|
if (config.timeout) {
|
|
1320
|
-
|
|
1320
|
+
clearTimeout2(config.timeout);
|
|
1321
1321
|
config.timeout = null;
|
|
1322
1322
|
if (config.timeoutHandler && this.test.timeout > 0) {
|
|
1323
1323
|
this.test.internalResetTimeout(this.test.timeout);
|
|
@@ -2341,7 +2341,7 @@ var require_qunit = __commonJS({
|
|
|
2341
2341
|
finish: function finish() {
|
|
2342
2342
|
config.current = this;
|
|
2343
2343
|
if (setTimeout$1) {
|
|
2344
|
-
|
|
2344
|
+
clearTimeout2(this.timeout);
|
|
2345
2345
|
config.timeoutHandler = null;
|
|
2346
2346
|
}
|
|
2347
2347
|
this.callback = void 0;
|
|
@@ -2554,7 +2554,7 @@ var require_qunit = __commonJS({
|
|
|
2554
2554
|
* @param {number} timeoutDuration
|
|
2555
2555
|
*/
|
|
2556
2556
|
internalResetTimeout: function internalResetTimeout(timeoutDuration) {
|
|
2557
|
-
|
|
2557
|
+
clearTimeout2(config.timeout);
|
|
2558
2558
|
config.timeout = setTimeout$1(config.timeoutHandler(timeoutDuration), timeoutDuration);
|
|
2559
2559
|
},
|
|
2560
2560
|
/**
|
|
@@ -2662,10 +2662,10 @@ var require_qunit = __commonJS({
|
|
|
2662
2662
|
internalRecover(test4);
|
|
2663
2663
|
};
|
|
2664
2664
|
};
|
|
2665
|
-
|
|
2665
|
+
clearTimeout2(config.timeout);
|
|
2666
2666
|
config.timeout = setTimeout$1(config.timeoutHandler(timeoutDuration), timeoutDuration);
|
|
2667
2667
|
} else {
|
|
2668
|
-
|
|
2668
|
+
clearTimeout2(config.timeout);
|
|
2669
2669
|
config.timeout = setTimeout$1(function() {
|
|
2670
2670
|
config.timeout = null;
|
|
2671
2671
|
if (!config._deprecated_timeout_shown) {
|
|
@@ -2960,12 +2960,12 @@ var require_qunit = __commonJS({
|
|
|
2960
2960
|
return;
|
|
2961
2961
|
}
|
|
2962
2962
|
if (setTimeout$1) {
|
|
2963
|
-
|
|
2963
|
+
clearTimeout2(config.timeout);
|
|
2964
2964
|
config.timeout = setTimeout$1(function() {
|
|
2965
2965
|
if (test4.pauses.size > 0) {
|
|
2966
2966
|
return;
|
|
2967
2967
|
}
|
|
2968
|
-
|
|
2968
|
+
clearTimeout2(config.timeout);
|
|
2969
2969
|
config.timeout = null;
|
|
2970
2970
|
config.blocking = false;
|
|
2971
2971
|
config.pq.advance();
|
|
@@ -4297,7 +4297,7 @@ var require_qunit = __commonJS({
|
|
|
4297
4297
|
equiv,
|
|
4298
4298
|
reporters,
|
|
4299
4299
|
hooks,
|
|
4300
|
-
is
|
|
4300
|
+
is,
|
|
4301
4301
|
objectType: objectType2,
|
|
4302
4302
|
on,
|
|
4303
4303
|
onError: onWindowError,
|
|
@@ -5973,6 +5973,9 @@ var require_qunit = __commonJS({
|
|
|
5973
5973
|
}
|
|
5974
5974
|
});
|
|
5975
5975
|
|
|
5976
|
+
// shims/deno/index.ts
|
|
5977
|
+
var import_qunit2 = __toESM(require_qunit(), 1);
|
|
5978
|
+
|
|
5976
5979
|
// jsr:https://jsr.io/@std/assert/1.0.19/assertion_error.ts
|
|
5977
5980
|
var AssertionError = class extends Error {
|
|
5978
5981
|
/** Constructs a new instance.
|
|
@@ -6017,9 +6020,6 @@ var ANSI_PATTERN = new RegExp(
|
|
|
6017
6020
|
"g"
|
|
6018
6021
|
);
|
|
6019
6022
|
|
|
6020
|
-
// shims/deno/index.ts
|
|
6021
|
-
var import_qunit2 = __toESM(require_qunit(), 1);
|
|
6022
|
-
|
|
6023
6023
|
// shims/shared/assert.ts
|
|
6024
6024
|
var import_qunit = __toESM(require_qunit(), 1);
|
|
6025
6025
|
|
|
@@ -6053,11 +6053,8 @@ function objectType(obj) {
|
|
|
6053
6053
|
return typeof obj;
|
|
6054
6054
|
}
|
|
6055
6055
|
}
|
|
6056
|
-
function is(type, obj) {
|
|
6057
|
-
return objectType(obj) === type;
|
|
6058
|
-
}
|
|
6059
6056
|
function objectValues(obj, allowArray = true) {
|
|
6060
|
-
const vals = allowArray &&
|
|
6057
|
+
const vals = allowArray && objectType(obj) === "array" ? [] : {};
|
|
6061
6058
|
for (const key in obj) {
|
|
6062
6059
|
if (hasOwn.call(obj, key)) {
|
|
6063
6060
|
const val = obj[key];
|
|
@@ -6089,13 +6086,15 @@ function validateExpectedExceptionArgs(expected, message, assertionMethod) {
|
|
|
6089
6086
|
expected = void 0;
|
|
6090
6087
|
return [expected, message];
|
|
6091
6088
|
} else {
|
|
6092
|
-
throw new Error(
|
|
6089
|
+
throw new Error(
|
|
6090
|
+
`assert.${assertionMethod} does not accept a string value for the expected argument.
|
|
6091
|
+
Use a non-string object value (e.g. RegExp or validator function) instead if necessary.`
|
|
6092
|
+
);
|
|
6093
6093
|
}
|
|
6094
6094
|
}
|
|
6095
|
-
const valid = !expected ||
|
|
6096
|
-
expectedType === "regexp" || expectedType === "function" || expectedType === "object";
|
|
6095
|
+
const valid = !expected || expectedType === "regexp" || expectedType === "function" || expectedType === "object";
|
|
6097
6096
|
if (!valid) {
|
|
6098
|
-
throw new Error(
|
|
6097
|
+
throw new Error(`Invalid expected value type (${expectedType}) provided to assert.${assertionMethod}.`);
|
|
6099
6098
|
}
|
|
6100
6099
|
return [expected, message];
|
|
6101
6100
|
}
|
|
@@ -6125,13 +6124,15 @@ function validateException(actual, expected, message) {
|
|
|
6125
6124
|
function errorString(error) {
|
|
6126
6125
|
const resultErrorString = String(error);
|
|
6127
6126
|
if (resultErrorString.slice(0, 7) === "[object") {
|
|
6128
|
-
|
|
6129
|
-
|
|
6130
|
-
return
|
|
6127
|
+
const name = error.name || "Error";
|
|
6128
|
+
const msg = error.message;
|
|
6129
|
+
return msg ? `${name}: ${msg}` : name;
|
|
6131
6130
|
}
|
|
6131
|
+
return resultErrorString;
|
|
6132
6132
|
}
|
|
6133
6133
|
|
|
6134
6134
|
// shims/shared/assert.ts
|
|
6135
|
+
var PENDING = /* @__PURE__ */ Symbol("pending");
|
|
6135
6136
|
var Assert = class _Assert {
|
|
6136
6137
|
/** @internal Set by each runtime shim before tests run. */
|
|
6137
6138
|
static QUnit;
|
|
@@ -6143,7 +6144,7 @@ var Assert = class _Assert {
|
|
|
6143
6144
|
test;
|
|
6144
6145
|
/** @internal */
|
|
6145
6146
|
constructor(module2, test3) {
|
|
6146
|
-
this.test = test3 || module2.
|
|
6147
|
+
this.test = test3 || module2.testContext;
|
|
6147
6148
|
}
|
|
6148
6149
|
/** @internal */
|
|
6149
6150
|
_incrementAssertionCount() {
|
|
@@ -6167,6 +6168,7 @@ var Assert = class _Assert {
|
|
|
6167
6168
|
throw new Error("assert.timeout() expects a positive integer.");
|
|
6168
6169
|
}
|
|
6169
6170
|
this.test.timeout = number;
|
|
6171
|
+
this.test.setTimeoutDuration(number);
|
|
6170
6172
|
}
|
|
6171
6173
|
/**
|
|
6172
6174
|
* Records a named step. Use with {@linkcode Assert.prototype.verifySteps} to assert that
|
|
@@ -6184,19 +6186,10 @@ var Assert = class _Assert {
|
|
|
6184
6186
|
* ```
|
|
6185
6187
|
*/
|
|
6186
6188
|
step(message) {
|
|
6187
|
-
let assertionMessage = message;
|
|
6188
|
-
let result = !!message;
|
|
6189
6189
|
this.test.steps.push(message);
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
assertionMessage = "You must provide a string value to assert.step";
|
|
6194
|
-
result = false;
|
|
6195
|
-
}
|
|
6196
|
-
this.pushResult({
|
|
6197
|
-
result,
|
|
6198
|
-
message: assertionMessage
|
|
6199
|
-
});
|
|
6190
|
+
const result = typeof message === "string" && message.length > 0;
|
|
6191
|
+
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";
|
|
6192
|
+
this.pushResult({ result, message: assertionMessage });
|
|
6200
6193
|
}
|
|
6201
6194
|
/**
|
|
6202
6195
|
* Asserts that the steps recorded via {@linkcode Assert.prototype.step} match the given array,
|
|
@@ -6256,14 +6249,9 @@ var Assert = class _Assert {
|
|
|
6256
6249
|
* ```
|
|
6257
6250
|
*/
|
|
6258
6251
|
async() {
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
});
|
|
6263
|
-
this.test.asyncOps.push(done);
|
|
6264
|
-
return () => {
|
|
6265
|
-
resolveFn();
|
|
6266
|
-
};
|
|
6252
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
6253
|
+
this.test.asyncOps.push(promise);
|
|
6254
|
+
return resolve;
|
|
6267
6255
|
}
|
|
6268
6256
|
/** @internal Used by the test runner to wait for all async operations to complete. */
|
|
6269
6257
|
waitForAsyncOps() {
|
|
@@ -6661,7 +6649,7 @@ var Assert = class _Assert {
|
|
|
6661
6649
|
* ```
|
|
6662
6650
|
*/
|
|
6663
6651
|
throws(blockFn, expectedInput, assertionMessage) {
|
|
6664
|
-
this
|
|
6652
|
+
this._incrementAssertionCount();
|
|
6665
6653
|
const [expected, message] = validateExpectedExceptionArgs(expectedInput, assertionMessage, "throws");
|
|
6666
6654
|
if (typeof blockFn !== "function") {
|
|
6667
6655
|
throw new _Assert.AssertionError({
|
|
@@ -6671,8 +6659,9 @@ var Assert = class _Assert {
|
|
|
6671
6659
|
stackStartFn: this.throws
|
|
6672
6660
|
});
|
|
6673
6661
|
}
|
|
6662
|
+
let returnValue;
|
|
6674
6663
|
try {
|
|
6675
|
-
blockFn();
|
|
6664
|
+
returnValue = blockFn();
|
|
6676
6665
|
} catch (error) {
|
|
6677
6666
|
const [result, validatedExpected, validatedMessage] = validateException(error, expected, message);
|
|
6678
6667
|
if (result === false) {
|
|
@@ -6685,6 +6674,14 @@ var Assert = class _Assert {
|
|
|
6685
6674
|
}
|
|
6686
6675
|
return;
|
|
6687
6676
|
}
|
|
6677
|
+
if (returnValue !== null && typeof returnValue === "object" && typeof returnValue.then === "function") {
|
|
6678
|
+
throw new _Assert.AssertionError({
|
|
6679
|
+
actual: returnValue,
|
|
6680
|
+
expected,
|
|
6681
|
+
message: "Function passed to `assert.throws` returned a Promise \u2014 did you mean to use `assert.rejects`?",
|
|
6682
|
+
stackStartFn: this.throws
|
|
6683
|
+
});
|
|
6684
|
+
}
|
|
6688
6685
|
throw new _Assert.AssertionError({
|
|
6689
6686
|
actual: blockFn,
|
|
6690
6687
|
expected,
|
|
@@ -6719,15 +6716,13 @@ var Assert = class _Assert {
|
|
|
6719
6716
|
stackStartFn: this.rejects
|
|
6720
6717
|
});
|
|
6721
6718
|
}
|
|
6722
|
-
let
|
|
6723
|
-
let rejectionError;
|
|
6719
|
+
let caught = PENDING;
|
|
6724
6720
|
try {
|
|
6725
6721
|
await promise;
|
|
6726
6722
|
} catch (error) {
|
|
6727
|
-
|
|
6728
|
-
rejectionError = error;
|
|
6723
|
+
caught = error;
|
|
6729
6724
|
}
|
|
6730
|
-
if (
|
|
6725
|
+
if (caught === PENDING) {
|
|
6731
6726
|
throw new _Assert.AssertionError({
|
|
6732
6727
|
actual: promise,
|
|
6733
6728
|
expected,
|
|
@@ -6735,7 +6730,7 @@ var Assert = class _Assert {
|
|
|
6735
6730
|
stackStartFn: this.rejects
|
|
6736
6731
|
});
|
|
6737
6732
|
}
|
|
6738
|
-
const [result, validatedExpected, validatedMessage] = validateException(
|
|
6733
|
+
const [result, validatedExpected, validatedMessage] = validateException(caught, expected, message);
|
|
6739
6734
|
if (result === false) {
|
|
6740
6735
|
throw new _Assert.AssertionError({
|
|
6741
6736
|
actual: result,
|
|
@@ -6755,70 +6750,26 @@ ${description}
|
|
|
6755
6750
|
|
|
6756
6751
|
${inspect(expected)}`;
|
|
6757
6752
|
}
|
|
6753
|
+
var INSPECT_OPTIONS = { depth: 10, colors: true, compact: false };
|
|
6758
6754
|
function inspect(value) {
|
|
6759
|
-
return Assert.inspect(value,
|
|
6755
|
+
return Assert.inspect(value, INSPECT_OPTIONS);
|
|
6760
6756
|
}
|
|
6761
6757
|
|
|
6762
6758
|
// shims/shared/test-context.ts
|
|
6763
6759
|
var TestContext = class _TestContext {
|
|
6764
6760
|
static Assert;
|
|
6765
|
-
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
get module() {
|
|
6774
|
-
return this.#module;
|
|
6775
|
-
}
|
|
6776
|
-
set module(value) {
|
|
6777
|
-
this.#module = value;
|
|
6778
|
-
}
|
|
6779
|
-
#asyncOps = [];
|
|
6780
|
-
get asyncOps() {
|
|
6781
|
-
return this.#asyncOps;
|
|
6782
|
-
}
|
|
6783
|
-
set asyncOps(value) {
|
|
6784
|
-
this.#asyncOps = value;
|
|
6785
|
-
}
|
|
6786
|
-
#assert;
|
|
6787
|
-
get assert() {
|
|
6788
|
-
return this.#assert;
|
|
6789
|
-
}
|
|
6790
|
-
set assert(value) {
|
|
6791
|
-
this.#assert = value;
|
|
6792
|
-
}
|
|
6793
|
-
#timeout;
|
|
6794
|
-
get timeout() {
|
|
6795
|
-
return this.#timeout;
|
|
6796
|
-
}
|
|
6797
|
-
set timeout(value) {
|
|
6798
|
-
this.#timeout = value;
|
|
6799
|
-
}
|
|
6800
|
-
#steps = [];
|
|
6801
|
-
get steps() {
|
|
6802
|
-
return this.#steps;
|
|
6803
|
-
}
|
|
6804
|
-
set steps(value) {
|
|
6805
|
-
this.#steps = value;
|
|
6806
|
-
}
|
|
6807
|
-
#expectedAssertionCount;
|
|
6808
|
-
get expectedAssertionCount() {
|
|
6809
|
-
return this.#expectedAssertionCount;
|
|
6810
|
-
}
|
|
6811
|
-
set expectedAssertionCount(value) {
|
|
6812
|
-
this.#expectedAssertionCount = value;
|
|
6813
|
-
}
|
|
6814
|
-
#totalExecutedAssertions = 0;
|
|
6815
|
-
get totalExecutedAssertions() {
|
|
6816
|
-
return this.#totalExecutedAssertions;
|
|
6817
|
-
}
|
|
6818
|
-
set totalExecutedAssertions(value) {
|
|
6819
|
-
this.#totalExecutedAssertions = value;
|
|
6820
|
-
}
|
|
6761
|
+
name;
|
|
6762
|
+
module;
|
|
6763
|
+
asyncOps = [];
|
|
6764
|
+
assert;
|
|
6765
|
+
timeout;
|
|
6766
|
+
steps = [];
|
|
6767
|
+
expectedAssertionCount;
|
|
6768
|
+
totalExecutedAssertions = 0;
|
|
6821
6769
|
userContext = {};
|
|
6770
|
+
rejectTimeout;
|
|
6771
|
+
#timeoutHandle;
|
|
6772
|
+
#timedOut = false;
|
|
6822
6773
|
constructor(name, moduleContext) {
|
|
6823
6774
|
if (moduleContext) {
|
|
6824
6775
|
this.name = `${moduleContext.name} | ${name}`;
|
|
@@ -6827,28 +6778,46 @@ var TestContext = class _TestContext {
|
|
|
6827
6778
|
this.assert = new _TestContext.Assert(moduleContext, this);
|
|
6828
6779
|
}
|
|
6829
6780
|
}
|
|
6781
|
+
setTimeoutDuration(ms) {
|
|
6782
|
+
if (this.#timeoutHandle !== void 0) {
|
|
6783
|
+
clearTimeout(this.#timeoutHandle);
|
|
6784
|
+
this.#timeoutHandle = void 0;
|
|
6785
|
+
}
|
|
6786
|
+
if (!this.rejectTimeout) return;
|
|
6787
|
+
this.#timeoutHandle = setTimeout(() => {
|
|
6788
|
+
this.#timedOut = true;
|
|
6789
|
+
this.rejectTimeout(new Error(`Test timed out after ${ms}ms`));
|
|
6790
|
+
}, ms);
|
|
6791
|
+
}
|
|
6792
|
+
clearTimeoutHandle() {
|
|
6793
|
+
if (this.#timeoutHandle !== void 0) {
|
|
6794
|
+
clearTimeout(this.#timeoutHandle);
|
|
6795
|
+
this.#timeoutHandle = void 0;
|
|
6796
|
+
}
|
|
6797
|
+
}
|
|
6830
6798
|
finish() {
|
|
6831
|
-
if (this
|
|
6832
|
-
|
|
6833
|
-
result: false,
|
|
6834
|
-
actual: this.totalExecutedAssertions,
|
|
6835
|
-
expected: "> 0",
|
|
6836
|
-
message: `Expected at least one assertion to be run for test: ${this.name}`
|
|
6837
|
-
});
|
|
6838
|
-
} else if (this.steps.length > 0) {
|
|
6799
|
+
if (this.#timedOut) return;
|
|
6800
|
+
if (this.steps.length > 0) {
|
|
6839
6801
|
this.assert.pushResult({
|
|
6840
6802
|
result: false,
|
|
6841
6803
|
actual: this.steps,
|
|
6842
6804
|
expected: [],
|
|
6843
6805
|
message: `Expected assert.verifySteps() to be called before end of test after using assert.step(). Unverified steps: ${this.steps.join(", ")}`
|
|
6844
6806
|
});
|
|
6845
|
-
} else if (this.expectedAssertionCount && this.expectedAssertionCount !== this.totalExecutedAssertions) {
|
|
6807
|
+
} else if (this.expectedAssertionCount !== void 0 && this.expectedAssertionCount !== this.totalExecutedAssertions) {
|
|
6846
6808
|
this.assert.pushResult({
|
|
6847
6809
|
result: false,
|
|
6848
6810
|
actual: this.totalExecutedAssertions,
|
|
6849
6811
|
expected: this.expectedAssertionCount,
|
|
6850
6812
|
message: `Expected ${this.expectedAssertionCount} assertions, but ${this.totalExecutedAssertions} were run for test: ${this.name}`
|
|
6851
6813
|
});
|
|
6814
|
+
} else if (this.expectedAssertionCount === void 0 && this.totalExecutedAssertions === 0) {
|
|
6815
|
+
this.assert.pushResult({
|
|
6816
|
+
result: false,
|
|
6817
|
+
actual: this.totalExecutedAssertions,
|
|
6818
|
+
expected: "> 0",
|
|
6819
|
+
message: `Expected at least one assertion to be run for test: ${this.name}`
|
|
6820
|
+
});
|
|
6852
6821
|
}
|
|
6853
6822
|
}
|
|
6854
6823
|
};
|
|
@@ -6858,21 +6827,21 @@ var ModuleContext = class _ModuleContext {
|
|
|
6858
6827
|
static Assert;
|
|
6859
6828
|
static currentModuleChain = [];
|
|
6860
6829
|
static get lastModule() {
|
|
6861
|
-
return this.currentModuleChain
|
|
6830
|
+
return this.currentModuleChain.at(-1);
|
|
6862
6831
|
}
|
|
6863
6832
|
name;
|
|
6864
6833
|
assert;
|
|
6865
6834
|
userContext;
|
|
6866
6835
|
// Internal fallback assert for modules with no direct tests
|
|
6867
|
-
|
|
6836
|
+
testContext = new TestContext();
|
|
6868
6837
|
moduleChain = [];
|
|
6869
6838
|
beforeEachHooks = [];
|
|
6870
6839
|
afterEachHooks = [];
|
|
6871
6840
|
tests = [];
|
|
6872
6841
|
constructor(name) {
|
|
6873
|
-
const parentModule = _ModuleContext.currentModuleChain
|
|
6842
|
+
const parentModule = _ModuleContext.currentModuleChain.at(-1);
|
|
6874
6843
|
_ModuleContext.currentModuleChain.push(this);
|
|
6875
|
-
this.moduleChain = _ModuleContext.currentModuleChain
|
|
6844
|
+
this.moduleChain = [..._ModuleContext.currentModuleChain];
|
|
6876
6845
|
this.name = parentModule ? `${parentModule.name} > ${name}` : name;
|
|
6877
6846
|
this.assert = new _ModuleContext.Assert(this);
|
|
6878
6847
|
this.userContext = parentModule ? Object.create(parentModule.userContext) : /* @__PURE__ */ Object.create(null);
|
|
@@ -7677,12 +7646,12 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7677
7646
|
});
|
|
7678
7647
|
return;
|
|
7679
7648
|
}
|
|
7680
|
-
const targetModuleContent = moduleContent
|
|
7649
|
+
const targetModuleContent = moduleContent ?? runtimeOptions;
|
|
7681
7650
|
const moduleContext = new ModuleContext(moduleName);
|
|
7682
7651
|
describe(moduleName, { ...targetRuntimeOptions }, function() {
|
|
7683
7652
|
const beforeHooks = [];
|
|
7684
7653
|
const afterHooks = [];
|
|
7685
|
-
beforeAll(async
|
|
7654
|
+
beforeAll(async () => {
|
|
7686
7655
|
const firstTest = moduleContext.tests[0];
|
|
7687
7656
|
const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
|
|
7688
7657
|
for (const hook of beforeHooks) {
|
|
@@ -7690,17 +7659,16 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7690
7659
|
}
|
|
7691
7660
|
});
|
|
7692
7661
|
afterAll(async () => {
|
|
7693
|
-
|
|
7694
|
-
|
|
7695
|
-
|
|
7696
|
-
const lastTest = moduleContext.tests[moduleContext.tests.length - 1];
|
|
7662
|
+
const allAsyncOps = moduleContext.tests.flatMap((t) => t.asyncOps);
|
|
7663
|
+
if (allAsyncOps.length > 0) await Promise.all(allAsyncOps);
|
|
7664
|
+
const lastTest = moduleContext.tests.at(-1);
|
|
7697
7665
|
if (lastTest) {
|
|
7698
|
-
for (
|
|
7699
|
-
await
|
|
7666
|
+
for (const hook of afterHooks.toReversed()) {
|
|
7667
|
+
await hook.call(lastTest.userContext, lastTest.assert, { context: lastTest.userContext });
|
|
7700
7668
|
}
|
|
7701
7669
|
}
|
|
7702
|
-
for (
|
|
7703
|
-
|
|
7670
|
+
for (const testCtx of moduleContext.tests) {
|
|
7671
|
+
testCtx.finish();
|
|
7704
7672
|
}
|
|
7705
7673
|
});
|
|
7706
7674
|
targetModuleContent.call(moduleContext.userContext, {
|
|
@@ -7716,7 +7684,7 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7716
7684
|
after(afterFn) {
|
|
7717
7685
|
afterHooks.push(afterFn);
|
|
7718
7686
|
}
|
|
7719
|
-
}, { moduleName, options:
|
|
7687
|
+
}, { moduleName, options: targetRuntimeOptions, context: moduleContext.userContext });
|
|
7720
7688
|
ModuleContext.currentModuleChain.pop();
|
|
7721
7689
|
});
|
|
7722
7690
|
}
|
|
@@ -7724,6 +7692,10 @@ module.skip = function skipModule(moduleName, _moduleContent) {
|
|
|
7724
7692
|
describe(moduleName, { ignore: true }, function() {
|
|
7725
7693
|
});
|
|
7726
7694
|
};
|
|
7695
|
+
module.todo = function todoModule(moduleName, _moduleContent) {
|
|
7696
|
+
describe(moduleName, { ignore: true }, function() {
|
|
7697
|
+
});
|
|
7698
|
+
};
|
|
7727
7699
|
|
|
7728
7700
|
// shims/deno/test.ts
|
|
7729
7701
|
function test2(testName, runtimeOptions, testContent) {
|
|
@@ -7738,26 +7710,36 @@ function test2(testName, runtimeOptions, testContent) {
|
|
|
7738
7710
|
});
|
|
7739
7711
|
return;
|
|
7740
7712
|
}
|
|
7741
|
-
const targetTestContent = testContent
|
|
7713
|
+
const targetTestContent = testContent ?? runtimeOptions;
|
|
7742
7714
|
const context = new TestContext(testName, moduleContext);
|
|
7743
7715
|
const userContext = Object.create(moduleContext.userContext);
|
|
7744
7716
|
context.userContext = userContext;
|
|
7745
|
-
it(testName, { ...targetRuntimeOptions },
|
|
7717
|
+
it(testName, { ...targetRuntimeOptions }, function() {
|
|
7718
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
7719
|
+
context.rejectTimeout = reject;
|
|
7746
7720
|
const hookMeta = { context: userContext };
|
|
7747
|
-
|
|
7748
|
-
|
|
7749
|
-
|
|
7750
|
-
|
|
7751
|
-
|
|
7752
|
-
|
|
7753
|
-
|
|
7754
|
-
|
|
7755
|
-
|
|
7756
|
-
|
|
7757
|
-
|
|
7721
|
+
(async () => {
|
|
7722
|
+
try {
|
|
7723
|
+
for (const mod of context.module.moduleChain) {
|
|
7724
|
+
for (const hook of mod.beforeEachHooks) {
|
|
7725
|
+
await hook.call(userContext, context.assert, hookMeta);
|
|
7726
|
+
}
|
|
7727
|
+
}
|
|
7728
|
+
await targetTestContent.call(userContext, context.assert, { testName, options: targetRuntimeOptions, context: userContext });
|
|
7729
|
+
await context.assert.waitForAsyncOps();
|
|
7730
|
+
for (const mod of context.module.moduleChain.toReversed()) {
|
|
7731
|
+
for (const hook of mod.afterEachHooks.toReversed()) {
|
|
7732
|
+
await hook.call(userContext, context.assert, hookMeta);
|
|
7733
|
+
}
|
|
7734
|
+
}
|
|
7735
|
+
resolve();
|
|
7736
|
+
} catch (err) {
|
|
7737
|
+
reject(err);
|
|
7738
|
+
} finally {
|
|
7739
|
+
context.clearTimeoutHandle();
|
|
7758
7740
|
}
|
|
7759
|
-
}
|
|
7760
|
-
return
|
|
7741
|
+
})();
|
|
7742
|
+
return promise;
|
|
7761
7743
|
});
|
|
7762
7744
|
}
|
|
7763
7745
|
test2.skip = function skipTest(testName, _testContent) {
|
package/dist/deno/module.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type Assert from '../shared/assert.d.ts';
|
|
2
2
|
import type { HooksObject } from '../types.d.ts';
|
|
3
|
-
export type { Assert };
|
|
4
|
-
export type { HookFn, HooksObject, PushResultInfo } from '../types.d.ts';
|
|
5
3
|
/**
|
|
6
4
|
* Defines a test module (suite) for Deno's BDD test runner.
|
|
7
5
|
*
|
|
@@ -42,5 +40,8 @@ declare function module(moduleName: string, runtimeOptions: object, moduleConten
|
|
|
42
40
|
}) => void): void;
|
|
43
41
|
declare namespace module {
|
|
44
42
|
var skip: (moduleName: string, _moduleContent?: unknown) => void;
|
|
43
|
+
var todo: (moduleName: string, _moduleContent?: unknown) => void;
|
|
45
44
|
}
|
|
46
45
|
export default module;
|
|
46
|
+
export type { Assert };
|
|
47
|
+
export type { HookFn, HooksObject, PushResultInfo } from '../types.d.ts';
|