xunit.ts 0.13.1 → 1.0.3

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.
Files changed (175) hide show
  1. package/.editorconfig +26 -0
  2. package/.eslintrc.json +37 -0
  3. package/README.md +2 -1
  4. package/SECURITY.md +11 -0
  5. package/cli.ts +6 -5
  6. package/dist/cli.js +2 -1
  7. package/dist/cli.js.map +1 -1
  8. package/dist/src/Assertions/Contains.js +1 -1
  9. package/dist/src/Assertions/Contains.js.map +1 -1
  10. package/dist/src/Assertions/Count.js.map +1 -1
  11. package/dist/src/Assertions/Defined.js +2 -2
  12. package/dist/src/Assertions/Defined.js.map +1 -1
  13. package/dist/src/Assertions/DoesNotContain.js +1 -1
  14. package/dist/src/Assertions/DoesNotContain.js.map +1 -1
  15. package/dist/src/Assertions/DoesNotThrow.js +2 -2
  16. package/dist/src/Assertions/DoesNotThrow.js.map +1 -1
  17. package/dist/src/Assertions/Empty.js +1 -1
  18. package/dist/src/Assertions/Empty.js.map +1 -1
  19. package/dist/src/Assertions/Equal.js +2 -2
  20. package/dist/src/Assertions/Equal.js.map +1 -1
  21. package/dist/src/Assertions/False.js +1 -1
  22. package/dist/src/Assertions/False.js.map +1 -1
  23. package/dist/src/Assertions/InstanceOf.d.ts +1 -1
  24. package/dist/src/Assertions/InstanceOf.d.ts.map +1 -1
  25. package/dist/src/Assertions/InstanceOf.js +1 -1
  26. package/dist/src/Assertions/InstanceOf.js.map +1 -1
  27. package/dist/src/Assertions/NotEmpty.js +2 -2
  28. package/dist/src/Assertions/NotEmpty.js.map +1 -1
  29. package/dist/src/Assertions/NotEqual.js +2 -2
  30. package/dist/src/Assertions/NotEqual.js.map +1 -1
  31. package/dist/src/Assertions/NotNull.js +2 -2
  32. package/dist/src/Assertions/NotNull.js.map +1 -1
  33. package/dist/src/Assertions/Null.js +1 -1
  34. package/dist/src/Assertions/Null.js.map +1 -1
  35. package/dist/src/Assertions/StringContains.d.ts.map +1 -1
  36. package/dist/src/Assertions/StringContains.js +2 -2
  37. package/dist/src/Assertions/StringContains.js.map +1 -1
  38. package/dist/src/Assertions/StringDoesNotContain.d.ts.map +1 -1
  39. package/dist/src/Assertions/StringDoesNotContain.js +1 -1
  40. package/dist/src/Assertions/StringDoesNotContain.js.map +1 -1
  41. package/dist/src/Assertions/StringDoesNotEndWith.d.ts.map +1 -1
  42. package/dist/src/Assertions/StringDoesNotEndWith.js +4 -2
  43. package/dist/src/Assertions/StringDoesNotEndWith.js.map +1 -1
  44. package/dist/src/Assertions/StringDoesNotStartWith.d.ts.map +1 -1
  45. package/dist/src/Assertions/StringDoesNotStartWith.js +1 -1
  46. package/dist/src/Assertions/StringDoesNotStartWith.js.map +1 -1
  47. package/dist/src/Assertions/StringEndsWith.d.ts.map +1 -1
  48. package/dist/src/Assertions/StringEndsWith.js +4 -2
  49. package/dist/src/Assertions/StringEndsWith.js.map +1 -1
  50. package/dist/src/Assertions/StringStartsWith.d.ts.map +1 -1
  51. package/dist/src/Assertions/StringStartsWith.js +1 -1
  52. package/dist/src/Assertions/StringStartsWith.js.map +1 -1
  53. package/dist/src/Assertions/Throws.js +1 -1
  54. package/dist/src/Assertions/Throws.js.map +1 -1
  55. package/dist/src/Assertions/True.js +1 -1
  56. package/dist/src/Assertions/True.js.map +1 -1
  57. package/dist/src/Assertions/Undefined.js +1 -1
  58. package/dist/src/Assertions/Undefined.js.map +1 -1
  59. package/dist/src/Assertions/index.d.ts +22 -22
  60. package/dist/src/Assertions/index.d.ts.map +1 -1
  61. package/dist/src/Assertions/index.js.map +1 -1
  62. package/dist/src/CLI.d.ts +4 -1
  63. package/dist/src/CLI.d.ts.map +1 -1
  64. package/dist/src/CLI.js +10 -8
  65. package/dist/src/CLI.js.map +1 -1
  66. package/dist/src/Factory.d.ts +5 -4
  67. package/dist/src/Factory.d.ts.map +1 -1
  68. package/dist/src/Factory.js +4 -4
  69. package/dist/src/Factory.js.map +1 -1
  70. package/dist/src/Framework/ResultType.d.ts.map +1 -1
  71. package/dist/src/Framework/ResultType.js.map +1 -1
  72. package/dist/src/Framework/Test.d.ts.map +1 -1
  73. package/dist/src/Framework/Test.js.map +1 -1
  74. package/dist/src/Framework/TestName.d.ts.map +1 -1
  75. package/dist/src/Framework/TestName.js.map +1 -1
  76. package/dist/src/Framework/TestResult.d.ts.map +1 -1
  77. package/dist/src/Framework/TestResult.js.map +1 -1
  78. package/dist/src/Framework/TestSuite.d.ts +1 -1
  79. package/dist/src/Framework/TestSuite.d.ts.map +1 -1
  80. package/dist/src/Framework/TestSuite.js.map +1 -1
  81. package/dist/src/Framework/TestSuiteResults.d.ts +1 -1
  82. package/dist/src/Framework/TestSuiteResults.d.ts.map +1 -1
  83. package/dist/src/Framework/TestSuiteResults.js.map +1 -1
  84. package/dist/src/IO/FileSystem.d.ts +2 -2
  85. package/dist/src/IO/FileSystem.d.ts.map +1 -1
  86. package/dist/src/IO/FileSystem.js +6 -6
  87. package/dist/src/IO/FileSystem.js.map +1 -1
  88. package/dist/src/IO/Output.d.ts.map +1 -1
  89. package/dist/src/IO/Output.js.map +1 -1
  90. package/dist/src/Reporters/ConsoleReporter.d.ts.map +1 -1
  91. package/dist/src/Reporters/ConsoleReporter.js +8 -7
  92. package/dist/src/Reporters/ConsoleReporter.js.map +1 -1
  93. package/dist/src/Reporters/FileReporter.d.ts.map +1 -1
  94. package/dist/src/Reporters/FileReporter.js +1 -0
  95. package/dist/src/Reporters/FileReporter.js.map +1 -1
  96. package/dist/src/Reporters/JUnitReporter.d.ts +2 -2
  97. package/dist/src/Reporters/JUnitReporter.d.ts.map +1 -1
  98. package/dist/src/Reporters/JUnitReporter.js +7 -7
  99. package/dist/src/Reporters/JUnitReporter.js.map +1 -1
  100. package/dist/src/Reporters/ResultReporter.d.ts +3 -3
  101. package/dist/src/Reporters/ResultReporter.d.ts.map +1 -1
  102. package/dist/src/Reporters/SonarReporter.d.ts +2 -2
  103. package/dist/src/Reporters/SonarReporter.d.ts.map +1 -1
  104. package/dist/src/Reporters/SonarReporter.js +16 -16
  105. package/dist/src/Reporters/SonarReporter.js.map +1 -1
  106. package/dist/src/Reporters/XMLReporter.d.ts.map +1 -1
  107. package/dist/src/Reporters/XMLReporter.js.map +1 -1
  108. package/dist/src/Runners/Runner.d.ts +3 -3
  109. package/dist/src/Runners/Runner.d.ts.map +1 -1
  110. package/dist/src/Runners/Runner.js +5 -5
  111. package/dist/src/Runners/Runner.js.map +1 -1
  112. package/dist/src/Runners/TestRunner.d.ts +4 -4
  113. package/dist/src/Runners/TestRunner.d.ts.map +1 -1
  114. package/dist/src/Runners/TestRunner.js +10 -9
  115. package/dist/src/Runners/TestRunner.js.map +1 -1
  116. package/dist/src/Runners/TestSuiteLoader.d.ts +3 -3
  117. package/dist/src/Runners/TestSuiteLoader.d.ts.map +1 -1
  118. package/dist/src/Runners/TestSuiteLoader.js +15 -15
  119. package/dist/src/Runners/TestSuiteLoader.js.map +1 -1
  120. package/dist/src/Runners/TestSuiteRunner.d.ts +5 -5
  121. package/dist/src/Runners/TestSuiteRunner.d.ts.map +1 -1
  122. package/dist/src/Runners/TestSuiteRunner.js +1 -1
  123. package/dist/src/Runners/TestSuiteRunner.js.map +1 -1
  124. package/dist/xunit.d.ts +3 -3
  125. package/dist/xunit.d.ts.map +1 -1
  126. package/dist/xunit.js.map +1 -1
  127. package/icon.svg +82 -0
  128. package/logo.svg +154 -0
  129. package/package.json +43 -35
  130. package/sonar-project.properties +1 -1
  131. package/src/Assertions/Contains.ts +10 -10
  132. package/src/Assertions/Count.ts +11 -11
  133. package/src/Assertions/Defined.ts +11 -11
  134. package/src/Assertions/DoesNotContain.ts +11 -11
  135. package/src/Assertions/DoesNotThrow.ts +13 -13
  136. package/src/Assertions/Empty.ts +11 -11
  137. package/src/Assertions/Equal.ts +12 -12
  138. package/src/Assertions/False.ts +11 -11
  139. package/src/Assertions/InstanceOf.ts +13 -13
  140. package/src/Assertions/NotEmpty.ts +11 -11
  141. package/src/Assertions/NotEqual.ts +12 -12
  142. package/src/Assertions/NotNull.ts +11 -11
  143. package/src/Assertions/Null.ts +11 -11
  144. package/src/Assertions/StringContains.ts +12 -12
  145. package/src/Assertions/StringDoesNotContain.ts +12 -12
  146. package/src/Assertions/StringDoesNotEndWith.ts +14 -12
  147. package/src/Assertions/StringDoesNotStartWith.ts +12 -12
  148. package/src/Assertions/StringEndsWith.ts +14 -12
  149. package/src/Assertions/StringStartsWith.ts +12 -12
  150. package/src/Assertions/Throws.ts +11 -11
  151. package/src/Assertions/True.ts +11 -11
  152. package/src/Assertions/Undefined.ts +12 -12
  153. package/src/Assertions/index.ts +45 -45
  154. package/src/CLI.ts +85 -84
  155. package/src/Factory.ts +25 -25
  156. package/src/Framework/ResultType.ts +4 -4
  157. package/src/Framework/Test.ts +6 -6
  158. package/src/Framework/TestName.ts +7 -7
  159. package/src/Framework/TestResult.ts +3 -2
  160. package/src/Framework/TestSuite.ts +18 -18
  161. package/src/Framework/TestSuiteResults.ts +17 -16
  162. package/src/IO/FileSystem.ts +28 -29
  163. package/src/IO/Output.ts +21 -20
  164. package/src/Reporters/ConsoleReporter.ts +88 -87
  165. package/src/Reporters/FileReporter.ts +29 -29
  166. package/src/Reporters/JUnitReporter.ts +80 -80
  167. package/src/Reporters/ResultReporter.ts +20 -12
  168. package/src/Reporters/SonarReporter.ts +86 -86
  169. package/src/Reporters/XMLReporter.ts +6 -6
  170. package/src/Runners/Runner.ts +21 -21
  171. package/src/Runners/TestRunner.ts +34 -32
  172. package/src/Runners/TestSuiteLoader.ts +41 -40
  173. package/src/Runners/TestSuiteRunner.ts +27 -26
  174. package/tsconfig.json +26 -24
  175. package/xunit.ts +6 -6
