qunitx 1.2.6 → 1.2.8
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 +172 -186
- 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 +89 -55
- 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 +22 -21
- package/shims/deno/module.ts +15 -15
- package/shims/deno/test.ts +30 -29
- package/shims/shared/assert.ts +92 -56
- 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.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() {
|
|
@@ -6412,7 +6399,7 @@ var Assert = class _Assert {
|
|
|
6412
6399
|
throw new _Assert.AssertionError({
|
|
6413
6400
|
actual,
|
|
6414
6401
|
expected,
|
|
6415
|
-
message: message || `
|
|
6402
|
+
message: message || `Values are not equal:${formatDiff(actual, expected)}`,
|
|
6416
6403
|
operator: "==",
|
|
6417
6404
|
stackStartFn: this.equal
|
|
6418
6405
|
});
|
|
@@ -6437,7 +6424,7 @@ var Assert = class _Assert {
|
|
|
6437
6424
|
actual,
|
|
6438
6425
|
expected,
|
|
6439
6426
|
operator: "!=",
|
|
6440
|
-
message: message || `
|
|
6427
|
+
message: message || `Values are unexpectedly equal:${formatUnexpectedMatch(actual)}`,
|
|
6441
6428
|
stackStartFn: this.notEqual
|
|
6442
6429
|
});
|
|
6443
6430
|
}
|
|
@@ -6466,7 +6453,7 @@ var Assert = class _Assert {
|
|
|
6466
6453
|
throw new _Assert.AssertionError({
|
|
6467
6454
|
actual: targetActual,
|
|
6468
6455
|
expected: targetExpected,
|
|
6469
|
-
message: message || `
|
|
6456
|
+
message: message || `Own properties are not equal:${formatDiff(targetActual, targetExpected)}`,
|
|
6470
6457
|
stackStartFn: this.propEqual
|
|
6471
6458
|
});
|
|
6472
6459
|
}
|
|
@@ -6492,7 +6479,7 @@ var Assert = class _Assert {
|
|
|
6492
6479
|
throw new _Assert.AssertionError({
|
|
6493
6480
|
actual: targetActual,
|
|
6494
6481
|
expected: targetExpected,
|
|
6495
|
-
message: message || `
|
|
6482
|
+
message: message || `Own properties are unexpectedly equal:${formatUnexpectedMatch(targetActual)}`,
|
|
6496
6483
|
stackStartFn: this.notPropEqual
|
|
6497
6484
|
});
|
|
6498
6485
|
}
|
|
@@ -6518,7 +6505,7 @@ var Assert = class _Assert {
|
|
|
6518
6505
|
throw new _Assert.AssertionError({
|
|
6519
6506
|
actual: targetActual,
|
|
6520
6507
|
expected: targetExpected,
|
|
6521
|
-
message: message || `
|
|
6508
|
+
message: message || `Object does not contain expected properties:${formatDiff(targetActual, targetExpected)}`,
|
|
6522
6509
|
stackStartFn: this.propContains
|
|
6523
6510
|
});
|
|
6524
6511
|
}
|
|
@@ -6544,7 +6531,7 @@ var Assert = class _Assert {
|
|
|
6544
6531
|
throw new _Assert.AssertionError({
|
|
6545
6532
|
actual: targetActual,
|
|
6546
6533
|
expected: targetExpected,
|
|
6547
|
-
message: message || `
|
|
6534
|
+
message: message || `Object unexpectedly contains all expected properties:${formatUnexpectedMatch(targetActual)}`,
|
|
6548
6535
|
stackStartFn: this.notPropContains
|
|
6549
6536
|
});
|
|
6550
6537
|
}
|
|
@@ -6568,7 +6555,7 @@ var Assert = class _Assert {
|
|
|
6568
6555
|
throw new _Assert.AssertionError({
|
|
6569
6556
|
actual,
|
|
6570
6557
|
expected,
|
|
6571
|
-
message: message || `
|
|
6558
|
+
message: message || `Values are not deeply equal:${formatDiff(actual, expected)}`,
|
|
6572
6559
|
operator: "deepEqual",
|
|
6573
6560
|
stackStartFn: this.deepEqual
|
|
6574
6561
|
});
|
|
@@ -6592,7 +6579,7 @@ var Assert = class _Assert {
|
|
|
6592
6579
|
throw new _Assert.AssertionError({
|
|
6593
6580
|
actual,
|
|
6594
6581
|
expected,
|
|
6595
|
-
message: message || `
|
|
6582
|
+
message: message || `Values are unexpectedly deeply equal:${formatUnexpectedMatch(actual)}`,
|
|
6596
6583
|
operator: "notDeepEqual",
|
|
6597
6584
|
stackStartFn: this.notDeepEqual
|
|
6598
6585
|
});
|
|
@@ -6616,7 +6603,7 @@ var Assert = class _Assert {
|
|
|
6616
6603
|
throw new _Assert.AssertionError({
|
|
6617
6604
|
actual,
|
|
6618
6605
|
expected,
|
|
6619
|
-
message: message || `
|
|
6606
|
+
message: message || `Values are not strictly equal:${formatDiff(actual, expected)}`,
|
|
6620
6607
|
operator: "strictEqual",
|
|
6621
6608
|
stackStartFn: this.strictEqual
|
|
6622
6609
|
});
|
|
@@ -6640,7 +6627,7 @@ var Assert = class _Assert {
|
|
|
6640
6627
|
throw new _Assert.AssertionError({
|
|
6641
6628
|
actual,
|
|
6642
6629
|
expected,
|
|
6643
|
-
message: message || `
|
|
6630
|
+
message: message || `Values are unexpectedly strictly equal:${formatUnexpectedMatch(actual)}`,
|
|
6644
6631
|
operator: "notStrictEqual",
|
|
6645
6632
|
stackStartFn: this.notStrictEqual
|
|
6646
6633
|
});
|
|
@@ -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,20 +6659,31 @@ 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
|
-
const [result,
|
|
6666
|
+
const [result, , validatedMessage] = validateException(error, expected, message);
|
|
6679
6667
|
if (result === false) {
|
|
6668
|
+
const expectedDesc = describeExpected(expected);
|
|
6669
|
+
const receivedDesc = String(error);
|
|
6680
6670
|
throw new _Assert.AssertionError({
|
|
6681
|
-
actual:
|
|
6682
|
-
expected:
|
|
6683
|
-
message: validatedMessage,
|
|
6671
|
+
actual: receivedDesc,
|
|
6672
|
+
expected: expectedDesc,
|
|
6673
|
+
message: validatedMessage || throwsFailMessage("throws", expectedDesc, receivedDesc),
|
|
6684
6674
|
stackStartFn: this.throws
|
|
6685
6675
|
});
|
|
6686
6676
|
}
|
|
6687
6677
|
return;
|
|
6688
6678
|
}
|
|
6679
|
+
if (returnValue !== null && typeof returnValue === "object" && typeof returnValue.then === "function") {
|
|
6680
|
+
throw new _Assert.AssertionError({
|
|
6681
|
+
actual: returnValue,
|
|
6682
|
+
expected,
|
|
6683
|
+
message: "Function passed to `assert.throws` returned a Promise \u2014 did you mean to use `assert.rejects`?",
|
|
6684
|
+
stackStartFn: this.throws
|
|
6685
|
+
});
|
|
6686
|
+
}
|
|
6689
6687
|
throw new _Assert.AssertionError({
|
|
6690
6688
|
actual: blockFn,
|
|
6691
6689
|
expected,
|
|
@@ -6720,15 +6718,13 @@ var Assert = class _Assert {
|
|
|
6720
6718
|
stackStartFn: this.rejects
|
|
6721
6719
|
});
|
|
6722
6720
|
}
|
|
6723
|
-
let
|
|
6724
|
-
let rejectionError;
|
|
6721
|
+
let caught = PENDING;
|
|
6725
6722
|
try {
|
|
6726
6723
|
await promise;
|
|
6727
6724
|
} catch (error) {
|
|
6728
|
-
|
|
6729
|
-
rejectionError = error;
|
|
6725
|
+
caught = error;
|
|
6730
6726
|
}
|
|
6731
|
-
if (
|
|
6727
|
+
if (caught === PENDING) {
|
|
6732
6728
|
throw new _Assert.AssertionError({
|
|
6733
6729
|
actual: promise,
|
|
6734
6730
|
expected,
|
|
@@ -6736,71 +6732,92 @@ var Assert = class _Assert {
|
|
|
6736
6732
|
stackStartFn: this.rejects
|
|
6737
6733
|
});
|
|
6738
6734
|
}
|
|
6739
|
-
const [result,
|
|
6735
|
+
const [result, , validatedMessage] = validateException(caught, expected, message);
|
|
6740
6736
|
if (result === false) {
|
|
6737
|
+
const expectedDesc = describeExpected(expected);
|
|
6738
|
+
const receivedDesc = String(caught);
|
|
6741
6739
|
throw new _Assert.AssertionError({
|
|
6742
|
-
actual:
|
|
6743
|
-
expected:
|
|
6744
|
-
message: validatedMessage,
|
|
6740
|
+
actual: receivedDesc,
|
|
6741
|
+
expected: expectedDesc,
|
|
6742
|
+
message: validatedMessage || throwsFailMessage("rejects", expectedDesc, receivedDesc),
|
|
6745
6743
|
stackStartFn: this.rejects
|
|
6746
6744
|
});
|
|
6747
6745
|
}
|
|
6748
6746
|
}
|
|
6749
6747
|
};
|
|
6750
|
-
|
|
6751
|
-
|
|
6748
|
+
var INSPECT_OPTIONS = { depth: 10, colors: true, compact: false };
|
|
6749
|
+
var inspect = (value) => Assert.inspect(value, INSPECT_OPTIONS);
|
|
6750
|
+
function formatDiff(actual, expected) {
|
|
6751
|
+
const aStr = inspect(actual), bStr = inspect(expected);
|
|
6752
|
+
const aLines = aStr.split("\n"), bLines = bStr.split("\n");
|
|
6753
|
+
if (aLines.length === 1 && bLines.length === 1) return `
|
|
6752
6754
|
|
|
6753
|
-
${
|
|
6755
|
+
Actual: ${aStr}
|
|
6756
|
+
Expected: ${bStr}`;
|
|
6757
|
+
const lines = lcsDiff(aLines, bLines).map(
|
|
6758
|
+
([t, line]) => t === "=" ? ` ${line}` : t === "-" ? `- ${line}` : `+ ${line}`
|
|
6759
|
+
);
|
|
6760
|
+
return `
|
|
6754
6761
|
|
|
6755
|
-
|
|
6762
|
+
- Actual + Expected
|
|
6756
6763
|
|
|
6757
|
-
${
|
|
6764
|
+
${lines.join("\n")}`;
|
|
6758
6765
|
}
|
|
6759
|
-
|
|
6760
|
-
|
|
6766
|
+
var formatUnexpectedMatch = (actual) => `
|
|
6767
|
+
|
|
6768
|
+
${inspect(actual)}`;
|
|
6769
|
+
var describeExpected = (expected) => expected == null ? "(no pattern)" : typeof expected === "string" ? expected : typeof expected === "function" ? expected.name || String(expected) : String(expected);
|
|
6770
|
+
var throwsFailMessage = (method, pattern, received) => `assert.${method}: thrown error did not match expected:
|
|
6771
|
+
|
|
6772
|
+
Pattern: ${pattern}
|
|
6773
|
+
Received: ${received}`;
|
|
6774
|
+
function lcsDiff(a, b) {
|
|
6775
|
+
const m = a.length, n = b.length;
|
|
6776
|
+
const dp = Array.from({ length: m + 1 }, () => new Array(n + 1).fill(0));
|
|
6777
|
+
for (let i2 = 1; i2 <= m; i2++)
|
|
6778
|
+
for (let j2 = 1; j2 <= n; j2++)
|
|
6779
|
+
dp[i2][j2] = a[i2 - 1] === b[j2 - 1] ? dp[i2 - 1][j2 - 1] + 1 : Math.max(dp[i2 - 1][j2], dp[i2][j2 - 1]);
|
|
6780
|
+
const result = [];
|
|
6781
|
+
let i = m, j = n;
|
|
6782
|
+
while (i > 0 || j > 0) {
|
|
6783
|
+
if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
|
|
6784
|
+
result.push(["=", a[i - 1]]);
|
|
6785
|
+
i--;
|
|
6786
|
+
j--;
|
|
6787
|
+
} else if (j > 0 && (i === 0 || dp[i][j - 1] >= dp[i - 1][j])) {
|
|
6788
|
+
result.push(["+", b[j - 1]]);
|
|
6789
|
+
j--;
|
|
6790
|
+
} else {
|
|
6791
|
+
result.push(["-", a[i - 1]]);
|
|
6792
|
+
i--;
|
|
6793
|
+
}
|
|
6794
|
+
}
|
|
6795
|
+
return result.reverse();
|
|
6761
6796
|
}
|
|
6762
6797
|
|
|
6763
6798
|
// shims/shared/test-context.ts
|
|
6764
6799
|
var TestContext = class _TestContext {
|
|
6765
6800
|
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
|
-
}
|
|
6801
|
+
name;
|
|
6802
|
+
module;
|
|
6803
|
+
asyncOps = [];
|
|
6804
|
+
assert;
|
|
6805
|
+
timeout;
|
|
6806
|
+
steps = [];
|
|
6807
|
+
expectedAssertionCount;
|
|
6808
|
+
totalExecutedAssertions = 0;
|
|
6809
|
+
userContext = {};
|
|
6801
6810
|
rejectTimeout;
|
|
6802
6811
|
#timeoutHandle;
|
|
6803
6812
|
#timedOut = false;
|
|
6813
|
+
constructor(name, moduleContext) {
|
|
6814
|
+
if (moduleContext) {
|
|
6815
|
+
this.name = `${moduleContext.name} | ${name}`;
|
|
6816
|
+
this.module = moduleContext;
|
|
6817
|
+
this.module.tests.push(this);
|
|
6818
|
+
this.assert = new _TestContext.Assert(moduleContext, this);
|
|
6819
|
+
}
|
|
6820
|
+
}
|
|
6804
6821
|
setTimeoutDuration(ms) {
|
|
6805
6822
|
if (this.#timeoutHandle !== void 0) {
|
|
6806
6823
|
clearTimeout(this.#timeoutHandle);
|
|
@@ -6818,59 +6835,29 @@ var TestContext = class _TestContext {
|
|
|
6818
6835
|
this.#timeoutHandle = void 0;
|
|
6819
6836
|
}
|
|
6820
6837
|
}
|
|
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
6838
|
finish() {
|
|
6852
6839
|
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) {
|
|
6840
|
+
if (this.steps.length > 0) {
|
|
6861
6841
|
this.assert.pushResult({
|
|
6862
6842
|
result: false,
|
|
6863
6843
|
actual: this.steps,
|
|
6864
6844
|
expected: [],
|
|
6865
6845
|
message: `Expected assert.verifySteps() to be called before end of test after using assert.step(). Unverified steps: ${this.steps.join(", ")}`
|
|
6866
6846
|
});
|
|
6867
|
-
} else if (this.expectedAssertionCount && this.expectedAssertionCount !== this.totalExecutedAssertions) {
|
|
6847
|
+
} else if (this.expectedAssertionCount !== void 0 && this.expectedAssertionCount !== this.totalExecutedAssertions) {
|
|
6868
6848
|
this.assert.pushResult({
|
|
6869
6849
|
result: false,
|
|
6870
6850
|
actual: this.totalExecutedAssertions,
|
|
6871
6851
|
expected: this.expectedAssertionCount,
|
|
6872
6852
|
message: `Expected ${this.expectedAssertionCount} assertions, but ${this.totalExecutedAssertions} were run for test: ${this.name}`
|
|
6873
6853
|
});
|
|
6854
|
+
} else if (this.expectedAssertionCount === void 0 && this.totalExecutedAssertions === 0) {
|
|
6855
|
+
this.assert.pushResult({
|
|
6856
|
+
result: false,
|
|
6857
|
+
actual: this.totalExecutedAssertions,
|
|
6858
|
+
expected: "> 0",
|
|
6859
|
+
message: `Expected at least one assertion to be run for test: ${this.name}`
|
|
6860
|
+
});
|
|
6874
6861
|
}
|
|
6875
6862
|
}
|
|
6876
6863
|
};
|
|
@@ -6880,21 +6867,21 @@ var ModuleContext = class _ModuleContext {
|
|
|
6880
6867
|
static Assert;
|
|
6881
6868
|
static currentModuleChain = [];
|
|
6882
6869
|
static get lastModule() {
|
|
6883
|
-
return this.currentModuleChain
|
|
6870
|
+
return this.currentModuleChain.at(-1);
|
|
6884
6871
|
}
|
|
6885
6872
|
name;
|
|
6886
6873
|
assert;
|
|
6887
6874
|
userContext;
|
|
6888
6875
|
// Internal fallback assert for modules with no direct tests
|
|
6889
|
-
|
|
6876
|
+
testContext = new TestContext();
|
|
6890
6877
|
moduleChain = [];
|
|
6891
6878
|
beforeEachHooks = [];
|
|
6892
6879
|
afterEachHooks = [];
|
|
6893
6880
|
tests = [];
|
|
6894
6881
|
constructor(name) {
|
|
6895
|
-
const parentModule = _ModuleContext.currentModuleChain
|
|
6882
|
+
const parentModule = _ModuleContext.currentModuleChain.at(-1);
|
|
6896
6883
|
_ModuleContext.currentModuleChain.push(this);
|
|
6897
|
-
this.moduleChain = _ModuleContext.currentModuleChain
|
|
6884
|
+
this.moduleChain = [..._ModuleContext.currentModuleChain];
|
|
6898
6885
|
this.name = parentModule ? `${parentModule.name} > ${name}` : name;
|
|
6899
6886
|
this.assert = new _ModuleContext.Assert(this);
|
|
6900
6887
|
this.userContext = parentModule ? Object.create(parentModule.userContext) : /* @__PURE__ */ Object.create(null);
|
|
@@ -7699,12 +7686,12 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7699
7686
|
});
|
|
7700
7687
|
return;
|
|
7701
7688
|
}
|
|
7702
|
-
const targetModuleContent = moduleContent
|
|
7689
|
+
const targetModuleContent = moduleContent ?? runtimeOptions;
|
|
7703
7690
|
const moduleContext = new ModuleContext(moduleName);
|
|
7704
7691
|
describe(moduleName, { ...targetRuntimeOptions }, function() {
|
|
7705
7692
|
const beforeHooks = [];
|
|
7706
7693
|
const afterHooks = [];
|
|
7707
|
-
beforeAll(async
|
|
7694
|
+
beforeAll(async () => {
|
|
7708
7695
|
const firstTest = moduleContext.tests[0];
|
|
7709
7696
|
const beforeAssert = firstTest ? firstTest.assert : moduleContext.assert;
|
|
7710
7697
|
for (const hook of beforeHooks) {
|
|
@@ -7712,17 +7699,16 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7712
7699
|
}
|
|
7713
7700
|
});
|
|
7714
7701
|
afterAll(async () => {
|
|
7715
|
-
|
|
7716
|
-
|
|
7717
|
-
|
|
7718
|
-
const lastTest = moduleContext.tests[moduleContext.tests.length - 1];
|
|
7702
|
+
const allAsyncOps = moduleContext.tests.flatMap((t) => t.asyncOps);
|
|
7703
|
+
if (allAsyncOps.length > 0) await Promise.all(allAsyncOps);
|
|
7704
|
+
const lastTest = moduleContext.tests.at(-1);
|
|
7719
7705
|
if (lastTest) {
|
|
7720
|
-
for (
|
|
7721
|
-
await
|
|
7706
|
+
for (const hook of afterHooks.toReversed()) {
|
|
7707
|
+
await hook.call(lastTest.userContext, lastTest.assert, { context: lastTest.userContext });
|
|
7722
7708
|
}
|
|
7723
7709
|
}
|
|
7724
|
-
for (
|
|
7725
|
-
|
|
7710
|
+
for (const testCtx of moduleContext.tests) {
|
|
7711
|
+
testCtx.finish();
|
|
7726
7712
|
}
|
|
7727
7713
|
});
|
|
7728
7714
|
targetModuleContent.call(moduleContext.userContext, {
|
|
@@ -7738,7 +7724,7 @@ function module(moduleName, runtimeOptions, moduleContent) {
|
|
|
7738
7724
|
after(afterFn) {
|
|
7739
7725
|
afterHooks.push(afterFn);
|
|
7740
7726
|
}
|
|
7741
|
-
}, { moduleName, options:
|
|
7727
|
+
}, { moduleName, options: targetRuntimeOptions, context: moduleContext.userContext });
|
|
7742
7728
|
ModuleContext.currentModuleChain.pop();
|
|
7743
7729
|
});
|
|
7744
7730
|
}
|
|
@@ -7764,37 +7750,36 @@ function test2(testName, runtimeOptions, testContent) {
|
|
|
7764
7750
|
});
|
|
7765
7751
|
return;
|
|
7766
7752
|
}
|
|
7767
|
-
const targetTestContent = testContent
|
|
7753
|
+
const targetTestContent = testContent ?? runtimeOptions;
|
|
7768
7754
|
const context = new TestContext(testName, moduleContext);
|
|
7769
7755
|
const userContext = Object.create(moduleContext.userContext);
|
|
7770
7756
|
context.userContext = userContext;
|
|
7771
7757
|
it(testName, { ...targetRuntimeOptions }, function() {
|
|
7772
|
-
|
|
7773
|
-
|
|
7774
|
-
|
|
7775
|
-
|
|
7776
|
-
|
|
7777
|
-
|
|
7778
|
-
|
|
7779
|
-
|
|
7780
|
-
}
|
|
7758
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
7759
|
+
context.rejectTimeout = reject;
|
|
7760
|
+
const hookMeta = { context: userContext };
|
|
7761
|
+
(async () => {
|
|
7762
|
+
try {
|
|
7763
|
+
for (const mod of context.module.moduleChain) {
|
|
7764
|
+
for (const hook of mod.beforeEachHooks) {
|
|
7765
|
+
await hook.call(userContext, context.assert, hookMeta);
|
|
7781
7766
|
}
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
}
|
|
7767
|
+
}
|
|
7768
|
+
await targetTestContent.call(userContext, context.assert, { testName, options: targetRuntimeOptions, context: userContext });
|
|
7769
|
+
await context.assert.waitForAsyncOps();
|
|
7770
|
+
for (const mod of context.module.moduleChain.toReversed()) {
|
|
7771
|
+
for (const hook of mod.afterEachHooks.toReversed()) {
|
|
7772
|
+
await hook.call(userContext, context.assert, hookMeta);
|
|
7789
7773
|
}
|
|
7790
|
-
resolve(result);
|
|
7791
|
-
} catch (err) {
|
|
7792
|
-
reject(err);
|
|
7793
|
-
} finally {
|
|
7794
|
-
context.clearTimeoutHandle();
|
|
7795
7774
|
}
|
|
7796
|
-
|
|
7797
|
-
|
|
7775
|
+
resolve();
|
|
7776
|
+
} catch (err) {
|
|
7777
|
+
reject(err);
|
|
7778
|
+
} finally {
|
|
7779
|
+
context.clearTimeoutHandle();
|
|
7780
|
+
}
|
|
7781
|
+
})();
|
|
7782
|
+
return promise;
|
|
7798
7783
|
});
|
|
7799
7784
|
}
|
|
7800
7785
|
test2.skip = function skipTest(testName, _testContent) {
|
|
@@ -7810,6 +7795,7 @@ test2.todo = function todoTest(testName, _testContent) {
|
|
|
7810
7795
|
var AssertionError2 = class extends AssertionError {
|
|
7811
7796
|
constructor(object) {
|
|
7812
7797
|
super(object.message ?? "Assertion failed");
|
|
7798
|
+
if (object.stackStartFn) Error.captureStackTrace(this, object.stackStartFn);
|
|
7813
7799
|
}
|
|
7814
7800
|
};
|
|
7815
7801
|
Assert.QUnit = globalThis.QUnit;
|
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';
|