qunitx 0.9.0 → 0.9.2

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.
@@ -1,237 +1,22 @@
1
- import { describe, it, before as beforeAll, after as afterAll } from 'node:test';
2
- import Assert from './assert.js';
1
+ import { AssertionError } from 'node:assert';
2
+ import QUnit from '../../vendor/qunit.js';
3
+ import Assert from '../shared/assert.js';
4
+ import ModuleContext from '../shared/module-context.js';
5
+ import TestContext from '../shared/test-context.js';
6
+ import Module from './module.js';
7
+ import Test from './test.js';
3
8
 
4
- // NOTE: node.js beforeEach & afterEach is buggy because the TestContext it has is NOT correct reference when called, it gets the last context
5
- // NOTE: QUnit expect() logic is buggy in nested modules
6
- // NOTE: after gets the last direct children test of the module, not last defined context of a module(last defined context is a module)
9
+ Assert.QUnit = QUnit;
10
+ Assert.AssertionError = AssertionError;
7
11
 
8
- class TestContext {
9
- name;
12
+ ModuleContext.Assert = Assert;
13
+ TestContext.Assert = Assert;
10
14
 
11
- #module;
12
- get module() {
13
- return this.#module;
14
- }
15
- set module(value) {
16
- this.#module = value;
17
- }
15
+ Object.freeze(Assert);
16
+ Object.freeze(ModuleContext);
17
+ Object.freeze(TestContext);
18
18
 
19
- #assert;
20
- get assert() {
21
- return this.#assert;
22
- }
23
- set assert(value) {
24
- this.#assert = value;
25
- }
19
+ export const module = Module;
20
+ export const test = Test;
26
21
 
27
- #timeout;
28
- get timeout() {
29
- return this.#timeout;
30
- }
31
- set timeout(value) {
32
- this.#timeout = value;
33
- }
34
-
35
- #steps = [];
36
- get steps() {
37
- return this.#steps;
38
- }
39
- set steps(value) {
40
- this.#steps = value;
41
- }
42
-
43
- #expectedAssertionCount;
44
- get expectedAssertionCount() {
45
- return this.#expectedAssertionCount;
46
- }
47
- set expectedAssertionCount(value) {
48
- this.#expectedAssertionCount = value;
49
- }
50
-
51
- #totalExecutedAssertions = 0;
52
- get totalExecutedAssertions() {
53
- return this.#totalExecutedAssertions;
54
- }
55
- set totalExecutedAssertions(value) {
56
- this.#totalExecutedAssertions = value;
57
- }
58
-
59
- constructor(name, moduleContext) {
60
- if (moduleContext) {
61
- this.name = `${moduleContext.name} | ${name}`;
62
- this.module = moduleContext;
63
- this.module.tests.push(this);
64
- this.assert = new Assert(moduleContext, this);
65
- }
66
- }
67
-
68
- finish() {
69
- if (this.totalExecutedAssertions === 0) {
70
- this.assert.pushResult({
71
- result: false,
72
- actual: this.totalExecutedAssertions,
73
- expected: '> 0',
74
- message: `Expected at least one assertion to be run for test: ${this.name}`,
75
- });
76
- } else if (this.steps.length > 0) {
77
- this.assert.pushResult({
78
- result: false,
79
- actual: this.steps,
80
- expected: [],
81
- message: `Expected assert.verifySteps() to be called before end of test after using assert.step(). Unverified steps: ${this.steps.join(', ')}`,
82
- });
83
- } else if (this.expectedAssertionCount && this.expectedAssertionCount !== this.totalExecutedAssertions) {
84
- this.assert.pushResult({
85
- result: false,
86
- actual: this.totalExecutedAssertions,
87
- expected: this.expectedAssertionCount,
88
- message: `Expected ${this.expectedAssertionCount} assertions, but ${this.totalExecutedAssertions} were run for test: ${this.name}`,
89
- });
90
- }
91
- }
92
- }
93
-
94
- class ModuleContext extends TestContext {
95
- static currentModuleChain = [];
96
-
97
- static get lastModule() {
98
- return this.currentModuleChain[this.currentModuleChain.length - 1];
99
- }
100
-
101
- #tests = [];
102
- get tests() {
103
- return this.#tests;
104
- }
105
-
106
- #beforeEachHooks = [];
107
- get beforeEachHooks() {
108
- return this.#beforeEachHooks;
109
- }
110
-
111
- #afterEachHooks = [];
112
- get afterEachHooks() {
113
- return this.#afterEachHooks;
114
- }
115
-
116
- #moduleChain = [];
117
- get moduleChain() {
118
- return this.#moduleChain;
119
- }
120
- set moduleChain(value) {
121
- this.#moduleChain = value;
122
- }
123
-
124
- constructor(name) {
125
- super(name);
126
-
127
- let parentModule = ModuleContext.currentModuleChain[ModuleContext.currentModuleChain.length - 1];
128
-
129
- ModuleContext.currentModuleChain.push(this);
130
-
131
- this.moduleChain = ModuleContext.currentModuleChain.slice(0);
132
- this.name = parentModule ? `${parentModule.name} > ${name}` : name;
133
- this.assert = new Assert(this);
134
- }
135
- }
136
-
137
- export const module = (moduleName, runtimeOptions, moduleContent) => {
138
- let targetRuntimeOptions = moduleContent ? runtimeOptions : {};
139
- let targetModuleContent = moduleContent ? moduleContent : runtimeOptions;
140
- let moduleContext = new ModuleContext(moduleName);
141
-
142
- return describe(moduleName, { concurrency: true, ...targetRuntimeOptions }, async function () {
143
- let beforeHooks = [];
144
- let afterHooks = [];
145
-
146
- beforeAll(async function () {
147
- Object.assign(moduleContext, moduleContext.moduleChain.reduce((result, module) => {
148
- const { name, ...moduleWithoutName } = module;
149
-
150
- return Object.assign(result, moduleWithoutName, {
151
- steps: result.steps.concat(module.steps),
152
- expectedAssertionCount: module.expectedAssertionCount
153
- ? module.expectedAssertionCount
154
- : result.expectedAssertionCount
155
- });
156
- }, { steps: [], expectedAssertionCount: undefined }));
157
-
158
- for (let hook of beforeHooks) {
159
- await hook.call(moduleContext, moduleContext.assert);
160
- }
161
-
162
- moduleContext.tests.forEach((testContext) => {
163
- const { name, ...moduleContextWithoutName } = moduleContext;
164
-
165
- Object.assign(testContext, moduleContextWithoutName, {
166
- steps: moduleContext.steps,
167
- totalExecutedAssertions: moduleContext.totalExecutedAssertions,
168
- expectedAssertionCount: moduleContext.expectedAssertionCount,
169
- });
170
- });
171
- });
172
- afterAll(async () => {
173
- for (const assert of moduleContext.tests.map(testContext => testContext.assert)) {
174
- await assert.waitForAsyncOps();
175
- }
176
-
177
- let targetContext = moduleContext.tests[moduleContext.tests.length - 1];
178
- for (let j = afterHooks.length - 1; j >= 0; j--) {
179
- await afterHooks[j].call(targetContext, targetContext.assert);
180
- }
181
-
182
- moduleContext.tests.forEach(testContext => testContext.finish());
183
- });
184
-
185
- targetModuleContent.call(moduleContext, {
186
- before(beforeFn) {
187
- return beforeHooks.push(beforeFn);
188
- },
189
- beforeEach(beforeEachFn) {
190
- return moduleContext.beforeEachHooks.push(beforeEachFn);
191
- },
192
- afterEach(afterEachFn) {
193
- return moduleContext.afterEachHooks.push(afterEachFn);
194
- },
195
- after(afterFn) {
196
- return afterHooks.push(afterFn);
197
- }
198
- }, { moduleName, options: runtimeOptions });
199
-
200
- ModuleContext.currentModuleChain.pop();
201
- });
202
- }
203
-
204
- export const test = (testName, runtimeOptions, testContent) => {
205
- let moduleContext = ModuleContext.lastModule;
206
- if (!moduleContext) {
207
- throw new Error(`Test '${testName}' called outside of module context.`);
208
- }
209
-
210
- let targetRuntimeOptions = testContent ? runtimeOptions : {};
211
- let targetTestContent = testContent ? testContent : runtimeOptions;
212
- let context = new TestContext(testName, moduleContext);
213
-
214
- return it(testName, { concurrency: true, ...targetRuntimeOptions }, async function () {
215
- let result;
216
- for (let module of context.module.moduleChain) {
217
- for (let hook of module.beforeEachHooks) {
218
- await hook.call(context, context.assert);
219
- }
220
- }
221
-
222
- result = await targetTestContent.call(context, context.assert, { testName, options: runtimeOptions });
223
-
224
- await context.assert.waitForAsyncOps();
225
-
226
- for (let i = context.module.moduleChain.length - 1; i >= 0; i--) {
227
- let module = context.module.moduleChain[i];
228
- for (let j = module.afterEachHooks.length - 1; j >= 0; j--) {
229
- await module.afterEachHooks[j].call(context, context.assert);
230
- }
231
- }
232
-
233
- return result;
234
- });
235
- }
236
-
237
- export default { module, test, config: {} };
22
+ export default { AssertionError: Assert.AssertionError, module, test, config: {} };
@@ -0,0 +1,71 @@
1
+ import { describe, before as beforeAll, after as afterAll } from 'node:test';
2
+ import ModuleContext from '../shared/module-context.js';
3
+
4
+ // NOTE: node.js beforeEach & afterEach is buggy because the TestContext it has is NOT correct reference when called, it gets the last context
5
+ // NOTE: QUnit expect() logic is buggy in nested modules
6
+ // NOTE: after gets the last direct children test of the module, not last defined context of a module(last defined context is a module)
7
+
8
+ export default function module(moduleName, runtimeOptions, moduleContent) {
9
+ let targetRuntimeOptions = moduleContent ? runtimeOptions : {};
10
+ let targetModuleContent = moduleContent ? moduleContent : runtimeOptions;
11
+ let moduleContext = new ModuleContext(moduleName);
12
+
13
+ return describe(moduleName, { concurrency: true, ...targetRuntimeOptions }, async function () {
14
+ let beforeHooks = [];
15
+ let afterHooks = [];
16
+
17
+ beforeAll(async function () {
18
+ Object.assign(moduleContext.context, moduleContext.moduleChain.reduce((result, module) => {
19
+ return Object.assign(result, module.context, {
20
+ steps: result.steps.concat(module.context.steps),
21
+ expectedAssertionCount: module.context.expectedAssertionCount
22
+ ? module.context.expectedAssertionCount
23
+ : result.expectedAssertionCount
24
+ });
25
+ }, { steps: [], expectedAssertionCount: undefined }));
26
+
27
+ for (let hook of beforeHooks) {
28
+ await hook.call(moduleContext.context, moduleContext.assert);
29
+ }
30
+
31
+ for (let i = 0, len = moduleContext.tests.length; i < len; i++) {
32
+ Object.assign(moduleContext.tests[i], moduleContext.context, {
33
+ steps: moduleContext.context.steps,
34
+ totalExecutedAssertions: moduleContext.context.totalExecutedAssertions,
35
+ expectedAssertionCount: moduleContext.context.expectedAssertionCount,
36
+ });
37
+ }
38
+ });
39
+ afterAll(async () => {
40
+ for (const assert of moduleContext.tests.map(testContext => testContext.assert)) {
41
+ await assert.waitForAsyncOps();
42
+ }
43
+
44
+ let targetContext = moduleContext.tests[moduleContext.tests.length - 1];
45
+ for (let j = afterHooks.length - 1; j >= 0; j--) {
46
+ await afterHooks[j].call(targetContext, targetContext.assert);
47
+ }
48
+
49
+ for (let i = 0, len = moduleContext.tests.length; i < len; i++) {
50
+ moduleContext.tests[i].finish();
51
+ }
52
+ });
53
+
54
+ targetModuleContent.call(moduleContext.context, {
55
+ before(beforeFn) {
56
+ beforeHooks[beforeHooks.length] = beforeFn;
57
+ },
58
+ beforeEach(beforeEachFn) {
59
+ moduleContext.beforeEachHooks[moduleContext.beforeEachHooks.length] = beforeEachFn;
60
+ },
61
+ afterEach(afterEachFn) {
62
+ moduleContext.afterEachHooks[moduleContext.afterEachHooks.length] = afterEachFn;
63
+ },
64
+ after(afterFn) {
65
+ afterHooks[afterHooks.length] = afterFn;
66
+ }
67
+ }, { moduleName, options: runtimeOptions });
68
+
69
+ ModuleContext.currentModuleChain.pop();
70
+ });
71
+ }
@@ -0,0 +1,36 @@
1
+ import { it } from 'node:test';
2
+ import TestContext from '../shared/test-context.js';
3
+ import ModuleContext from '../shared/module-context.js';
4
+
5
+ export default function test(testName, runtimeOptions, testContent) {
6
+ let moduleContext = ModuleContext.lastModule;
7
+ if (!moduleContext) {
8
+ throw new Error(`Test '${testName}' called outside of module context.`);
9
+ }
10
+
11
+ let targetRuntimeOptions = testContent ? runtimeOptions : {};
12
+ let targetTestContent = testContent ? testContent : runtimeOptions;
13
+ let context = new TestContext(testName, moduleContext);
14
+
15
+ return it(testName, { concurrency: true, ...targetRuntimeOptions }, async function () {
16
+ for (let module of context.module.moduleChain) {
17
+ for (let hook of module.beforeEachHooks) {
18
+ await hook.call(context, context.assert);
19
+ }
20
+ }
21
+
22
+ let result = await targetTestContent.call(context, context.assert, { testName, options: runtimeOptions });
23
+
24
+ await context.assert.waitForAsyncOps();
25
+
26
+ for (let i = context.module.moduleChain.length - 1; i >= 0; i--) {
27
+ let module = context.module.moduleChain[i];
28
+ for (let j = module.afterEachHooks.length - 1; j >= 0; j--) {
29
+ await module.afterEachHooks[j].call(context, context.assert);
30
+ }
31
+ }
32
+
33
+ return result;
34
+ });
35
+ }
36
+
@@ -1,23 +1,19 @@
1
- import QUnit from '../../vendor/qunit.js';
1
+ import '../../vendor/qunit.js';
2
2
  import { objectValues, objectValuesSubset, validateExpectedExceptionArgs, validateException } from '../shared/index.js';