package/src/Factory.ts CHANGED
@@ -1,33 +1,33 @@
1
- import Args from 'command-line-args';
2
- import ConsoleReporter from './Reporters/ConsoleReporter';
3
- import FileSystem from './IO/FileSystem';
4
- import JUnitReporter from './Reporters/JUnitReporter';
5
- import Output from './IO/Output';
6
- import ResultReporter from './Reporters/ResultReporter';
7
- import Runner from './Runners/Runner';
8
- import TestRunner from './Runners/TestRunner';
9
- import TestSuiteLoader from './Runners/TestSuiteLoader';
10
- import TestSuiteRunner from './Runners/TestSuiteRunner';
1
+ import Args from "command-line-args";
2
+ import ConsoleReporter from "./Reporters/ConsoleReporter";
3
+ import FileSystem from "./IO/FileSystem";
4
+ import JUnitReporter from "./Reporters/JUnitReporter";
5
+ import Output from "./IO/Output";
6
+ import ResultReporter from "./Reporters/ResultReporter";
7
+ import Runner from "./Runners/Runner";
8
+ import TestRunner from "./Runners/TestRunner";
9
+ import TestSuiteLoader from "./Runners/TestSuiteLoader";
10
+ import TestSuiteRunner from "./Runners/TestSuiteRunner";
11
11
  import fs from "fs/promises";
