@everyonesoftware/common 6.0.0 → 7.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.
@@ -1,9 +1,16 @@
1
1
  import {
2
+ ANSIStyles,
3
+ AsyncResult,
2
4
  CurrentProcess,
5
+ IndentedCharacterWriteStream,
6
+ Iterable,
3
7
  List,
8
+ Map,
4
9
  NodeJSCharacterWriteStream,
10
+ NotFoundError,
5
11
  PreCondition,
6
12
  PromiseAsyncResult,
13
+ Stack,
7
14
  ToStringFunctions,
8
15
  __export,
9
16
  andList,
@@ -12,11 +19,10 @@ import {
12
19
  isBoolean,
13
20
  isFunction,
14
21
  isJavascriptIterable,
15
- isPromise,
16
22
  isString,
17
23
  isUndefinedOrNull,
18
24
  join
19
- } from "./chunk-5Z677JON.js";
25
+ } from "./chunk-MMAX3IZF.js";
20
26
 
21
27
  // tests/test.ts
22
28
  var Test = class _Test {
@@ -94,16 +100,23 @@ var Test = class _Test {
94
100
  test2.assertNotSame(value, void 0);
95
101
  }
96
102
  /**
97
- * Assert that the provided value is false.
103
+ * Assert that the provided collection is not undefined, not null, and not empty.
98
104
  * @param value The value to check.
99
105
  */
100
- assertFalse(value) {
101
- _Test.assertFalse(this, value);
106
+ assertNotEmpty(value) {
107
+ _Test.assertNotEmpty(this, value);
108
+ }
109
+ static assertNotEmpty(test2, value) {
110
+ test2.assertNotUndefinedAndNotNull(value);
111
+ test2.assertTrue(Iterable.any(value).await());
102
112
  }
103
113
  /**
104
114
  * Assert that the provided value is false.
105
115
  * @param value The value to check.
106
116
  */
117
+ assertFalse(value) {
118
+ _Test.assertFalse(this, value);
119
+ }
107
120
  static assertFalse(test2, value) {
108
121
  PreCondition.assertNotUndefinedAndNotNull(test2, "test");
109
122
  test2.assertSame(value, false);
@@ -183,6 +196,9 @@ var AssertTest = class _AssertTest {
183
196
  assertNotUndefinedAndNotNull(value) {
184
197
  Test.assertNotUndefinedAndNotNull(this, value);
185
198
  }
199
+ assertNotEmpty(value) {
200
+ Test.assertNotEmpty(this, value);
201
+ }
186
202
  assertSame(left, right) {
187
203
  assert.strictEqual(left, right);
188
204
  }
@@ -321,22 +337,19 @@ var BasicTestSkip = class _BasicTestSkip {
321
337
 
322
338
  // tests/failedTest.ts
323
339
  var FailedTest = class _FailedTest {
324
- fullTestNameParts;
340
+ testAction;
325
341
  error;
326
- constructor(fullTestNameParts, error) {
327
- PreCondition.assertNotEmpty(fullTestNameParts, "fullTestName");
342
+ constructor(testAction, error) {
343
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
328
344
  PreCondition.assertNotUndefinedAndNotNull(error, "error");
329
- this.fullTestNameParts = fullTestNameParts;
345
+ this.testAction = testAction;
330
346
  this.error = error;
331
347
  }
332
- static create(fullTestNameParts, error) {
333
- return new _FailedTest(fullTestNameParts, error);
334
- }
335
- getFullTestNameParts() {
336
- return this.fullTestNameParts;
348
+ static create(testAction, error) {
349
+ return new _FailedTest(testAction, error);
337
350
  }
338
- getFullTestName() {
339
- return join(" ", this.fullTestNameParts);
351
+ getTestAction() {
352
+ return this.testAction;
340
353
  }
341
354
  getError() {
342
355
  return this.error;
@@ -349,24 +362,21 @@ var FailedTest = class _FailedTest {
349
362
  // tests/skippedTest.ts
350
363
  var SkippedTest = class _SkippedTest {
351
364
  skip;
352
- fullTestNameParts;
353
- constructor(skip, fullTestNameParts) {
365
+ testAction;
366
+ constructor(skip, testAction) {
354
367
  PreCondition.assertNotUndefinedAndNotNull(skip, "skip");
355
- PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
368
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
356
369
  this.skip = skip;
357
- this.fullTestNameParts = fullTestNameParts;
370
+ this.testAction = testAction;
358
371
  }
359
- static create(skip, fullTestNameParts) {
360
- return new _SkippedTest(skip, fullTestNameParts);
372
+ static create(skip, testAction) {
373
+ return new _SkippedTest(skip, testAction);
361
374
  }
362
375
  getSkipMessage() {
363
376
  return this.skip.getMessage();
364
377
  }
365
- getFullTestNameParts() {
366
- return this.fullTestNameParts;
367
- }
368
- getFullTestName() {
369
- return join(" ", this.fullTestNameParts);
378
+ getTestAction() {
379
+ return this.testAction;
370
380
  }
371
381
  };
372
382
 
@@ -374,18 +384,21 @@ var SkippedTest = class _SkippedTest {
374
384
  var TestAction = class _TestAction {
375
385
  parent;
376
386
  name;
387
+ type;
377
388
  skip;
378
389
  action;
379
- constructor(parent, name, skip, action) {
390
+ constructor(parent, name, type, skip, action) {
380
391
  PreCondition.assertNotUndefinedAndNotNull(name, "name");
392
+ PreCondition.assertNotEmpty(type, "type");
381
393
  PreCondition.assertNotUndefinedAndNotNull(action, "action");
382
394
  this.parent = parent;
383
395
  this.name = name;
396
+ this.type = type;
384
397
  this.skip = skip;
385
398
  this.action = action;
386
399
  }
387
- static create(parent, name, skip, action) {
388
- return new _TestAction(parent, name, skip, action);
400
+ static create(parent, name, type, skip, action) {
401
+ return new _TestAction(parent, name, type, skip, action);
389
402
  }
390
403
  getParent() {
391
404
  return this.parent;
@@ -404,6 +417,9 @@ var TestAction = class _TestAction {
404
417
  getFullName() {
405
418
  return join(" ", this.getFullNameParts());
406
419
  }
420
+ getType() {
421
+ return this.type;
422
+ }
407
423
  getSkip() {
408
424
  return this.skip || this.parent?.getSkip();
409
425
  }
@@ -487,113 +503,237 @@ var TestRunner = class _TestRunner {
487
503
  static skip(_runner, shouldSkip, message) {
488
504
  return TestSkip.create(shouldSkip, message);
489
505
  }
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
- }
506
+ };
507
+
508
+ // tests/ConsoleTestRunnerUI.ts
509
+ var ConsoleTestRunnerUI = class {
510
+ writeStream;
511
+ styles;
512
+ constructor() {
513
+ this.styles = Map.create();
496
514
  }
497
- testFile(fileName, skipOrTestAction, testAction) {
498
- _TestRunner.testFile(this, fileName, skipOrTestAction, testAction);
515
+ static flat() {
516
+ return FlatConsoleTestRunnerUI.create();
499
517
  }
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);
518
+ static tree() {
519
+ return TreeConsoleTestRunnerUI.create();
520
520
  }
521
- testType(typeNameOrType, skipOrTestAction, testAction) {
522
- _TestRunner.testType(this, typeNameOrType, skipOrTestAction, testAction);
521
+ setWriteStream(writeStream) {
522
+ PreCondition.assertNotUndefinedAndNotNull(writeStream, "writeStream");
523
+ this.writeStream = IndentedCharacterWriteStream.create(writeStream);
524
+ return this;
523
525
  }
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;
526
+ setStyle(style, styleFunction) {
527
+ PreCondition.assertNotEmpty(style, "style");
528
+ PreCondition.assertNotUndefinedAndNotNull(styleFunction, "styleFunction");
529
+ this.styles.set(style, styleFunction);
530
+ return this;
531
+ }
532
+ setStyles(styles) {
533
+ PreCondition.assertNotUndefinedAndNotNull(styles, "styles");
534
+ for (const entry of Object.entries(styles)) {
535
+ this.setStyle(entry[0], entry[1]);
547
536
  }
537
+ return this;
538
+ }
539
+ applyStyle(style, text) {
540
+ PreCondition.assertNotEmpty(style, "style");
541
+ PreCondition.assertNotUndefinedAndNotNull(text, "text");
542
+ const styleFunction = this.styles.get(style).catch(NotFoundError, () => {
543
+ return (text2) => text2;
544
+ }).await();
545
+ return styleFunction(text);
546
+ }
547
+ addIndentation() {
548
+ this.writeStream?.addIndentation();
549
+ }
550
+ removeIndentation() {
551
+ this.writeStream?.removeIndentation();
552
+ }
553
+ indent(action) {
554
+ return this.writeStream?.indent(action) ?? AsyncResult.value(0);
555
+ }
556
+ writeString(text) {
557
+ return this.writeStream?.writeString(text) ?? AsyncResult.value(0);
558
+ }
559
+ writeLine(text) {
560
+ return this.writeStream?.writeLine(text) ?? AsyncResult.value(0);
561
+ }
562
+ writeTestActionName(testAction) {
563
+ return this.writeString(this.applyStyle(testAction.getType(), testAction.getName()));
564
+ }
565
+ writeFullTestActionName(testAction) {
566
+ return AsyncResult.create(async () => {
567
+ let result = 0;
568
+ const testActionStack = Stack.create();
569
+ let currentTestAction = testAction;
570
+ while (currentTestAction) {
571
+ testActionStack.add(currentTestAction);
572
+ currentTestAction = currentTestAction.getParent();
573
+ }
574
+ while (await testActionStack.any()) {
575
+ currentTestAction = await testActionStack.remove();
576
+ if (currentTestAction.getParent()) {
577
+ result += await this.writeString(" ");
578
+ }
579
+ result += await this.writeTestActionName(currentTestAction);
580
+ }
581
+ return result;
582
+ });
583
+ }
584
+ beforeTestGroup(testGroup) {
585
+ PreCondition.assertNotUndefinedAndNotNull(testGroup, "testGroup");
586
+ return AsyncResult.empty();
587
+ }
588
+ afterTestGroup(testGroup) {
589
+ PreCondition.assertNotUndefinedAndNotNull(testGroup, "testGroup");
590
+ return AsyncResult.empty();
591
+ }
592
+ beforeTest(testAction) {
593
+ return AsyncResult.empty();
594
+ }
595
+ afterPassedTest(testAction) {
596
+ return AsyncResult.create(async () => {
597
+ await this.writeLine(` - ${this.applyStyle("passed", "Passed")}`);
598
+ });
599
+ }
600
+ afterSkippedTest(testAction, skip) {
548
601
  PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
549
- _TestRunner.runTestAction(runner, typeName, skip, testAction);
602
+ PreCondition.assertNotUndefinedAndNotNull(skip, "skip");
603
+ return AsyncResult.create(async () => {
604
+ await this.writeLine(` - ${this.applyStyle("skipped", "Skipped")}`);
605
+ });
550
606
  }
551
- testFunction(functionSignature, skipOrTestAction, testAction) {
552
- _TestRunner.testFunction(this, functionSignature, skipOrTestAction, testAction);
607
+ afterFailedTest(currentTestAction, error) {
608
+ PreCondition.assertNotUndefinedAndNotNull(currentTestAction, "currentTestAction");
609
+ PreCondition.assertNotUndefinedAndNotNull(error, "error");
610
+ return AsyncResult.create(async () => {
611
+ await this.writeLine(` - ${this.applyStyle("failed", "Failed")}`);
612
+ });
553
613
  }
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
- }
614
+ writeSummary(passedTestCount, skippedTests, failedTests) {
615
+ PreCondition.assertGreaterThanOrEqualTo(passedTestCount, 0, "passedTestCount");
616
+ PreCondition.assertNotUndefinedAndNotNull(skippedTests, "skippedTests");
617
+ PreCondition.assertNotUndefinedAndNotNull(failedTests, "failedTests");
618
+ return AsyncResult.create(async () => {
619
+ await this.writeLine();
620
+ if (await skippedTests.any()) {
621
+ await this.writeLine(`${this.applyStyle("skipped", "Skipped Tests")}:`);
622
+ let counter = 0;
623
+ for (const skippedTest of skippedTests) {
624
+ await this.writeString(`${++counter}) `);
625
+ await this.writeFullTestActionName(skippedTest.getTestAction());
626
+ await this.writeLine();
627
+ const skipMessage = skippedTest.getSkipMessage();
628
+ if (skipMessage) {
629
+ await this.indent(() => this.writeLine(skipMessage));
630
+ }
631
+ }
632
+ await this.writeLine();
633
+ }
634
+ if (await failedTests.any()) {
635
+ await this.writeLine(`${this.applyStyle("failed", "Failed Tests")}:`);
636
+ let counter = 0;
637
+ for (const failedTest of failedTests) {
638
+ await this.writeString(`${++counter}) `);
639
+ await this.writeFullTestActionName(failedTest.getTestAction());
640
+ await this.writeLine();
641
+ await this.indent(() => this.writeLine(failedTest.getErrorMessage()));
642
+ await this.writeLine();
643
+ }
644
+ }
645
+ if (passedTestCount > 0) {
646
+ await this.writeLine(`${this.applyStyle("passed", "Passed")}: ${passedTestCount}`);
647
+ }
648
+ if (await skippedTests.any()) {
649
+ await this.writeLine(`${this.applyStyle("skipped", "Skipped")}: ${skippedTests.getCount().await()}`);
650
+ }
651
+ if (await failedTests.any()) {
652
+ await this.writeLine(`${this.applyStyle("failed", "Failed")}: ${failedTests.getCount().await()}`);
653
+ }
654
+ });
655
+ }
656
+ };
657
+ var FlatConsoleTestRunnerUI = class _FlatConsoleTestRunnerUI extends ConsoleTestRunnerUI {
658
+ constructor() {
659
+ super();
660
+ }
661
+ static create() {
662
+ return new _FlatConsoleTestRunnerUI();
663
+ }
664
+ beforeTest(testAction) {
665
+ return AsyncResult.create(async () => {
666
+ await this.writeFullTestActionName(testAction);
667
+ });
668
+ }
669
+ };
670
+ var TreeConsoleTestRunnerUI = class _TreeConsoleTestRunnerUI extends ConsoleTestRunnerUI {
671
+ testActions;
672
+ testActionWrittenDepth;
673
+ constructor() {
674
+ super();
675
+ this.testActions = List.create();
676
+ this.testActionWrittenDepth = 0;
677
+ }
678
+ static create() {
679
+ return new _TreeConsoleTestRunnerUI();
680
+ }
681
+ beforeTestGroup(testGroup) {
682
+ return AsyncResult.create(() => {
683
+ this.testActions.add(testGroup);
684
+ });
685
+ }
686
+ afterTestGroup(testGroup) {
687
+ PreCondition.assertNotUndefinedAndNotNull(testGroup, "testGroup");
688
+ PreCondition.assertTrue(this.testActions.any().await(), "this.testActions.any().await()");
689
+ return AsyncResult.create(() => {
690
+ this.testActions.removeLast().await();
691
+ const testActionCount = this.testActions.getCount().await();
692
+ if (this.testActionWrittenDepth > testActionCount) {
693
+ this.testActionWrittenDepth--;
694
+ this.removeIndentation();
695
+ }
696
+ });
697
+ }
698
+ beforeTest(testAction) {
571
699
  PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
572
- _TestRunner.runTestAction(runner, functionSignature, skip, testAction);
700
+ return AsyncResult.create(async () => {
701
+ const testActionCount = this.testActions.getCount().await();
702
+ while (this.testActionWrittenDepth < testActionCount) {
703
+ const testGroup = this.testActions.get(this.testActionWrittenDepth).await();
704
+ await this.writeTestActionName(testGroup);
705
+ await this.writeLine();
706
+ this.addIndentation();
707
+ this.testActionWrittenDepth++;
708
+ }
709
+ await this.writeTestActionName(testAction);
710
+ });
573
711
  }
574
712
  };
575
713
 
576
714
  // tests/consoleTestRunner.ts
577
- var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
715
+ var ConsoleTestRunner = class _ConsoleTestRunner {
578
716
  writeStream;
579
- pendingActions;
580
- pendingActionsInsertIndex;
717
+ testActions;
718
+ testActionInsertIndex;
581
719
  currentTestAction;
582
720
  currentTest;
583
721
  passedTestCount;
584
722
  skippedTests;
585
723
  testFailures;
586
- constructor() {
587
- super();
588
- this.writeStream = NodeJSCharacterWriteStream.create(process.stdout);
589
- this.pendingActions = List.create();
590
- this.pendingActionsInsertIndex = 0;
724
+ ui;
725
+ constructor(ui) {
726
+ this.writeStream = IndentedCharacterWriteStream.create(NodeJSCharacterWriteStream.create(process.stdout));
727
+ this.testActions = List.create();
728
+ this.testActionInsertIndex = 0;
591
729
  this.passedTestCount = 0;
592
730
  this.skippedTests = List.create();
593
731
  this.testFailures = List.create();
732
+ this.ui = ui || ConsoleTestRunnerUI.tree();
733
+ this.ui.setWriteStream(this.writeStream);
594
734
  }
595
- static create() {
596
- return new _ConsoleTestRunner();
735
+ static create(ui) {
736
+ return new _ConsoleTestRunner(ui);
597
737
  }
598
738
  static run(testFunctionOrTestFunctions) {
599
739
  let testFunction;
@@ -614,7 +754,15 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
614
754
  };
615
755
  }
616
756
  return CurrentProcess.run(async (currentProcess) => {
617
- const runner = _ConsoleTestRunner.create().setWriteStream(currentProcess.getOutputWriteStream());
757
+ const runner = _ConsoleTestRunner.create().setWriteStream(currentProcess.getOutputWriteStream()).setStyles({
758
+ file: (t) => ANSIStyles.blue(t),
759
+ function: (t) => ANSIStyles.blue(t),
760
+ type: (t) => ANSIStyles.blue(t),
761
+ group: (t) => ANSIStyles.blue(t),
762
+ passed: (t) => ANSIStyles.green(`\u2713 ${t}`),
763
+ skipped: (t) => ANSIStyles.yellow(`\u25CC ${t}`),
764
+ failed: (t) => ANSIStyles.red(`\u2717 ${t}`)
765
+ });
618
766
  await testFunction(runner);
619
767
  await runner.runAsync();
620
768
  await runner.printSummary();
@@ -622,21 +770,39 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
622
770
  }
623
771
  setWriteStream(writeStream) {
624
772
  PreCondition.assertNotUndefinedAndNotNull(writeStream, "writeStream");
625
- this.writeStream = writeStream;
773
+ this.writeStream = IndentedCharacterWriteStream.create(writeStream);
774
+ this.ui.setWriteStream(this.writeStream);
775
+ return this;
776
+ }
777
+ setStyle(style, styleFunction) {
778
+ this.ui.setStyle(style, styleFunction);
779
+ return this;
780
+ }
781
+ setStyles(styles) {
782
+ this.ui.setStyles(styles);
626
783
  return this;
627
784
  }
628
785
  /**
629
786
  * Get the number of {@link TestAction}s that have yet to be executed.
630
787
  */
631
- getPendingTestActionsCount() {
632
- return this.pendingActions.getCount().await();
788
+ getTestActionCount() {
789
+ return this.testActions.getCount().await();
633
790
  }
634
791
  /**
635
- * Get the index in the pending-{@link TestAction} stack that new {@link TestAction}s will be
792
+ * Get the index in the {@link TestAction} list that new {@link TestAction}s will be
636
793
  * inserted at.
637
794
  */
638
- getPendingTestActionsInsertIndex() {
639
- return this.pendingActionsInsertIndex;
795
+ getTestActionInsertIndex() {
796
+ return this.testActionInsertIndex;
797
+ }
798
+ resetTestActionInsertIndex() {
799
+ this.testActionInsertIndex = 0;
800
+ }
801
+ insertTestAction(testActionName, testActionType, skip, action) {
802
+ const parentTestAction = this.getCurrentTestAction();
803
+ const testAction = TestAction.create(parentTestAction, testActionName, testActionType, skip, action);
804
+ this.testActions.insert(this.testActionInsertIndex, testAction);
805
+ this.testActionInsertIndex++;
640
806
  }
641
807
  /**
642
808
  * Get the number of tests that have been skipped.
@@ -670,37 +836,103 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
670
836
  return this.currentTest;
671
837
  }
672
838
  assertNoCurrentTest() {
673
- if (this.currentTest !== void 0) {
839
+ if (this.currentTest) {
674
840
  this.currentTest.fail("Can't start a new test group or a new test while running a test.");
675
841
  }
676
842
  }
677
- beforeTest(fullTestNameParts) {
678
- return PromiseAsyncResult.create(async () => {
679
- await this.writeStream.writeString(join(" ", fullTestNameParts));
680
- });
843
+ beforeTestGroup(testAction) {
844
+ return this.ui.beforeTestGroup(testAction);
845
+ }
846
+ afterTestGroup(testAction) {
847
+ return this.ui.afterTestGroup(testAction);
848
+ }
849
+ beforeTest(testAction) {
850
+ return this.ui.beforeTest(testAction);
681
851
  }
682
- afterPassedTest() {
683
- return PromiseAsyncResult.create(async () => {
684
- await this.writeStream.writeLine(" - Passed");
852
+ afterPassedTest(testAction) {
853
+ return AsyncResult.create(async () => {
854
+ await this.ui.afterPassedTest(testAction);
685
855
  this.passedTestCount++;
686
856
  });
687
857
  }
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");
858
+ afterSkippedTest(testAction, skip) {
859
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
860
+ return AsyncResult.create(async () => {
861
+ await this.ui.afterSkippedTest(testAction, skip);
862
+ this.skippedTests.add(SkippedTest.create(skip, testAction));
694
863
  });
695
864
  }
696
- afterFailedTest(fullTestNameParts, error) {
697
- PreCondition.assertNotEmpty(fullTestNameParts, "fullTestNameParts");
865
+ afterFailedTest(testAction, error) {
866
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
698
867
  PreCondition.assertNotUndefinedAndNotNull(error, "error");
699
- return PromiseAsyncResult.create(async () => {
700
- this.testFailures.add(FailedTest.create(fullTestNameParts, error));
701
- await this.writeStream.writeLine(" - Failed");
868
+ return AsyncResult.create(async () => {
869
+ await this.ui.afterFailedTest(testAction, error);
870
+ this.testFailures.add(FailedTest.create(testAction, error));
702
871
  });
703
872
  }
873
+ andList(values) {
874
+ return TestRunner.andList(this, values);
875
+ }
876
+ toString(value) {
877
+ return TestRunner.toString(this, value);
878
+ }
879
+ skip(messageOrShouldSkip, message) {
880
+ let shouldSkip;
881
+ if (!isBoolean(messageOrShouldSkip)) {
882
+ shouldSkip = true;
883
+ message = messageOrShouldSkip;
884
+ } else {
885
+ shouldSkip = messageOrShouldSkip;
886
+ }
887
+ return TestRunner.skip(this, shouldSkip, message);
888
+ }
889
+ testFile(fileName, skipOrTestAction, testAction) {
890
+ PreCondition.assertNotUndefinedAndNotNull(fileName, "fileName");
891
+ PreCondition.assertNotEmpty(fileName, "fileName");
892
+ let skip;
893
+ if (isFunction(skipOrTestAction)) {
894
+ PreCondition.assertUndefined(testAction, "testAction");
895
+ skip = void 0;
896
+ testAction = skipOrTestAction;
897
+ } else {
898
+ skip = skipOrTestAction;
899
+ }
900
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
901
+ this.testGroupOrTest(fileName, "file", skip, testAction);
902
+ }
903
+ testType(typeNameOrType, skipOrTestAction, testAction) {
904
+ PreCondition.assertNotUndefinedAndNotNull(typeNameOrType, "typeNameOrType");
905
+ let typeName;
906
+ if (isString(typeNameOrType)) {
907
+ typeName = typeNameOrType;
908
+ } else {
909
+ typeName = getName(typeNameOrType);
910
+ }
911
+ PreCondition.assertNotEmpty(typeName, "typeName");
912
+ let skip;
913
+ if (isFunction(skipOrTestAction)) {
914
+ PreCondition.assertUndefined(testAction, "testAction");
915
+ skip = void 0;
916
+ testAction = skipOrTestAction;
917
+ } else {
918
+ skip = skipOrTestAction;
919
+ }
920
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
921
+ this.testGroupOrTest(typeName, "type", skip, testAction);
922
+ }
923
+ testFunction(functionSignature, skipOrTestAction, testAction) {
924
+ PreCondition.assertNotEmpty(functionSignature, "functionSignature");
925
+ let skip;
926
+ if (isFunction(skipOrTestAction)) {
927
+ PreCondition.assertUndefined(testAction, "testAction");
928
+ skip = void 0;
929
+ testAction = skipOrTestAction;
930
+ } else {
931
+ skip = skipOrTestAction;
932
+ }
933
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
934
+ this.testGroupOrTest(functionSignature, "function", skip, testAction);
935
+ }
704
936
  testGroup(testGroupName, skipOrTestAction, testAction) {
705
937
  PreCondition.assertNotUndefinedAndNotNull(testGroupName, "testGroupName");
706
938
  PreCondition.assertNotEmpty(testGroupName, "testGroupName");
@@ -713,27 +945,7 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
713
945
  skip = skipOrTestAction;
714
946
  }
715
947
  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
- );
948
+ this.innerTestGroup(testGroupName, "group", skip, testAction);
737
949
  }
738
950
  test(testName, skipOrTestAction, testAction) {
739
951
  PreCondition.assertNotUndefinedAndNotNull(testName, "testName");
@@ -747,85 +959,90 @@ var ConsoleTestRunner = class _ConsoleTestRunner extends TestRunner {
747
959
  skip = skipOrTestAction;
748
960
  }
749
961
  PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
962
+ this.innerTest(testName, "test", skip, testAction);
963
+ }
964
+ innerTestGroup(testGroupName, type, skip, testGroupAction) {
965
+ PreCondition.assertNotEmpty(testGroupName, "testGroupName");
966
+ PreCondition.assertNotUndefinedAndNotNull(testGroupAction, "testGroupAction");
750
967
  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
- }
968
+ this.insertTestAction(
969
+ testGroupName,
970
+ type,
971
+ skip,
972
+ () => this.beforeTestGroup(this.getCurrentTestAction())
973
+ );
974
+ this.insertTestAction(
975
+ testGroupName,
976
+ type,
977
+ skip,
978
+ async () => {
979
+ this.resetTestActionInsertIndex();
980
+ try {
981
+ await testGroupAction();
982
+ } catch (error) {
983
+ const currentTestGroupAction = this.getCurrentTestAction();
984
+ await this.afterFailedTest(currentTestGroupAction, error);
985
+ }
986
+ }
987
+ );
988
+ this.insertTestAction(
989
+ testGroupName,
990
+ type,
991
+ skip,
992
+ () => this.afterTestGroup(this.getCurrentTestAction())
993
+ );
994
+ }
995
+ innerTest(testName, testType, skip, testAction) {
996
+ PreCondition.assertNotEmpty(testName, "testName");
997
+ PreCondition.assertNotUndefinedAndNotNull(testAction, "testAction");
998
+ this.assertNoCurrentTest();
999
+ this.insertTestAction(
1000
+ testName,
1001
+ testType,
1002
+ skip,
1003
+ async () => {
1004
+ const currentTestAction = this.getCurrentTestAction();
1005
+ try {
1006
+ await this.beforeTest(currentTestAction);
1007
+ const skip2 = currentTestAction.getSkip();
1008
+ if (skip2?.getShouldSkip()) {
1009
+ await this.afterSkippedTest(currentTestAction, skip2);
1010
+ } else {
1011
+ this.currentTest = AssertTest.create(testName);
1012
+ try {
1013
+ await testAction(this.currentTest);
1014
+ } finally {
1015
+ this.currentTest = void 0;
771
1016
  }
772
- } catch (error) {
773
- await this.afterFailedTest(currentTestAction.getFullNameParts(), error);
1017
+ await this.afterPassedTest(currentTestAction);
774
1018
  }
1019
+ } catch (error) {
1020
+ await this.afterFailedTest(currentTestAction, error);
775
1021
  }
776
- )
1022
+ }
777
1023
  );
778
1024
  }
1025
+ testGroupOrTest(name, type, skip, testAction) {
1026
+ if (getParameterCount(testAction) === 0) {
1027
+ this.innerTestGroup(name, type, skip, testAction);
1028
+ } else {
1029
+ this.innerTest(name, type, skip, testAction);
1030
+ }
1031
+ }
779
1032
  async runAsync() {
780
- while (this.pendingActions.any().await()) {
781
- this.currentTestAction = this.pendingActions.removeLast().await();
1033
+ while (this.testActions.any().await()) {
1034
+ this.resetTestActionInsertIndex();
1035
+ this.currentTestAction = this.testActions.removeFirst().await();
782
1036
  try {
783
- const result = this.currentTestAction.runAsync();
784
- if (isPromise(result)) {
785
- await result;
786
- }
1037
+ await this.currentTestAction.runAsync();
787
1038
  } finally {
788
1039
  this.currentTestAction = void 0;
789
1040
  }
790
1041
  }
1042
+ this.resetTestActionInsertIndex();
791
1043
  }
792
1044
  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
- });
1045
+ return this.ui.writeSummary(this.passedTestCount, this.getSkippedTests(), this.getFailedTests());
829
1046
  }
830
1047
  };
831
1048
 
@@ -842,4 +1059,4 @@ export {
842
1059
  TestRunner,
843
1060
  ConsoleTestRunner
844
1061
  };
845
- //# sourceMappingURL=chunk-CHBOMCYM.js.map
1062
+ //# sourceMappingURL=chunk-VF6FBNAU.js.map