qunitx 1.2.6 → 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 +20 -20
- package/dist/browser/index.js +52 -52
- package/dist/deno/index.d.ts +20 -19
- package/dist/deno/index.js +108 -163
- package/dist/deno/module.d.ts +2 -2
- package/dist/deno/module.js +11 -12
- package/dist/deno/test.d.ts +2 -2
- package/dist/deno/test.js +24 -25
- package/dist/node/index.d.ts +3 -2
- package/dist/node/index.js +1 -1
- package/dist/node/module.js +11 -12
- package/dist/node/test.js +23 -24
- package/dist/shared/assert.d.ts +2 -2
- package/dist/shared/assert.js +26 -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 +10 -18
- package/dist/shared/test-context.js +26 -74
- package/dist/types.d.ts +1 -1
- package/package.json +2 -2
- package/shims/deno/index.ts +21 -21
- package/shims/deno/module.ts +15 -15
- package/shims/deno/test.ts +30 -29
- package/shims/shared/assert.ts +37 -33
- package/shims/shared/index.ts +14 -27
- package/shims/shared/module-context.ts +5 -5
- package/shims/shared/test-context.ts +27 -84
- package/shims/types.ts +1 -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
|
@@ -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";
|
|
@@ -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() {
|
|
@@ -6185,19 +6186,10 @@ var Assert = class _Assert {
|
|
|
6185
6186
|
* ```
|
|
6186
6187
|
*/
|
|
6187
6188
|
step(message) {
|
|
6188
|
-
let assertionMessage = message;
|
|
6189
|
-
let result = !!message;
|
|
6190
6189
|
this.test.steps.push(message);
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
assertionMessage = "You must provide a string value to assert.step";
|
|
6195
|
-
result = false;
|
|
6196
|
-
}
|
|
6197
|
-
this.pushResult({
|
|
6198
|
-
result,
|
|
6199
|
-
message: assertionMessage
|
|
6200
|
-
});
|
|
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 });
|
|
6201
6193
|
}
|
|
6202
6194
|
/**
|
|
6203
6195
|
* Asserts that the steps recorded via {@linkcode Assert.prototype.step} match the given array,
|
|
@@ -6257,14 +6249,9 @@ var Assert = class _Assert {
|
|
|
6257
6249
|
* ```
|
|
6258
6250
|
*/
|
|
6259
6251
|
async() {
|
|
6260
|
-
|
|
6261
|
-
|
|
6262
|
-
|
|
6263
|
-
});
|
|
6264
|
-
this.test.asyncOps.push(done);
|
|
6265
|
-
return () => {
|
|
6266
|
-
resolveFn();
|
|
6267
|
-
};
|
|
6252
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
6253
|
+
this.test.asyncOps.push(promise);
|
|
6254
|
+
return resolve;
|
|
6268
6255
|
}
|
|
6269
6256
|
/** @internal Used by the test runner to wait for all async operations to complete. */
|
|
6270
6257
|
waitForAsyncOps() {
|
|
@@ -6662,7 +6649,7 @@ var Assert = class _Assert {
|
|
|
6662
6649
|
* ```
|
|
6663
6650
|
*/
|
|
6664
6651
|
throws(blockFn, expectedInput, assertionMessage) {
|
|
6665
|
-
this
|
|
6652
|
+
this._incrementAssertionCount();
|
|
6666
6653
|
const [expected, message] = validateExpectedExceptionArgs(expectedInput, assertionMessage, "throws");
|
|
6667
6654
|
if (typeof blockFn !== "function") {
|
|
6668
6655
|
throw new _Assert.AssertionError({
|
|
@@ -6672,8 +6659,9 @@ var Assert = class _Assert {
|
|
|
6672
6659
|
stackStartFn: this.throws
|
|
6673
6660
|
});
|
|
6674
6661
|
}
|
|
6662
|
+
let returnValue;
|
|
6675
6663
|
try {
|
|
6676
|
-
blockFn();
|
|
6664
|
+
returnValue = blockFn();
|
|
6677
6665
|
} catch (error) {
|
|
6678
6666
|
const [result, validatedExpected, validatedMessage] = validateException(error, expected, message);
|
|
6679
6667
|
if (result === false) {
|
|
@@ -6686,6 +6674,14 @@ var Assert = class _Assert {
|
|
|
6686
6674
|
}
|
|
6687
6675
|
return;
|
|
6688
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
|
+
}
|
|
6689
6685
|
throw new _Assert.AssertionError({
|
|
6690
6686
|
actual: blockFn,
|
|
6691
6687
|
expected,
|
|
@@ -6720,15 +6716,13 @@ var Assert = class _Assert {
|
|
|
6720
6716
|
stackStartFn: this.rejects
|
|
6721
6717
|
});
|
|
6722
6718
|
}
|
|
6723
|
-
let
|
|
6724
|
-
let rejectionError;
|
|
6719
|
+
let caught = PENDING;
|
|
6725
6720
|
try {
|
|
6726
6721
|
await promise;
|
|
6727
6722
|
} catch (error) {
|
|
6728
|
-
|
|
6729
|
-
rejectionError = error;
|
|
6723
|
+
caught = error;
|
|
6730
6724
|
}
|
|
6731
|
-
if (
|
|
6725
|
+
if (caught === PENDING) {
|
|
6732
6726
|
throw new _Assert.AssertionError({
|
|
6733
6727
|
actual: promise,
|
|
6734
6728
|
expected,
|
|
@@ -6736,7 +6730,7 @@ var Assert = class _Assert {
|
|
|
6736
6730
|
stackStartFn: this.rejects
|
|
6737
6731
|
});
|
|
6738
6732
|
}
|
|
6739
|
-
const [result, validatedExpected, validatedMessage] = validateException(
|
|
6733
|
+
const [result, validatedExpected, validatedMessage] = validateException(caught, expected, message);
|
|
6740
6734
|
if (result === false) {
|
|
6741
6735
|
throw new _Assert.AssertionError({
|
|
6742
6736
|
actual: result,
|
|
@@ -6756,51 +6750,34 @@ ${description}
|
|
|
6756
6750
|
|
|
6757
6751
|
${inspect(expected)}`;
|
|
6758
6752
|
}
|
|
6753
|
+
var INSPECT_OPTIONS = { depth: 10, colors: true, compact: false };
|
|
6759
6754
|
function inspect(value) {
|
|
6760
|
-
return Assert.inspect(value,
|
|
6755
|
+
return Assert.inspect(value, INSPECT_OPTIONS);
|
|
6761
6756
|
}
|
|
6762
6757
|
|
|
6763
6758
|
// shims/shared/test-context.ts
|
|
6764
6759
|
var TestContext = class _TestContext {
|
|
6765
6760
|
static Assert;
|
|
6766
|
-
|
|
6767
|
-
|
|
6768
|
-
|
|
6769
|
-
|
|
6770
|
-
|
|
6771
|
-
|
|
6772
|
-
|
|
6773
|
-
|
|
6774
|
-
|
|
6775
|
-
return this.#module;
|
|
6776
|
-
}
|
|
6777
|
-
set module(value) {
|
|
6778
|
-
this.#module = value;
|
|
6779
|
-
}
|
|
6780
|
-
#asyncOps = [];
|
|
6781
|
-
get asyncOps() {
|
|
6782
|
-
return this.#asyncOps;
|
|
6783
|
-
}
|
|
6784
|
-
set asyncOps(value) {
|
|
6785
|
-
this.#asyncOps = value;
|
|
6786
|
-
}
|
|
6787
|
-
#assert;
|
|
6788
|
-
get assert() {
|
|
6789
|
-
return this.#assert;
|
|
6790
|
-
}
|
|
6791
|
-
set assert(value) {
|
|
6792
|
-
this.#assert = value;
|
|
6793
|
-
}
|
|
6794
|
-
#timeout;
|
|
6795
|
-
get timeout() {
|
|
6796
|
-
return this.#timeout;
|
|
6797
|
-
}
|
|
6798
|
-
set timeout(value) {
|
|
6799
|
-
this.#timeout = value;
|
|
6800
|
-
}
|
|
6761
|
+
name;
|
|
6762
|
+
module;
|
|
6763
|
+
asyncOps = [];
|
|
6764
|
+
assert;
|
|
6765
|
+
timeout;
|
|
6766
|
+
steps = [];
|
|
6767
|
+
expectedAssertionCount;
|
|
6768
|
+
totalExecutedAssertions = 0;
|
|
6769
|
+
userContext = {};
|
|
6801
6770
|
rejectTimeout;
|
|
6802
6771
|
#timeoutHandle;
|
|
6803
6772
|
#timedOut = false;
|
|
6773
|
+
constructor(name, moduleContext) {
|
|
6774
|
+
if (moduleContext) {
|
|
6775
|
+
this.name = `${moduleContext.name} | ${name}`;
|
|
6776
|
+
this.module = moduleContext;
|
|
6777
|
+
this.module.tests.push(this);
|
|
6778
|
+
this.assert = new _TestContext.Assert(moduleContext, this);
|
|
6779
|
+
}
|
|
6780
|
+
}
|
|
6804
6781
|
setTimeoutDuration(ms) {
|
|
6805
6782
|
if (this.#timeoutHandle !== void 0) {
|
|
6806
6783
|
clearTimeout(this.#timeoutHandle);
|
|
@@ -6818,59 +6795,29 @@ var TestContext = class _TestContext {
|
|
|
6818
6795
|
this.#timeoutHandle = void 0;
|
|
6819
6796
|
}
|
|
6820
6797
|
}
|
|
6821
|
-
#steps = [];
|
|
6822
|
-
get steps() {
|
|
6823
|
-
return this.#steps;
|
|
6824
|
-
}
|
|
6825
|
-
set steps(value) {
|
|
6826
|
-
this.#steps = value;
|
|
6827
|
-
}
|
|
6828
|
-
#expectedAssertionCount;
|
|
6829
|
-
get expectedAssertionCount() {
|
|
6830
|
-
return this.#expectedAssertionCount;
|
|
6831
|
-
}
|
|
6832
|
-
set expectedAssertionCount(value) {
|
|
6833
|
-
this.#expectedAssertionCount = value;
|
|
6834
|
-
}
|
|
6835
|
-
#totalExecutedAssertions = 0;
|
|
6836
|
-
get totalExecutedAssertions() {
|
|
6837
|
-
return this.#totalExecutedAssertions;
|
|
6838
|
-
}
|
|
6839
|
-
set totalExecutedAssertions(value) {
|
|
6840
|
-
this.#totalExecutedAssertions = value;
|
|
6841
|
-
}
|
|
6842
|
-
userContext = {};
|
|
6843
|
-
constructor(name, moduleContext) {
|
|
6844
|
-
if (moduleContext) {
|
|
6845
|
-
this.name = `${moduleContext.name} | ${name}`;
|
|
6846
|
-
this.module = moduleContext;
|
|
6847
|
-
this.module.tests.push(this);
|
|
6848
|
-
this.assert = new _TestContext.Assert(moduleContext, this);
|
|
6849
|
-
}
|
|
6850
|
-
}
|
|
6851
6798
|
finish() {
|
|
6852
6799
|
if (this.#timedOut) return;
|
|
6853
|
-
if (this.
|
|
6854
|
-
this.assert.pushResult({
|
|
6855
|
-
result: false,
|
|
6856
|
-
actual: this.totalExecutedAssertions,
|
|
6857
|
-
expected: "> 0",
|
|
6858
|
-
message: `Expected at least one assertion to be run for test: ${this.name}`
|
|
6859
|
-
});
|
|
6860
|
-
} else if (this.steps.length > 0) {
|
|
6800
|
+
if (this.steps.length > 0) {
|
|
6861
6801
|
this.assert.pushResult({
|
|
6862
6802
|
result: false,
|
|
6863
6803
|
actual: this.steps,
|
|
6864
6804
|
expected: [],
|
|
6865
6805
|
message: `Expected assert.verifySteps() to be called before end of test after using assert.step(). Unverified steps: ${this.steps.join(", ")}`
|
|
6866
6806
|
});
|
|
6867
|
-
} else if (this.expectedAssertionCount && this.expectedAssertionCount !== this.totalExecutedAssertions) {
|
|
6807
|
+
} else if (this.expectedAssertionCount !== void 0 && this.expectedAssertionCount !== this.totalExecutedAssertions) {
|
|
6868
6808
|
this.assert.pushResult({
|
|
6869
6809
|
result: false,
|
|
6870
6810
|
actual: this.totalExecutedAssertions,
|
|
6871
6811
|
expected: this.expectedAssertionCount,
|
|
6872
6812
|
message: `Expected ${this.expectedAssertionCount} assertions, but ${this.totalExecutedAssertions} were run for test: ${this.name}`
|
|
6873
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
|
+
});
|
|
6874
6821
|
}
|
|
6875
6822
|
}
|
|
6876
6823
|
};
|
|
@@ -6880,21 +6827,21 @@ var ModuleContext = class _ModuleContext {
|
|
|
6880
6827
|
static Assert;
|
|
6881
6828
|
static currentModuleChain = [];
|
|
6882
6829
|
static get lastModule() {
|
|
6883
|
-
return this.currentModuleChain
|
|
6830
|
+
return this.currentModuleChain.at(-1);
|
|
6884
6831
|
}
|
|
6885
6832
|
name;
|
|
6886
6833
|
assert;
|
|
6887
6834
|
userContext;
|
|
6888
6835
|
// Internal fallback assert for modules with no direct tests
|
|
6889
|
-
|
|
6836
|
+
testContext = new TestContext();
|
|
6890
6837
|
moduleChain = [];
|
|
6891
6838
|
beforeEachHooks = [];
|
|
6892
6839
|
afterEachHooks = [];
|
|
6893
6840
|
tests = [];
|
|
6894
6841
|
constructor(name) {
|
|
6895
|
-
const parentModule = _ModuleContext.currentModuleChain
|
|
6842
|
+
const parentModule = _ModuleContext.currentModuleChain.at(-1);
|
|
6896
6843
|
_ModuleContext.currentModuleChain.push(this);
|
|
6897
|
-
this.moduleChain = _ModuleContext.currentModuleChain
|
|
6844
|
+
this.moduleChain = [..._ModuleContext.currentModuleChain];
|
|
6898
6845
|
this.name = parentModule ? `${parentModule.name} > ${name}` : name;
|
|
6899
6846
|
this.assert = new _ModuleContext.Assert(this);
|
|
6900
6847
|
this.userContext = parentModule ? Object.create(parentModule.userContext) : /* @__PURE__ */ Object.create(null);
|
|
@@ -7699,12 +7646,12 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7699
7646
|
});
|
|
7700
7647
|
return;
|
|
7701
7648
|
}
|
|
7702
|
-
const targetModuleContent = moduleContent
|
|
7649
|
+
const targetModuleContent = moduleContent ?? runtimeOptions;
|
|
7703
7650
|
const moduleContext = new ModuleContext(moduleName);
|
|
7704
7651
|
describe(moduleName, { ...targetRuntimeOptions }, function() {
|
|
7705
7652
|
const beforeHooks = [];
|
|
7706
7653
|
const afterHooks = [];
|
|
7707
|
-
beforeAll(async
|
|
7654
|
+
beforeAll(async () => {
|
|
7708
7655
|
const firstTest = moduleContext.tests[0];
|
|
7709
7656
|
const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
|
|
7710
7657
|
for (const hook of beforeHooks) {
|
|
@@ -7712,17 +7659,16 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7712
7659
|
}
|
|
7713
7660
|
});
|
|
7714
7661
|
afterAll(async () => {
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
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);
|
|
7719
7665
|
if (lastTest) {
|
|
7720
|
-
for (
|
|
7721
|
-
await
|
|
7666
|
+
for (const hook of afterHooks.toReversed()) {
|
|
7667
|
+
await hook.call(lastTest.userContext, lastTest.assert, { context: lastTest.userContext });
|
|
7722
7668
|
}
|
|
7723
7669
|
}
|
|
7724
|
-
for (
|
|
7725
|
-
|
|
7670
|
+
for (const testCtx of moduleContext.tests) {
|
|
7671
|
+
testCtx.finish();
|
|
7726
7672
|
}
|
|
7727
7673
|
});
|
|
7728
7674
|
targetModuleContent.call(moduleContext.userContext, {
|
|
@@ -7738,7 +7684,7 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7738
7684
|
after(afterFn) {
|
|
7739
7685
|
afterHooks.push(afterFn);
|
|
7740
7686
|
}
|
|
7741
|
-
}, { moduleName, options:
|
|
7687
|
+
}, { moduleName, options: targetRuntimeOptions, context: moduleContext.userContext });
|
|
7742
7688
|
ModuleContext.currentModuleChain.pop();
|
|
7743
7689
|
});
|
|
7744
7690
|
}
|
|
@@ -7764,37 +7710,36 @@ function test2(testName, runtimeOptions, testContent) {
|
|
|
7764
7710
|
});
|
|
7765
7711
|
return;
|
|
7766
7712
|
}
|
|
7767
|
-
const targetTestContent = testContent
|
|
7713
|
+
const targetTestContent = testContent ?? runtimeOptions;
|
|
7768
7714
|
const context = new TestContext(testName, moduleContext);
|
|
7769
7715
|
const userContext = Object.create(moduleContext.userContext);
|
|
7770
7716
|
context.userContext = userContext;
|
|
7771
7717
|
it(testName, { ...targetRuntimeOptions }, function() {
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
}
|
|
7718
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
7719
|
+
context.rejectTimeout = reject;
|
|
7720
|
+
const hookMeta = { context: userContext };
|
|
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);
|
|
7781
7726
|
}
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
}
|
|
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);
|
|
7789
7733
|
}
|
|
7790
|
-
resolve(result);
|
|
7791
|
-
} catch (err) {
|
|
7792
|
-
reject(err);
|
|
7793
|
-
} finally {
|
|
7794
|
-
context.clearTimeoutHandle();
|
|
7795
7734
|
}
|
|
7796
|
-
|
|
7797
|
-
|
|
7735
|
+
resolve();
|
|
7736
|
+
} catch (err) {
|
|
7737
|
+
reject(err);
|
|
7738
|
+
} finally {
|
|
7739
|
+
context.clearTimeoutHandle();
|
|
7740
|
+
}
|
|
7741
|
+
})();
|
|
7742
|
+
return promise;
|
|
7798
7743
|
});
|
|
7799
7744
|
}
|
|
7800
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
|
*
|
|
@@ -45,3 +43,5 @@ declare namespace module {
|
|
|
45
43
|
var todo: (moduleName: string, _moduleContent?: unknown) => void;
|
|
46
44
|
}
|
|
47
45
|
export default module;
|
|
46
|
+
export type { Assert };
|
|
47
|
+
export type { HookFn, HooksObject, PushResultInfo } from '../types.d.ts';
|
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
|
}
|
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';
|