12
12
  import SonarReporter from "./Reporters/SonarReporter";
13
13
 
14
14
  export default class Factory {
15
- private static readonly file_system = new FileSystem(fs);
15
+ static readonly file_system = new FileSystem(fs);
16
16
 
17
- static Runner(args: Args.CommandLineOptions) {
18
- const loader = new TestSuiteLoader(this.file_system);
19
- const reporters = this.Reporters(args);
20
- const test_runner = new TestRunner(reporters);
21
- const test_suite_runner = new TestSuiteRunner(test_runner, reporters);
17
+ static Runner(args: Args.CommandLineOptions) {
18
+ const loader = new TestSuiteLoader(Factory.file_system);
19
+ const reporters = Factory.Reporters(args);
20
+ const test_runner = new TestRunner(reporters);
21
+ const test_suite_runner = new TestSuiteRunner(test_runner, reporters);
22
22
 
23
- return new Runner(loader, test_suite_runner, reporters);
24
- }
23
+ return new Runner(loader, test_suite_runner, reporters);
24
+ }
25
25
 
26
- static Reporters(args: Args.CommandLineOptions): ReadonlyArray<ResultReporter> {
27
- return [
28
- !args.quiet ? new ConsoleReporter(new Output(process.stdout)) : null,
29
- args.junit !== undefined ? new JUnitReporter(this.file_system, args.junit ?? JUnitReporter.defaultFileName) : null,
30
- args.sonar !== undefined ? new SonarReporter(this.file_system, args.sonar ?? SonarReporter.defaultFileName) : null
31
- ].filter(r => r !== null) as ResultReporter[];
32
- }
26
+ static Reporters(args: Args.CommandLineOptions): ReadonlyArray<ResultReporter> {
27
+ return [
28
+ !args.quiet ? new ConsoleReporter(new Output(process.stdout)) : null,
29
+ args.junit !== undefined ? new JUnitReporter(Factory.file_system, args.junit ?? JUnitReporter.defaultFileName) : null,
30
+ args.sonar !== undefined ? new SonarReporter(Factory.file_system, args.sonar ?? SonarReporter.defaultFileName) : null
31
+ ].filter(r => r !== null) as ResultReporter[];
32
+ }
33
33
  }
