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