@everyonesoftware/common 4.0.0 → 6.0.0

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.
@@ -0,0 +1,845 @@
1
+ import {
2
+ CurrentProcess,
3
+ List,
4
+ NodeJSCharacterWriteStream,
5
+ PreCondition,
6
+ PromiseAsyncResult,
7
+ ToStringFunctions,
8
+ __export,
9
+ andList,
10
+ getName,
11
+ getParameterCount,
12
+ isBoolean,
13
+ isFunction,
14
+ isJavascriptIterable,
15
+ isPromise,
16
+ isString,
17
+ isUndefinedOrNull,
18
+ join
19
+ } from "./chunk-5Z677JON.js";
20
+
21
+ // tests/test.ts
22
+ var Test = class _Test {
23
+ /**
24
+ * Assert that the provided value is undefined;
25
+ * @param value The value to check.
26
+ */
27
+ assertUndefined(value) {
28
+ _Test.assertUndefined(this, value);
29
+ }
30
+ /**
31
+ * Assert that the provided value is undefined.
32
+ * @param test The current {@link Test}.
33
+ * @param value The value to check.
34
+ */
35
+ static assertUndefined(test2, value) {
36
+ test2.assertSame(value, void 0);
37
+ }
38
+ /**
39
+ * Assert that the provided value is not undefined;
40
+ * @param value The value to check.
41
+ */
42
+ assertNotUndefined(value) {
43
+ _Test.assertNotUndefined(this, value);
44
+ }
45
+ /**
46
+ * Assert that the provided value is not undefined.
47
+ * @param test The current {@link Test}.
48
+ * @param value The value to check.
49
+ */
50
+ static assertNotUndefined(test2, value) {
51
+ test2.assertNotSame(value, void 0);
52
+ }
53
+ /**
54
+ * Assert that the provided value is null.
55
+ * @param value The value to check.
56
+ */
57
+ assertNull(value) {
58
+ _Test.assertNull(this, value);
59
+ }
60
+ /**
61
+ * Assert that the provided value is null.
62
+ * @param value The value to check.
63
+ */
64
+ static assertNull(test2, value) {
65
+ test2.assertSame(value, null);
66
+ }
67
+ /**
68
+ * Assert that the provided value is not null.
69
+ * @param value The value to check.
70
+ */
71
+ assertNotNull(value) {
72
+ _Test.assertNull(this, value);
73
+ }
74
+ /**
75
+ * Assert that the provided value is not null.
76
+ * @param value The value to check.
77
+ */
78
+ static assertNotNull(test2, value) {
79
+ test2.assertNotSame(value, null);
80
+ }
81
+ /**
82
+ * Assert that the provided value is not undefined and not null.
83
+ * @param value The value to check.
84
+ */
85
+ assertNotUndefinedAndNotNull(value) {
86
+ _Test.assertNotUndefinedAndNotNull(this, value);
87
+ }
88
+ /**
89
+ * Assert that the provided value is not undefined and not null.
90
+ * @param value The value to check.
91
+ */
92
+ static assertNotUndefinedAndNotNull(test2, value) {
93
+ test2.assertNotSame(value, null);
94
+ test2.assertNotSame(value, void 0);
95
+ }
96
+ /**
97
+ * Assert that the provided value is false.
98
+ * @param value The value to check.
99
+ */
100
+ assertFalse(value) {
101
+ _Test.assertFalse(this, value);
102
+ }
103
+ /**
104
+ * Assert that the provided value is false.
105
+ * @param value The value to check.
106
+ */
107
+ static assertFalse(test2, value) {
108
+ PreCondition.assertNotUndefinedAndNotNull(test2, "test");
109
+ test2.assertSame(value, false);
110
+ }
111
+ /**
112
+ * Assert that the provided value is true.
113
+ * @param value The value to check.
114
+ */
115
+ assertTrue(value) {
116
+ _Test.assertTrue(this, value);
117
+ }
118
+ /**
119
+ * Assert that the provided value is true.
120
+ * @param value The value to check.
121
+ */
122
+ static assertTrue(test2, value) {
123
+ PreCondition.assertNotUndefinedAndNotNull(test2, "test");
124
+ test2.assertSame(value, true);
125
+ }
126
+ /**
127
+ * Assert that the provided value is an instance of the provided {@link Type}.
128
+ * @param value The value to check.
129
+ * @param type The {@link Type} to check.
130
+ * @param expression The expression that produced the value.
131
+ * @param message An optional error message.
132
+ */
133
+ assertInstanceOf(value, type, typeCheck) {
134
+ return _Test.assertInstanceOf(this, value, type, typeCheck);
135
+ }
136
+ /**
137
+ * Assert that the provided value is an instance of the provided {@link Type}.
138
+ * @param value The value to check.
139
+ * @param type The {@link Type} to check.
140
+ * @param expression The expression that produced the value.
141
+ * @param message An optional error message.
142
+ */
143
+ static assertInstanceOf(test2, value, type, typeCheck) {
144
+ PreCondition.assertNotUndefinedAndNotNull(type, "type");
145
+ if (isUndefinedOrNull(typeCheck)) {
146
+ typeCheck = ((value2) => value2 instanceof type);
147
+ }
148
+ if (!typeCheck(value)) {
149
+ test2.fail(`Expected value to be of type ${type.name} but found ${value} instead.`);
150
+ }
151
+ }
152
+ };
153
+
154
+ // tests/assertTest.ts
155
+ import * as assert from "assert";
156
+ var AssertTest = class _AssertTest {
157
+ name;
158
+ constructor(name) {
159
+ this.name = name;
160
+ }
161
+ /**
162
+ * Create a new {@link AssertTest} object.
163
+ */
164
+ static create(name) {
165
+ return new _AssertTest(name);
166
+ }
167
+ fail(message) {
168
+ PreCondition.assertNotEmpty(message, "message");
169
+ assert.fail(message);
170
+ }
171
+ assertUndefined(value) {
172
+ Test.assertUndefined(this, value);
173
+ }
174
+ assertNotUndefined(value) {
175
+ Test.assertNotUndefined(this, value);
176
+ }
177
+ assertNull(value) {
178
+ Test.assertNull(this, value);
179
+ }
180
+ assertNotNull(value) {
181
+ Test.assertNotNull(this, value);
182
+ }
183
+ assertNotUndefinedAndNotNull(value) {
184
+ Test.assertNotUndefinedAndNotNull(this, value);
185
+ }
186
+ assertSame(left, right) {
187
+ assert.strictEqual(left, right);
188
+ }
189
+ assertNotSame(left, right) {
190
+ assert.notStrictEqual(left, right);
191
+ }
192
+ assertEqual(left, right, message) {
193
+ assert.deepStrictEqual(left, right, message);
194
+ }
195
+ assertNotEqual(left, right) {
196
+ assert.notDeepStrictEqual(left, right);
197
+ }
198
+ assertFalse(value) {
199
+ Test.assertFalse(this, value);
200
+ }
201
+ assertTrue(value) {
202
+ Test.assertTrue(this, value);
203
+ }
204
+ assertThrows(action, expectedError) {
205
+ if (!isFunction(action)) {
206
+ const syncResult = action;
207
+ action = () => {
208
+ syncResult.await();
209
+ };
210
+ }
211
+ assert.throws(action, expectedError);
212
+ }
213
+ assertThrowsAsync(action, expectedError) {
214
+ const promiseOrAsyncAction = isFunction(action) ? async () => await action() : action;
215
+ return PromiseAsyncResult.create(assert.rejects(promiseOrAsyncAction, expectedError));
216
+ }
217
+ assertInstanceOf(value, type, typeCheck) {
218
+ Test.assertInstanceOf(this, value, type, typeCheck);
219
+ }
220
+ };
221
+
222
+ // tests/assertTestTests.ts
223
+ var assertTestTests_exports = {};
224
+ __export(assertTestTests_exports, {
225
+ test: () => test
226
+ });
227
+ import { AssertionError } from "assert";
228
+ function test(runner) {
229
+ runner.testFile("assertTest.ts", () => {
230
+ runner.testType("AssertTest", () => {
231
+ runner.testFunction("assertThrows()", () => {
232
+ runner.test("with throwing action", (test2) => {
233
+ const at = AssertTest.create("fake-test-name");
234
+ at.assertThrows(() => {
235
+ throw new Error("abc");
236
+ }, new Error("abc"));
237
+ });
238
+ runner.test("with non-throwing action", (test2) => {
239
+ const at = AssertTest.create("fake-test-name");
240
+ test2.assertThrows(
241
+ () => at.assertThrows(() => {
242
+ }, new Error("oops")),
243
+ new AssertionError({
244
+ message: "Missing expected exception (Error).",
245
+ operator: "throws",
246
+ expected: new Error("oops")
247
+ })
248
+ );
249
+ });
250
+ });
251
+ runner.testFunction("assertThrowsAsync()", () => {
252
+ runner.test("with throwing sync action", async (test2) => {
253
+ const at = AssertTest.create("fake-test-name");
254
+ await at.assertThrowsAsync(() => {
255
+ throw new Error("abc");
256
+ }, new Error("abc"));
257
+ });
258
+ runner.test("with throwing async action", async (test2) => {
259
+ const at = AssertTest.create("fake-test-name");
260
+ await at.assertThrowsAsync(async () => {
261
+ throw new Error("abc");
262
+ }, new Error("abc"));
263
+ });
264
+ runner.test("with rejected Promise", async (test2) => {
265
+ const at = AssertTest.create("fake-test-name");
266
+ await at.assertThrowsAsync(Promise.reject(new Error("abc")), new Error("abc"));
267
+ });
268
+ runner.test("with throwing action that returns a rejected Promise", async (test2) => {
269
+ const at = AssertTest.create("fake-test-name");
270
+ await at.assertThrowsAsync(() => Promise.reject(new Error("abc")), new Error("abc"));
271
+ });
272
+ runner.test("with non-throwing async action", async (test2) => {
273
+ const at = AssertTest.create("fake-test-name");
274
+ await test2.assertThrowsAsync(
275
+ async () => await at.assertThrowsAsync(async () => {
276
+ }, new Error("oops")),
277
+ new AssertionError({
278
+ message: "Missing expected rejection (Error).",
279
+ operator: "rejects",
280
+ expected: new Error("oops")
281
+ })
282
+ );
283
+ });
284
+ });
285
+ });
286
+ });
287
+ }
288
+
289
+ // tests/basicTestSkip.ts
290
+ var BasicTestSkip = class _BasicTestSkip {
291
+ shouldSkip;
292
+ message;
293
+ constructor(shouldSkip, message) {
294
+ PreCondition.assertNotUndefinedAndNotNull(message, "message");
295
+ this.shouldSkip = shouldSkip;
296
+ this.message = message;
297
+ }
298
+ /**
299
+ * Create a new {@link TestSkip} with the provided properties.
300
+ * @param shouldSkip Whether the tests associated with the new {@link TestSkip}
301
+ * should be skipped.
302
+ * @param message The message that explains why the tests associated with this {@link TestSkip}
303
+ * should be skipped.
304
+ */
305
+ static create(shouldSkip, message) {
306
+ if (shouldSkip === void 0 || shouldSkip === null) {
307
+ shouldSkip = true;
308
+ }
309
+ if (message === void 0 || message === null) {
310
+ message = "";
311
+ }
312
+ return new _BasicTestSkip(shouldSkip, message);
313
+ }
314
+ getShouldSkip() {
315
+ return this.shouldSkip;
316
+ }
317
+ getMessage() {
318
+ return this.message;
319
+ }
320
+ };
321
+
322
+ // tests/failedTest.ts
323
+ var FailedTest = class _FailedTest {
324
+ fullTestNameParts;
325
+ error;
326
+ constructor(fullTestNameParts, error) {
327
+ PreCondition.assertNotEmpty(fullTestNameParts, "fullTestName");
328
+ PreCondition.assertNotUndefinedAndNotNull(error, "error");
329
+ this.fullTestNameParts = fullTestNameParts;
330
+ this.error = error;
331
+ }
332
+ static create(fullTestNameParts, error) {
333
+ return new _FailedTest(fullTestNameParts, error);
334
+ }
335
+ getFullTestNameParts() {
336
+ return this.fullTestNameParts;
337
+ }
338
+ getFullTestName() {
339
+ return join(" ", this.fullTestNameParts);
340
+ }
341
+ getError() {
342
+ return this.error;
343
+ }
344
+ getErrorMessage() {
345
+ return this.error instanceof Error && this.error.stack ? this.error.stack : `${this.error}`;
346
+ }
347
+ };
348
+
349
+ // tests/skippedTest.ts
350
+ var SkippedTest = class _SkippedTest {
351
+ skip;
352
+ fullTestNameParts;
353
+ constructor(skip, fullTestNameParts) {
354
+ PreCondition.assertNotUndefinedAndNotNull(skip, "skip");
355
+ PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
356
+ this.skip = skip;
357
+ this.fullTestNameParts = fullTestNameParts;
358
+ }
359
+ static create(skip, fullTestNameParts) {
360
+ return new _SkippedTest(skip, fullTestNameParts);
361
+ }
362
+ getSkipMessage() {
363
+ return this.skip.getMessage();
364
+ }
365
+ getFullTestNameParts() {
366
+ return this.fullTestNameParts;
367
+ }
368
+ getFullTestName() {
369
+ return join(" ", this.fullTestNameParts);
370
+ }
371
+ };
372
+
373
+ // tests/testAction.ts
374
+ var TestAction = class _TestAction {
375
+ parent;
376
+ name;
377
+ skip;
378
+ action;
379
+ constructor(parent, name, skip, action) {
380
+ PreCondition.assertNotUndefinedAndNotNull(name, "name");
381
+ PreCondition.assertNotUndefinedAndNotNull(action, "action");
382
+ this.parent = parent;
383
+ this.name = name;
384
+ this.skip = skip;
385
+ this.action = action;
386
+ }
387
+ static create(parent, name, skip, action) {
388
+ return new _TestAction(parent, name, skip, action);
389
+ }
390
+ getParent() {
391
+ return this.parent;
392
+ }
393
+ getName() {
394
+ return this.name;
395
+ }
396
+ getFullNameParts() {
397
+ const result = List.create();
398
+ if (this.parent) {
399
+ result.addAll(this.parent.getFullNameParts());
400
+ }
401
+ result.add(this.getName());
402
+ return result;
403
+ }
404
+ getFullName() {
405
+ return join(" ", this.getFullNameParts());
406
+ }
407
+ getSkip() {
408
+ return this.skip || this.parent?.getSkip();
409
+ }
410
+ shouldSkip() {
411
+ return !!this.getSkip()?.getShouldSkip();
412
+ }
413
+ getAction() {
414
+ return this.action;
415
+ }
416
+ runAsync() {
417
+ return this.action();
418
+ }
419
+ };
420
+
421
+ // tests/testSkip.ts
422
+ var TestSkip = class {
423
+ constructor() {
424
+ }
425
+ /**
426
+ * Create a new {@link TestSkip} with the provided properties.
427
+ * @param shouldSkip Whether the tests associated with the new {@link TestSkip}
428
+ * should be skipped.
429
+ * @param message The message that explains why the tests associated with this {@link TestSkip}
430
+ * should be skipped.
431
+ */
432
+ static create(shouldSkip, message) {
433
+ return BasicTestSkip.create(shouldSkip, message);
434
+ }
435
+ };
436
+
437
+ // tests/testRunner.ts
438
+ var TestRunner = class _TestRunner {
439
+ /**
440
+ * Get a {@link string} that concatenates the {@link string} representation of each
441
+ * of the provided values into an "and-list".
442
+ * @param values The values to concatenate.
443
+ */
444
+ andList(values) {
445
+ return _TestRunner.andList(this, values);
446
+ }
447
+ /**
448
+ * Get a {@link string} that concatenates the {@link string} representation of each
449
+ * of the provided values into an "and-list".
450
+ * @param values The values to concatenate.
451
+ */
452
+ static andList(runner, values) {
453
+ PreCondition.assertNotUndefinedAndNotNull(runner, "runner");
454
+ PreCondition.assertNotUndefinedAndNotNull(values, "values");
455
+ return andList(values.map((value) => runner.toString(value)));
456
+ }
457
+ /**
458
+ * Get the {@link string} representation of the provided value.
459
+ * @param value The value to get the {@link string} representation of.
460
+ */
461
+ toString(value) {
462
+ return _TestRunner.toString(this, value);
463
+ }
464
+ /**
465
+ * Get the {@link string} representation of the provided value.
466
+ * @param value The value to get the {@link string} representation of.
467
+ */
468
+ static toString(_runner, value) {
469
+ const toStringFunctions = ToStringFunctions.create();
470
+ return toStringFunctions.toString(value);
471
+ }
472
+ skip(messageOrShouldSkip, message) {
473
+ let shouldSkip;
474
+ if (!isBoolean(messageOrShouldSkip)) {
475
+ shouldSkip = true;
476
+ message = messageOrShouldSkip;
477
+ } else {
478
+ shouldSkip = messageOrShouldSkip;
479
+ }
480
+ return _TestRunner.skip(this, shouldSkip, message);
481
+ }
482
+ /**
483
+ * Create a {@link TestSkip} object that will prevent tests from being run.
484
+ * @param shouldSkip Whether these tests should be skipped.
485
+ * @param message The message that explains why the tests are being skipped.
486
+ */
487
+ static skip(_runner, shouldSkip, message) {
488
+ return TestSkip.create(shouldSkip, message);
489
+ }
490
+ static runTestAction(runner, name, skip, testAction) {
491
+ if (getParameterCount(testAction) === 0) {
492
+ runner.testGroup(name, skip, testAction);
493
+ } else {
494
+ runner.test(name, skip, testAction);
495
+ }
496
+ }
497
+ testFile(fileName, skipOrTestAction, testAction) {
498
+ _TestRunner.testFile(this, fileName, skipOrTestAction, testAction);
499
+ }
500
+ /**
501
+ * Create a test group that will test the provided file.
502
+ * @param runner The {@link TestRunner} that will run the tests.
503
+ * @param fileName The name of the file that is being tested.
504
+ * @param testAction The action that will run the tests.
505
+ */
506
+ static testFile(runner, fileName, skipOrTestAction, testAction) {
507
+ PreCondition.assertNotUndefinedAndNotNull(runner, "runner");
508
+ PreCondition.assertNotUndefinedAndNotNull(fileName, "fileName");
509
+ PreCondition.assertNotEmpty(fileName, "fileName");
510
+ let skip;
511
+ if (isFunction(skipOrTestAction)) {
512
+ PreCondition.assertUndefined(testAction, "testAction");
513
+ skip = void 0;
514
+ testAction = skipOrTestAction;
515
+ } else {
516
+ skip = skipOrTestAction;
517
+ }
518
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
519
+ _TestRunner.runTestAction(runner, fileName, skip, testAction);
520
+ }
521
+ testType(typeNameOrType, skipOrTestAction, testAction) {
522
+ _TestRunner.testType(this, typeNameOrType, skipOrTestAction, testAction);
523
+ }
524
+ /**
525
+ * Create a test group that will test the provided type.
526
+ * @param runner The {@link TestRunner} that will run the tests.
527
+ * @param type The {@link Type} or name of the type that is being tested.
528
+ * @param testAction The action that will run the tests.
529
+ */
530
+ static testType(runner, typeNameOrType, skipOrTestAction, testAction) {
531
+ PreCondition.assertNotUndefinedAndNotNull(runner, "runner");
532
+ PreCondition.assertNotUndefinedAndNotNull(typeNameOrType, "typeNameOrType");
533
+ let typeName;
534
+ if (isString(typeNameOrType)) {
535
+ typeName = typeNameOrType;
536
+ } else {
537
+ typeName = getName(typeNameOrType);
538
+ }
539
+ PreCondition.assertNotEmpty(typeName, "typeName");
540
+ let skip;
541
+ if (isFunction(skipOrTestAction)) {
542
+ PreCondition.assertUndefined(testAction, "testAction");
543
+ skip = void 0;
544
+ testAction = skipOrTestAction;
545
+ } else {
546
+ skip = skipOrTestAction;
547
+ }
548
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
549
+ _TestRunner.runTestAction(runner, typeName, skip, testAction);
550
+ }
551
+ testFunction(functionSignature, skipOrTestAction, testAction) {
552
+ _TestRunner.testFunction(this, functionSignature, skipOrTestAction, testAction);
553
+ }
554
+ /**
555
+ * Create a test group that will test the provided function.
556
+ * @param runner The {@link TestRunner} that will run the tests.
557
+ * @param functionSignature The signature of the function that is being tested.
558
+ * @param testAction The action that will run the tests.
559
+ */
560
+ static testFunction(runner, functionSignature, skipOrTestAction, testAction) {
561
+ PreCondition.assertNotUndefinedAndNotNull(runner, "runner");
562
+ PreCondition.assertNotEmpty(functionSignature, "functionSignature");
563
+ let skip;
564
+ if (isFunction(skipOrTestAction)) {
565
+ PreCondition.assertUndefined(testAction, "testAction");
566
+ skip = void 0;
567
+ testAction = skipOrTestAction;
568
+ } else {
569
+ skip = skipOrTestAction;
570
+ }
571
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
572
+ _TestRunner.runTestAction(runner, functionSignature, skip, testAction);
573
+ }
574
+ };
575
+
576
+ // tests/consoleTestRunner.ts
577
+ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
578
+ writeStream;
579
+ pendingActions;
580
+ pendingActionsInsertIndex;
581
+ currentTestAction;
582
+ currentTest;
583
+ passedTestCount;
584
+ skippedTests;
585
+ testFailures;
586
+ constructor() {
587
+ super();
588
+ this.writeStream = NodeJSCharacterWriteStream.create(process.stdout);
589
+ this.pendingActions = List.create();
590
+ this.pendingActionsInsertIndex = 0;
591
+ this.passedTestCount = 0;
592
+ this.skippedTests = List.create();
593
+ this.testFailures = List.create();
594
+ }
595
+ static create() {
596
+ return new _ConsoleTestRunner();
597
+ }
598
+ static run(testFunctionOrTestFunctions) {
599
+ let testFunction;
600
+ if (isFunction(testFunctionOrTestFunctions)) {
601
+ testFunction = testFunctionOrTestFunctions;
602
+ } else if (!isJavascriptIterable(testFunctionOrTestFunctions)) {
603
+ testFunction = testFunctionOrTestFunctions.test;
604
+ } else {
605
+ const testFunctions = testFunctionOrTestFunctions;
606
+ testFunction = async (runner) => {
607
+ for (const testFunction2 of testFunctions) {
608
+ if (isFunction(testFunction2)) {
609
+ await testFunction2(runner);
610
+ } else {
611
+ await testFunction2.test(runner);
612
+ }
613
+ }
614
+ };
615
+ }
616
+ return CurrentProcess.run(async (currentProcess) => {
617
+ const runner = _ConsoleTestRunner.create().setWriteStream(currentProcess.getOutputWriteStream());
618
+ await testFunction(runner);
619
+ await runner.runAsync();
620
+ await runner.printSummary();
621
+ });
622
+ }
623
+ setWriteStream(writeStream) {
624
+ PreCondition.assertNotUndefinedAndNotNull(writeStream, "writeStream");
625
+ this.writeStream = writeStream;
626
+ return this;
627
+ }
628
+ /**
629
+ * Get the number of {@link TestAction}s that have yet to be executed.
630
+ */
631
+ getPendingTestActionsCount() {
632
+ return this.pendingActions.getCount().await();
633
+ }
634
+ /**
635
+ * Get the index in the pending-{@link TestAction} stack that new {@link TestAction}s will be
636
+ * inserted at.
637
+ */
638
+ getPendingTestActionsInsertIndex() {
639
+ return this.pendingActionsInsertIndex;
640
+ }
641
+ /**
642
+ * Get the number of tests that have been skipped.
643
+ */
644
+ getSkippedTestCount() {
645
+ return this.skippedTests.getCount().await();
646
+ }
647
+ getSkippedTests() {
648
+ return this.skippedTests;
649
+ }
650
+ /**
651
+ * Get the number of tests that have passed.
652
+ */
653
+ getPassedTestCount() {
654
+ return this.passedTestCount;
655
+ }
656
+ getFailedTestCount() {
657
+ return this.testFailures.getCount().await();
658
+ }
659
+ getFailedTests() {
660
+ return this.testFailures;
661
+ }
662
+ /**
663
+ * Get the {@link TestAction} that is currently executing or undefined if no {@link TestAction}
664
+ * is executing.
665
+ */
666
+ getCurrentTestAction() {
667
+ return this.currentTestAction;
668
+ }
669
+ getCurrentTest() {
670
+ return this.currentTest;
671
+ }
672
+ assertNoCurrentTest() {
673
+ if (this.currentTest !== void 0) {
674
+ this.currentTest.fail("Can't start a new test group or a new test while running a test.");
675
+ }
676
+ }
677
+ beforeTest(fullTestNameParts) {
678
+ return PromiseAsyncResult.create(async () => {
679
+ await this.writeStream.writeString(join(" ", fullTestNameParts));
680
+ });
681
+ }
682
+ afterPassedTest() {
683
+ return PromiseAsyncResult.create(async () => {
684
+ await this.writeStream.writeLine(" - Passed");
685
+ this.passedTestCount++;
686
+ });
687
+ }
688
+ afterSkippedTest(fullTestNameParts, skip) {
689
+ PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
690
+ PreCondition.assertNotUndefinedAndNotNull(skip, "skip");
691
+ return PromiseAsyncResult.create(async () => {
692
+ this.skippedTests.add(SkippedTest.create(skip, fullTestNameParts));
693
+ await this.writeStream.writeLine(" - Skipped");
694
+ });
695
+ }
696
+ afterFailedTest(fullTestNameParts, error) {
697
+ PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
698
+ PreCondition.assertNotUndefinedAndNotNull(error, "error");
699
+ return PromiseAsyncResult.create(async () => {
700
+ this.testFailures.add(FailedTest.create(fullTestNameParts, error));
701
+ await this.writeStream.writeLine(" - Failed");
702
+ });
703
+ }
704
+ testGroup(testGroupName, skipOrTestAction, testAction) {
705
+ PreCondition.assertNotUndefinedAndNotNull(testGroupName, "testGroupName");
706
+ PreCondition.assertNotEmpty(testGroupName, "testGroupName");
707
+ let skip;
708
+ if (isFunction(skipOrTestAction)) {
709
+ PreCondition.assertUndefined(testAction, "testAction");
710
+ skip = void 0;
711
+ testAction = skipOrTestAction;
712
+ } else {
713
+ skip = skipOrTestAction;
714
+ }
715
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
716
+ this.assertNoCurrentTest();
717
+ this.pendingActions.insert(
718
+ this.pendingActionsInsertIndex,
719
+ TestAction.create(
720
+ this.getCurrentTestAction(),
721
+ testGroupName,
722
+ skip,
723
+ async () => {
724
+ const previousTestActionInsertIndex = this.pendingActionsInsertIndex;
725
+ this.pendingActionsInsertIndex = this.pendingActions.getCount().await();
726
+ const currentTestAction = this.getCurrentTestAction();
727
+ try {
728
+ await testAction();
729
+ } catch (error) {
730
+ await this.afterFailedTest(currentTestAction.getFullNameParts(), error);
731
+ } finally {
732
+ this.pendingActionsInsertIndex = previousTestActionInsertIndex;
733
+ }
734
+ }
735
+ )
736
+ );
737
+ }
738
+ test(testName, skipOrTestAction, testAction) {
739
+ PreCondition.assertNotUndefinedAndNotNull(testName, "testName");
740
+ PreCondition.assertNotEmpty(testName, "testName");
741
+ let skip;
742
+ if (isFunction(skipOrTestAction)) {
743
+ PreCondition.assertUndefined(testAction, "testAction");
744
+ skip = void 0;
745
+ testAction = skipOrTestAction;
746
+ } else {
747
+ skip = skipOrTestAction;
748
+ }
749
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
750
+ this.assertNoCurrentTest();
751
+ this.pendingActions.insert(
752
+ this.pendingActionsInsertIndex,
753
+ TestAction.create(
754
+ this.getCurrentTestAction(),
755
+ testName,
756
+ skip,
757
+ async () => {
758
+ const currentTestAction = this.getCurrentTestAction();
759
+ try {
760
+ await this.beforeTest(currentTestAction.getFullNameParts());
761
+ if (currentTestAction.shouldSkip()) {
762
+ await this.afterSkippedTest(currentTestAction.getFullNameParts(), currentTestAction.getSkip());
763
+ } else {
764
+ this.currentTest = AssertTest.create(testName);
765
+ try {
766
+ await testAction(this.currentTest);
767
+ await this.afterPassedTest();
768
+ } finally {
769
+ this.currentTest = void 0;
770
+ }
771
+ }
772
+ } catch (error) {
773
+ await this.afterFailedTest(currentTestAction.getFullNameParts(), error);
774
+ }
775
+ }
776
+ )
777
+ );
778
+ }
779
+ async runAsync() {
780
+ while (this.pendingActions.any().await()) {
781
+ this.currentTestAction = this.pendingActions.removeLast().await();
782
+ try {
783
+ const result = this.currentTestAction.runAsync();
784
+ if (isPromise(result)) {
785
+ await result;
786
+ }
787
+ } finally {
788
+ this.currentTestAction = void 0;
789
+ }
790
+ }
791
+ }
792
+ printSummary() {
793
+ return PromiseAsyncResult.create(async () => {
794
+ await this.writeStream.writeLine();
795
+ const skippedTests = this.getSkippedTests();
796
+ if (await skippedTests.any()) {
797
+ await this.writeStream.writeLine(`Skipped Tests:`);
798
+ let counter = 0;
799
+ for (const skippedTest of skippedTests) {
800
+ await this.writeStream.writeLine(`${++counter}) ${skippedTest.getFullTestName()}`);
801
+ const skipMessage = skippedTest.getSkipMessage();
802
+ if (skipMessage) {
803
+ await this.writeStream.writeLine(` ${skipMessage}`);
804
+ }
805
+ }
806
+ await this.writeStream.writeLine();
807
+ }
808
+ const failedTests = this.getFailedTests();
809
+ if (await failedTests.any()) {
810
+ await this.writeStream.writeLine("Failed Tests:");
811
+ let counter = 0;
812
+ for (const failedTest of failedTests) {
813
+ await this.writeStream.writeLine(`${++counter}) ${failedTest.getFullTestName()}`);
814
+ await this.writeStream.writeLine(` ${failedTest.getErrorMessage()}`);
815
+ await this.writeStream.writeLine();
816
+ }
817
+ }
818
+ const passedTestCount = this.getPassedTestCount();
819
+ if (passedTestCount > 0) {
820
+ await this.writeStream.writeLine(`Passed: ${passedTestCount}`);
821
+ }
822
+ if (await skippedTests.any()) {
823
+ await this.writeStream.writeLine(`Skipped: ${skippedTests.getCount().await()}`);
824
+ }
825
+ if (await failedTests.any()) {
826
+ await this.writeStream.writeLine(`Failed: ${failedTests.getCount().await()}`);
827
+ }
828
+ });
829
+ }
830
+ };
831
+
832
+ export {
833
+ Test,
834
+ AssertTest,
835
+ test,
836
+ assertTestTests_exports,
837
+ BasicTestSkip,
838
+ FailedTest,
839
+ SkippedTest,
840
+ TestAction,
841
+ TestSkip,
842
+ TestRunner,
843
+ ConsoleTestRunner
844
+ };
845
+ //# sourceMappingURL=chunk-CHBOMCYM.js.map