@@ -1,6 +1,6 @@
1
1
  export enum ResultType {
2
- Error = -2,
3
- Failed = -1,
4
- Incomplete = 0,
5
- Passed = 1
2
+ Error = -2,
3
+ Failed = -1,
4
+ Incomplete = 0,
5
+ Passed = 1
6
6
  }
@@ -4,12 +4,12 @@ import TestName from "./TestName";
4
4
 
5
5
  /**
6
6
  * Annotates a test method within a {@link TestSuite}
7
- *
7
+ *
8
8
  * @remarks
9
9
  * This instructs `xunit.ts` to run this method as part of its {@link TestSuite}
10
- *
10
+ *
11
11
  * @param test_name (optional) the test's display name; if not set, a sentence case version of the method name will be used
12
- *
12
+ *
13
13
  * @example
14
14
  * ```
15
15
  * @Test()
@@ -17,7 +17,7 @@ import TestName from "./TestName";
17
17
  * ```
18
18
  */
19
19
  export default function Test(test_name?: string) {
20
- return function (suite: TestSuite, method_name: string, info: TestInfo) {
21
- suite.addTest(test_name || TestName.toSentenceCase(method_name), info);
22
- }
20
+ return function (suite: TestSuite, method_name: string, info: TestInfo) {
21
+ suite.addTest(test_name || TestName.toSentenceCase(method_name), info);
22
+ };
23
23
  }
@@ -1,9 +1,9 @@
1
1
  export default class TestName {
2
- static toSentenceCase(test_name: string) {
3
- const result = test_name
4
- .replace(/_([A-Z])/gi, (substring: string, match: string) => match.toUpperCase())
5
- .replace(/([A-Z])/g, " $1")
6
- .trim();
7
- return result.charAt(0).toUpperCase() + result.slice(1);
8
- }
2
+ static toSentenceCase(test_name: string) {
3
+ const result = test_name
4
+ .replace(/_([A-Z])/gi, (substring: string, match: string) => match.toUpperCase())
5
+ .replace(/([A-Z])/g, " $1")
6
+ .trim();
7
+ return result.charAt(0).toUpperCase() + result.slice(1);
8
+ }
9
9
  }
@@ -1,5 +1,6 @@
1
- import {ResultType} from "./ResultType";
1
+ import { ResultType } from "./ResultType";
2
2
 