3
- import assert, { AssertionError as _AssertionError } from 'node:assert';
4
3
  import util from 'node:util';
5
4
 
6
- export const AssertionError = _AssertionError;
7
-
8
5
  // More: contexts needed for timeout
9
- // NOTE: QUnit API provides assert on hooks, which makes it hard to make it concurrent
10
6
  // NOTE: Another approach for a global report Make this._assertions.set(this.currentTest, (this._assertions.get(this.currentTest) || 0) + 1); for pushResult
11
7
  // NOTE: This should *always* be a singleton(?), passed around as an argument for hooks. Seems difficult with concurrency. Singleton needs to be a concurrent data structure.
12
8
 
13
9
  export default class Assert {
14
- AssertionError = _AssertionError;
15
-
16
- #asyncOps = [];
10
+ static QUnit;
11
+ static AssertionError;
17
12
 
18
13
  constructor(module, test) {
19
- this.test = test || module;
14
+ this.test = test || module.context;
20
15
  }
16
+
21
17
  _incrementAssertionCount() {
22
18
  this.test.totalExecutedAssertions++;
23
19
  }
@@ -61,17 +57,17 @@ export default class Assert {
61
57
  let resolveFn;
62
58
  let done = new Promise(resolve => { resolveFn = resolve; });
63
59
 
64
- this.#asyncOps.push(done);
60
+ this.test.asyncOps.push(done);
65
61
 
66
62
  return () => { resolveFn(); };
67
63
  }
68
64
  async waitForAsyncOps() {
69
- return Promise.all(this.#asyncOps);
65
+ return Promise.all(this.test.asyncOps);
70
66
  }
71
67
  pushResult(resultInfo = {}) {
72
68
  this._incrementAssertionCount();
73
69
  if (!resultInfo.result) {
74
- throw new AssertionError({
70
+ throw new Assert.AssertionError({
75
71
  actual: resultInfo.actual,
76
72
  expected: resultInfo.expected,
77
73
  message: resultInfo.message || 'Custom assertion failed!',
@@ -84,7 +80,7 @@ export default class Assert {
84
80
  ok(state, message) {
85
81
  this._incrementAssertionCount();
86
82
  if (!state) {
87
- throw new AssertionError({
83
+ throw new Assert.AssertionError({
88
84
  actual: state,
89
85
  expected: true,
90
86
  message: message || `Expected argument to be truthy, it was: ${inspect(state)}`,
@@ -95,7 +91,7 @@ export default class Assert {
95
91
  notOk(state, message) {
96
92
  this._incrementAssertionCount();
97
93
  if (state) {
98
- throw new AssertionError({
94
+ throw new Assert.AssertionError({
99
95
  actual: state,
100
96
  expected: false,
101
97
  message: message || `Expected argument to be falsy, it was: ${inspect(state)}`,
@@ -106,7 +102,7 @@ export default class Assert {
106
102
  true(state, message) {
107
103
  this._incrementAssertionCount();
108
104
  if (state !== true) {
109
- throw new AssertionError({
105
+ throw new Assert.AssertionError({
110
106
  actual: state,
111
107
  expected: true,
112
108
  message: message || `Expected argument to be true, it was: ${inspect(state)}`,
@@ -117,9 +113,9 @@ export default class Assert {
117
113
  false(state, message) {
118
114
  this._incrementAssertionCount();
119
115
  if (state !== false) {
120
- throw new AssertionError({
116
+ throw new Assert.AssertionError({
121
117
  actual: state,
122
- expected: true,
118
+ expected: false,
123
119
  message: message || `Expected argument to be false, it was: ${inspect(state)}`,
124
120
  stackStartFn: this.false,
125
121
  });
@@ -128,7 +124,7 @@ export default class Assert {
128
124
  equal(actual, expected, message) {
129
125
  this._incrementAssertionCount();
130
126
  if (actual != expected) {
131
- throw new AssertionError({
127
+ throw new Assert.AssertionError({
132
128
  actual,
133
129
  expected,
134
130
  message: message || `Expected: ${defaultMessage(actual, 'should equal to:', expected)}`,
@@ -140,7 +136,7 @@ export default class Assert {
140
136
  notEqual(actual, expected, message) {
141
137
  this._incrementAssertionCount();
142
138
  if (actual == expected) {
143
- throw new AssertionError({
139
+ throw new Assert.AssertionError({
144
140
  actual,
145
141
  expected,
146
142
  operator: '!=',
@@ -153,8 +149,8 @@ export default class Assert {
153
149
  this._incrementAssertionCount();
154
150
  let targetActual = objectValues(actual);
155
151
  let targetExpected = objectValues(expected);
156
- if (!QUnit.equiv(targetActual, targetExpected)) {
157
- throw new AssertionError({
152
+ if (!Assert.QUnit.equiv(targetActual, targetExpected)) {
153
+ throw new Assert.AssertionError({
158
154
  actual: targetActual,
159
155
  expected: targetExpected,
160
156
  message: message || `Expected properties to be propEqual: ${defaultMessage(targetActual, 'should propEqual to:', targetExpected)}`,
@@ -166,8 +162,8 @@ export default class Assert {
166
162
  this._incrementAssertionCount();
167
163
  let targetActual = objectValues(actual);
168
164
  let targetExpected = objectValues(expected);
169
- if (QUnit.equiv(targetActual, targetExpected)) {
170
- throw new AssertionError({
165
+ if (Assert.QUnit.equiv(targetActual, targetExpected)) {
166
+ throw new Assert.AssertionError({
171
167
  actual: targetActual,
172
168
  expected: targetExpected,
173
169
  message: message || `Expected properties to NOT be propEqual: ${defaultMessage(targetActual, 'should notPropEqual to:', targetExpected)}`,
@@ -179,8 +175,8 @@ export default class Assert {
179
175
  this._incrementAssertionCount();
180
176
  let targetActual = objectValuesSubset(actual, expected);
181
177
  let targetExpected = objectValues(expected, false);
182
- if (!QUnit.equiv(targetActual, targetExpected)) {
183
- throw new AssertionError({
178
+ if (!Assert.QUnit.equiv(targetActual, targetExpected)) {
179
+ throw new Assert.AssertionError({
184
180
  actual: targetActual,
185
181
  expected: targetExpected,
186
182
  message: message || `propContains assertion fail on: ${defaultMessage(targetActual, 'should propContains to:', targetExpected)}`,
@@ -192,8 +188,8 @@ export default class Assert {
192
188
  this._incrementAssertionCount();
193
189
  let targetActual = objectValuesSubset(actual, expected);
194
190
  let targetExpected = objectValues(expected);
195
- if (QUnit.equiv(targetActual, targetExpected)) {
196
- throw new AssertionError({
191
+ if (Assert.QUnit.equiv(targetActual, targetExpected)) {
192
+ throw new Assert.AssertionError({
197
193
  actual: targetActual,
198
194
  expected: targetExpected,
199
195
  message: message || `notPropContains assertion fail on: ${defaultMessage(targetActual, 'should notPropContains of:', targetExpected)}`,
@@ -203,8 +199,8 @@ export default class Assert {
203
199
  }
204
200
  deepEqual(actual, expected, message) {
205
201
  this._incrementAssertionCount();
206
- if (!QUnit.equiv(actual, expected)) {
207
- throw new AssertionError({
202
+ if (!Assert.QUnit.equiv(actual, expected)) {
203
+ throw new Assert.AssertionError({
208
204
  actual,
209
205
  expected,
210
206
  message: message || `Expected values to be deepEqual: ${defaultMessage(actual, 'should deepEqual to:', expected)}`,
@@ -215,8 +211,8 @@ export default class Assert {
215
211
  }
216
212
  notDeepEqual(actual, expected, message) {
217
213
  this._incrementAssertionCount();
218
- if (QUnit.equiv(actual, expected)) {
219
- throw new AssertionError({
214
+ if (Assert.QUnit.equiv(actual, expected)) {
215
+ throw new Assert.AssertionError({
220
216
  actual,
221
217
  expected,
222
218
  message: message || `Expected values to be NOT deepEqual: ${defaultMessage(actual, 'should notDeepEqual to:', expected)}`,
@@ -228,7 +224,7 @@ export default class Assert {
228
224
  strictEqual(actual, expected, message) {
229
225
  this._incrementAssertionCount();
230
226
  if (actual !== expected) {
231
- throw new AssertionError({
227
+ throw new Assert.AssertionError({
232
228
  actual,
233
229
  expected,
234
230
  message: message || `Expected: ${defaultMessage(actual, 'is strictEqual to:', expected)}`,
@@ -240,7 +236,7 @@ export default class Assert {
240
236
  notStrictEqual(actual, expected, message) {
241
237
  this._incrementAssertionCount();
242
238
  if (actual === expected) {
243
- throw new AssertionError({
239
+ throw new Assert.AssertionError({
244
240
  actual,
245
241
  expected,
246
242
  message: message || `Expected: ${defaultMessage(actual, 'is notStrictEqual to:', expected)}`,
@@ -253,7 +249,7 @@ export default class Assert {
253
249
  this?._incrementAssertionCount();
254
250
  let [expected, message] = validateExpectedExceptionArgs(expectedInput, assertionMessage, 'rejects');
255
251
  if (typeof blockFn !== 'function') {
256
- throw new AssertionError({
252
+ throw new Assert.AssertionError({
257
253
  actual: blockFn,
258
254
  expected: Function,
259
255
  message: 'The value provided to `assert.throws` was not a function.',
@@ -266,7 +262,7 @@ export default class Assert {
266
262
  } catch (error) {
267
263
  let validation = validateException(error, expected, message);
268
264
  if (validation.result === false) {
269
- throw new AssertionError({
265
+ throw new Assert.AssertionError({
270
266
  actual: validation.result,
271
267
  expected: validation.expected,
272
268
  message: validation.message,
@@ -277,7 +273,7 @@ export default class Assert {
277
273
  return;
278
274
  }
279
275
 
280
- throw new AssertionError({
276
+ throw new Assert.AssertionError({
281
277
  actual: blockFn,
282
278
  expected: expected,
283
279
  message: 'Function passed to `assert.throws` did not throw an exception!',
@@ -289,7 +285,7 @@ export default class Assert {
289
285
  let [expected, message] = validateExpectedExceptionArgs(expectedInput, assertionMessage, 'rejects');
290
286
  let then = promise && promise.then;
291
287
  if (typeof then !== 'function') {
292
- throw new AssertionError({
288
+ throw new Assert.AssertionError({
293
289
  actual: promise,
294
290
  expected: expected,
295
291
  message: 'The value provided to `assert.rejects` was not a promise!',
@@ -299,7 +295,7 @@ export default class Assert {
299
295
 
300
296
  try {
301
297
  await promise;
302
- throw new AssertionError({
298
+ throw new Assert.AssertionError({
303
299
  actual: promise,
304
300
  expected: expected,
305
301
  message: 'The promise returned by the `assert.rejects` callback did not reject!',
@@ -308,7 +304,7 @@ export default class Assert {
308
304
  } catch (error) {
309
305
  let validation = validateException(error, expected, message);
310
306
  if (validation.result === false) {
311
- throw new AssertionError({
307
+ throw new Assert.AssertionError({
312
308
  actual: validation.result,
313
309
  expected: validation.expected,
314
310
  message: validation.message,
@@ -0,0 +1,29 @@
1
+ import TestContext from './test-context.js';
2
+
3
+ export default class ModuleContext {
4
+ static Assert;
5
+ static currentModuleChain = [];
6
+
7
+ static get lastModule() {
8
+ return this.currentModuleChain[this.currentModuleChain.length - 1];
9
+ }
10
+
11
+ context = new TestContext();
12
+
13
+ moduleChain = [];
14
+ beforeEachHooks = [];
15
+ afterEachHooks = [];
16
+ tests = [];
17
+
18
+ constructor(name) {
19
+ let parentModule = ModuleContext.currentModuleChain[ModuleContext.currentModuleChain.length - 1];
20
+
21
+ ModuleContext.currentModuleChain.push(this);
22
+
23
+ this.moduleChain = ModuleContext.currentModuleChain.slice(0);
24
+ this.name = parentModule ? `${parentModule.name} > ${name}` : name;
25
+ this.assert = new ModuleContext.Assert(this);
26
+
27
+ return Object.freeze(this);
28
+ }
29
+ }