3
3
  export default class TestResult {
4
- constructor(readonly type: ResultType, readonly duration: number, readonly error: Error|null = null) { }
4
+ constructor(readonly type: ResultType, readonly duration: number, readonly error: Error | null = null) {
5
+ }
5
6
  }
@@ -1,32 +1,32 @@
1
- import TestInfo from './TestInfo';
2
- import AssertionLibrary from '../Assertions';
1
+ import TestInfo from "./TestInfo";
2
+ import AssertionLibrary from "../Assertions";
3
3
 
4
4
  /**
5
5
  * Defines a container of tests
6
- *
6
+ *
7
7
  * @remarks
8
8
  * Extend this class for `xunit.ts` load its tests
9
- *
9
+ *
10
10
  * @example
11
11
  * export default class CustomClassTests extends TestSuite { ... }
12
12
  */
13
13
  export default abstract class TestSuite {
14
- assert = AssertionLibrary;
14
+ assert = AssertionLibrary;
15
15
 
16
- private tests: Record<string, TestInfo> = {};
16
+ private tests: Record<string, TestInfo> = {};
17
17
 
18
- addTest(name: string, info: TestInfo) {
19
- if (this.tests === undefined || this.tests === null) {
20
- this.tests = {};
21
- }
22
- this.tests[name] = info;
23
- }
18
+ addTest(name: string, info: TestInfo) {
19
+ if (this.tests === undefined || this.tests === null) {
20
+ this.tests = {};
21
+ }
22
+ this.tests[name] = info;
23
+ }
24
24
 
25
- setTests(tests: Record<string, TestInfo>) {
26
- this.tests = tests;
27
- }
25
+ setTests(tests: Record<string, TestInfo>) {
26
+ this.tests = tests;
27
+ }
28
28
 
29
- getTests() {
30
- return this.tests;
31
- }
29
+ getTests() {
30
+ return this.tests;
31
+ }
32
32
  }
@@ -1,26 +1,27 @@
1
- import { ResultType } from './ResultType';
1
+ import { ResultType } from "./ResultType";
2
2
  import TestResult from "./TestResult";
3
3
  import TestSuite from "./TestSuite";
4
4
 
5
5
  export default class TestSuiteResults {
6
6
 
7
- readonly results: Record<string, TestResult> = {};
8
-
9
- constructor(readonly suite: TestSuite) { }
7
+ readonly results: Record<string, TestResult> = {};
10
8
 
11
- addResult(name: string, result: TestResult) {
12
- this.results[name] = result;
13
- }
9
+ constructor(readonly suite: TestSuite) {
10
+ }
14
11
 
15
- total() {
16
- return Object.values(this.results).length;
17
- }
12
+ addResult(name: string, result: TestResult) {
13
+ this.results[name] = result;
14
+ }
18
15
 
19
- count(result_type: ResultType) {
20
- return Object.values(this.results).filter(result => result.type === result_type).length;
21
- }
16
+ total() {
17
+ return Object.values(this.results).length;
18
+ }
22
19
 
23
- time() {
24
- return Object.values(this.results).reduce((sum, result) => sum + result.duration, 0);
25
- }
20
+ count(result_type: ResultType) {
21
+ return Object.values(this.results).filter(result => result.type === result_type).length;
22
+ }
23
+
24
+ time() {
25
+ return Object.values(this.results).reduce((sum, result) => sum + result.duration, 0);
26
+ }
26
27
  }
@@ -1,37 +1,36 @@
1
- import fs_promises from 'fs/promises';
1
+ import fs_promises from "fs/promises";
2
2
  import path from "path";
3
3
 
4
4
  export default class FileSystem {
5
5
 
6
- constructor(private readonly fs: typeof fs_promises) {
7
- }
6
+ constructor(private readonly fs: typeof fs_promises) {
7
+ }
8
8
 
9
- async getFiles(dir: string): Promise<string[]> {
10
- try {
11
- const files = [];
12
- const contents = await this.fs.readdir(dir);
13
- for (const item of contents) {
14
- const item_path = `${dir}${path.sep}${item}`;
15
- const stats = await this.fs.stat(item_path);
16
- files.push(...stats.isDirectory()
17
- ? await this.getFiles(item_path)
18
- : [item_path]);
19
- }
20
- return files;
21
- } catch (e) {
22
- return [];
23
- }
24
- }
9
+ static extension(file: string) {
10
+ const match = file.match(/\.(\w+)$/);
11
+ return match !== undefined && match !== null && match.length > 1
12
+ ? match[1]
13
+ : "";
14
+ }
25
15
 
16
+ async getFiles(dir: string): Promise<string[]> {
17
+ try {
18
+ const files = [];
19
+ const contents = await this.fs.readdir(dir);
20
+ for (const item of contents) {
21
+ const item_path = `${dir}${path.sep}${item}`;
22
+ const stats = await this.fs.stat(item_path);
23
+ files.push(...stats.isDirectory()
24
+ ? await this.getFiles(item_path)
25
+ : [ item_path ]);
26
+ }
27
+ return files;
28
+ } catch (e) {
29
+ return [];
30
+ }
31
+ }
26
32
 
27
- static extension(file: string) {
28
- const match = file.match(/\.(\w+)$/);
29
- return match !== undefined && match !== null && match.length > 1
30
- ? match[1]
31
- : '';
32
- }
33
-
34
- async save(data: string, file_path: string) {
35
- await this.fs.writeFile(file_path, data);
36
- }
33
+ async save(data: string, file_path: string) {
34
+ await this.fs.writeFile(file_path, data);
35
+ }
37
36
  }
package/src/IO/Output.ts CHANGED
@@ -2,29 +2,30 @@ import { WriteStream } from "tty";
2
2
 
3
3
  export default class Output {
4
4
 
5
- constructor(private readonly out: WriteStream) { }
5
+ constructor(private readonly out: WriteStream) {
6
+ }
6
7
 
7
- write(data: string) {
8
- this.out.write(data);
9
- }
8
+ write(data: string) {
9
+ this.out.write(data);
10
+ }
10
11
 
11
- writeLine(data: string = "") {
12
- this.out.write(data + "\n");
13
- }
12
+ writeLine(data = "") {
13
+ this.out.write(data + "\n");
14
+ }
14
15
 
15
- overwrite(data: string) {
16
- this.deleteLine();
17
- this.write(data);
18
- }
16
+ overwrite(data: string) {
17
+ this.deleteLine();
18
+ this.write(data);
19
+ }
19
20
 
20
- overwriteLine(data: string) {
21
- this.deleteLine();
22
- this.writeLine(data);
23
- }
21
+ overwriteLine(data: string) {
22
+ this.deleteLine();
23
+ this.writeLine(data);
24
+ }
24
25
 
25
- deleteLine() {
26
- if (this.out.isTTY) {
27
- this.out.cursorTo(0);
28
- }
29
- }
26
+ deleteLine() {
27
+ if (this.out.isTTY) {
28
+ this.out.cursorTo(0);
29
+ }
30
+ }
30
31
  }
@@ -3,95 +3,96 @@ import TestSuite from "../Framework/TestSuite";
3
3
  import Output from "../IO/Output";
4
4
  import TestName from "../Framework/TestName";
5
5
  import colors from "colors";
6
- import {AssertionError} from "assert";
6
+ import { AssertionError } from "assert";
7
7
  import TestSuiteResults from "../Framework/TestSuiteResults";
8
- import {ResultType} from "../Framework/ResultType";
8
+ import { ResultType } from "../Framework/ResultType";
9
9
 
10
10
  export default class ConsoleReporter implements ResultReporter {
11
11
 
12
- constructor(private readonly out: Output) {
13
- }
14
-
15
- runStarted(): void {
16
- this.out.writeLine('Starting xunit.ts...');
17
- this.out.writeLine();
18
- }
19
-
20
- suiteStarted(suite: TestSuite): void {
21
- this.out.writeLine(TestName.toSentenceCase(suite.constructor.name));
22
- }
23
-
24
- testStarted(suite: TestSuite, test_name: string): void {
25
- this.out.write(` ${colors.white('')} ${test_name}`);
26
- }
27
-
28
- testPassed(suite: TestSuite, test_name: string, duration: number): void {
29
- this.out.write(` (${Math.round(duration)} ms)`);
30
- this.out.overwrite(` ${colors.green('')}\n`);
31
- }
32
-
33
- testFailed(suite: TestSuite, test_name: string, error: AssertionError, duration: number): void {
34
- this.out.write(` (${Math.round(duration)} ms)`);
35
- this.out.overwrite(` ${colors.red('')}\n`);
36
- this.out.writeLine(` ${error.message}`);
37
- this.out.writeLine(` Expected: ${colors.green(String(error.expected))}`);
38
- this.out.writeLine(` Actual: ${colors.red(String(error.actual))}`);
39
- this.out.writeLine();
40
- }
41
-
42
- testErrored(suite: TestSuite, test_name: string, error: Error, duration: number): void {
43
- this.out.write(` (${Math.round(duration)} ms)`);
44
- this.out.overwrite(` ${colors.red('')}\n`);
45
- this.out.writeLine(` ${error.stack}`);
46
- this.out.writeLine();
47
- }
48
-
49
- testIncomplete(suite: TestSuite, test_name: string): void {
50
- this.out.overwrite(` ${colors.yellow('?')}\n`);
51
- }
52
-
53
- suiteCompleted(suite: TestSuite, results: TestSuiteResults): void {
54
- const passed = results.count(ResultType.Passed);
55
- const total = results.total();
56
- const time = results.time();
57
- const color = passed === total ? colors.green : colors.red;
58
- const fraction = `${passed} / ${total}`;
59
- this.out.writeLine(` ${color(fraction)} passed (${Math.round(time)} ms)`);
60
- this.out.writeLine();
61
- }
62
-
63
- runCompleted(suites: Record<string, TestSuiteResults>): void {
64
- const results = Object.values(suites);
65
- if (!results.length) {
66
- this.out.writeLine('No tests found!');
67
- return;
68
- }
69
-
70
- const sum = (result_type?: ResultType) => results
71
- .map((suite_result) => result_type !== undefined ? suite_result.count(result_type) : suite_result.total())
72
- .reduce((acc, current) => acc + current);
73
-
74
- const result = (result_type?: ResultType, color: (string: string) => string = colors.white) => {
75
- const count = sum(result_type).toString();
76
- const pad = sum().toString().length;
77
- return color(count.padStart(pad));
78
- }
79
-
80
- this.out.writeLine(` Passed: ${result(ResultType.Passed, colors.green)}`);
81
-
82
- if (sum(ResultType.Failed)) {
83
- this.out.writeLine(` Failed: ${result(ResultType.Failed, colors.red)}`);
84
- }
85
-
86
- if (sum(ResultType.Error)) {
87
- this.out.writeLine(` Error: ${result(ResultType.Error, colors.red)}`);
88
- }
89
-
90
- if (sum(ResultType.Incomplete)) {
91
- this.out.writeLine(`Incomplete: ${result(ResultType.Incomplete, colors.yellow)}`);
92
- }
93
-
94
- this.out.writeLine(` Total: ${result(undefined, sum() === sum(ResultType.Passed) ? colors.green : undefined)}`);
95
- this.out.writeLine();
96
- }
12
+ constructor(private readonly out: Output) {
13
+ }
14
+
15
+ runStarted(): void {
16
+ this.out.writeLine("Starting xunit.ts...");
17
+ this.out.writeLine();
18
+ }
19
+
20
+ suiteStarted(suite: TestSuite): void {
21
+ this.out.writeLine(TestName.toSentenceCase(suite.constructor.name));
22
+ }
23
+
24
+ testStarted(suite: TestSuite, test_name: string): void {
25
+ this.out.write(` ${colors.white("")} ${test_name}`);
26
+ }
27
+
28
+ testPassed(suite: TestSuite, test_name: string, duration: number): void {
29
+ this.out.write(` (${Math.round(duration)} ms)`);
30
+ this.out.overwrite(` ${colors.green("")}\n`);
31
+ }
32
+
33
+ testFailed(suite: TestSuite, test_name: string, error: AssertionError, duration: number): void {
34
+ this.out.write(` (${Math.round(duration)} ms)`);
35
+ this.out.overwrite(` ${colors.red("")}\n`);
36
+ this.out.writeLine(` ${error.message}`);
37
+ this.out.writeLine(` Expected: ${colors.green(String(error.expected))}`);
38
+ this.out.writeLine(` Actual: ${colors.red(String(error.actual))}`);
39
+ this.out.writeLine();
40
+ }
41
+
42
+ testErrored(suite: TestSuite, test_name: string, error: Error, duration: number): void {
43
+ this.out.write(` (${Math.round(duration)} ms)`);
44
+ this.out.overwrite(` ${colors.red("")}\n`);
45
+ this.out.writeLine(` ${error.stack}`);
46
+ this.out.writeLine();
47
+ }
48
+
49
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
50
+ testIncomplete(suite: TestSuite, test_name: string): void {
51
+ this.out.overwrite(` ${colors.yellow("?")}\n`);
52
+ }
53
+
54
+ suiteCompleted(suite: TestSuite, results: TestSuiteResults): void {
55
+ const passed = results.count(ResultType.Passed);
56
+ const total = results.total();
57
+ const time = results.time();
58
+ const color = passed === total ? colors.green : colors.red;
59
+ const fraction = `${passed} / ${total}`;
60
+ this.out.writeLine(` ${color(fraction)} passed (${Math.round(time)} ms)`);
61
+ this.out.writeLine();
62
+ }
63
+
64
+ runCompleted(suites: Record<string, TestSuiteResults>): void {
65
+ const results = Object.values(suites);
66
+ if (!results.length) {
67
+ this.out.writeLine("No tests found!");
68
+ return;
69
+ }
70
+
71
+ const sum = (result_type?: ResultType) => results
72
+ .map((suite_result) => result_type !== undefined ? suite_result.count(result_type) : suite_result.total())
73
+ .reduce((acc, current) => acc + current);
74
+
75
+ const result = (result_type?: ResultType, color: (string: string) => string = colors.white) => {
76
+ const count = sum(result_type).toString();
77
+ const pad = sum().toString().length;
78
+ return color(count.padStart(pad));
79
+ };
80
+
81
+ this.out.writeLine(` Passed: ${result(ResultType.Passed, colors.green)}`);
82
+
83
+ if (sum(ResultType.Failed)) {
84
+ this.out.writeLine(` Failed: ${result(ResultType.Failed, colors.red)}`);
85
+ }
86
+
87
+ if (sum(ResultType.Error)) {
88
+ this.out.writeLine(` Error: ${result(ResultType.Error, colors.red)}`);
89
+ }
90
+
91
+ if (sum(ResultType.Incomplete)) {
92
+ this.out.writeLine(`Incomplete: ${result(ResultType.Incomplete, colors.yellow)}`);
93
+ }
94
+
95
+ this.out.writeLine(` Total: ${result(undefined, sum() === sum(ResultType.Passed) ? colors.green : undefined)}`);
96
+ this.out.writeLine();
97
+ }
97
98
  }
@@ -1,45 +1,45 @@
1
1
  import ResultReporter from "./ResultReporter";
2
2
  import TestSuiteResults from "../Framework/TestSuiteResults";
3
3
  import TestSuite from "../Framework/TestSuite";
4
- import {AssertionError} from "assert";
4
+ import { AssertionError } from "assert";
5
5
  import FileSystem from "../IO/FileSystem";
6
6
 
7
7
  export default abstract class FileReporter implements ResultReporter {
8
+ /* eslint-disable @typescript-eslint/no-unused-vars */
9
+ constructor(protected readonly file_system: FileSystem, protected readonly path: string) {
10
+ }
8
11
 
9
- constructor(protected readonly file_system: FileSystem, protected readonly path: string) {
10
- }
12
+ runStarted(): void {
13
+ return;
14
+ }
11
15
 
12
- runStarted(): void {
13
- return;
14
- }
16
+ suiteStarted(suite: TestSuite): void {
17
+ return;
18
+ }
15
19
 
16
- suiteStarted(suite: TestSuite): void {
17
- return;
18
- }
20
+ testStarted(suite: TestSuite, test_name: string): void {
21
+ return;
22
+ }
19
23
 
20
- testStarted(suite: TestSuite, test_name: string): void {
21
- return;
22
- }
24
+ testErrored(suite: TestSuite, test_name: string, error: Error, duration: number): void {
25
+ return;
26
+ }
23
27
 
24
- testErrored(suite: TestSuite, test_name: string, error: Error, duration: number): void {
25
- return;
26
- }
28
+ testFailed(suite: TestSuite, test_name: string, error: AssertionError, duration: number): void {
29
+ return;
30
+ }
27
31
 
28
- testFailed(suite: TestSuite, test_name: string, error: AssertionError, duration: number): void {
29
- return;
30
- }
32
+ testIncomplete(suite: TestSuite, test_name: string): void {
33
+ return;
34
+ }
31
35
 
32
- testIncomplete(suite: TestSuite, test_name: string): void {
33
- return;
34
- }
36
+ testPassed(suite: TestSuite, test_name: string, duration: number): void {
37
+ return;
38
+ }
35
39
 
36
- testPassed(suite: TestSuite, test_name: string, duration: number): void {
37
- return;
38
- }
40
+ suiteCompleted(suite: TestSuite, results: TestSuiteResults): void {
41
+ return;
42
+ }
39
43
 
40
- suiteCompleted(suite: TestSuite, results: TestSuiteResults): void {
41
- return;
42
- }
43
-
44
- abstract runCompleted(results: Record<string, TestSuiteResults>): void;
44
+ abstract runCompleted(results: Record<string, TestSuiteResults>): void;
45
45
  }