xunit.ts 1.0.1 → 1.1.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.
Files changed (168) hide show
  1. package/.editorconfig +2 -0
  2. package/.eslintrc.json +37 -0
  3. package/README.md +6 -2
  4. package/cli.ts +5 -5
  5. package/dist/cli.js.map +1 -1
  6. package/dist/src/Assertions/Contains.js +1 -1
  7. package/dist/src/Assertions/Contains.js.map +1 -1
  8. package/dist/src/Assertions/Count.js.map +1 -1
  9. package/dist/src/Assertions/Defined.js +2 -2
  10. package/dist/src/Assertions/Defined.js.map +1 -1
  11. package/dist/src/Assertions/DoesNotContain.js +1 -1
  12. package/dist/src/Assertions/DoesNotContain.js.map +1 -1
  13. package/dist/src/Assertions/DoesNotThrow.js +2 -2
  14. package/dist/src/Assertions/DoesNotThrow.js.map +1 -1
  15. package/dist/src/Assertions/Empty.js +1 -1
  16. package/dist/src/Assertions/Empty.js.map +1 -1
  17. package/dist/src/Assertions/Equal.js +1 -1
  18. package/dist/src/Assertions/Equal.js.map +1 -1
  19. package/dist/src/Assertions/False.js +1 -1
  20. package/dist/src/Assertions/False.js.map +1 -1
  21. package/dist/src/Assertions/InstanceOf.d.ts +1 -1
  22. package/dist/src/Assertions/InstanceOf.d.ts.map +1 -1
  23. package/dist/src/Assertions/InstanceOf.js +1 -1
  24. package/dist/src/Assertions/InstanceOf.js.map +1 -1
  25. package/dist/src/Assertions/NotEmpty.js +2 -2
  26. package/dist/src/Assertions/NotEmpty.js.map +1 -1
  27. package/dist/src/Assertions/NotEqual.js +1 -1
  28. package/dist/src/Assertions/NotEqual.js.map +1 -1
  29. package/dist/src/Assertions/NotNull.js +2 -2
  30. package/dist/src/Assertions/NotNull.js.map +1 -1
  31. package/dist/src/Assertions/Null.js +1 -1
  32. package/dist/src/Assertions/Null.js.map +1 -1
  33. package/dist/src/Assertions/StringContains.js +1 -1
  34. package/dist/src/Assertions/StringContains.js.map +1 -1
  35. package/dist/src/Assertions/StringDoesNotContain.d.ts.map +1 -1
  36. package/dist/src/Assertions/StringDoesNotContain.js +1 -1
  37. package/dist/src/Assertions/StringDoesNotContain.js.map +1 -1
  38. package/dist/src/Assertions/StringDoesNotEndWith.js +1 -1
  39. package/dist/src/Assertions/StringDoesNotEndWith.js.map +1 -1
  40. package/dist/src/Assertions/StringDoesNotStartWith.d.ts.map +1 -1
  41. package/dist/src/Assertions/StringDoesNotStartWith.js +1 -1
  42. package/dist/src/Assertions/StringDoesNotStartWith.js.map +1 -1
  43. package/dist/src/Assertions/StringEndsWith.js +1 -1
  44. package/dist/src/Assertions/StringEndsWith.js.map +1 -1
  45. package/dist/src/Assertions/StringStartsWith.d.ts.map +1 -1
  46. package/dist/src/Assertions/StringStartsWith.js +1 -1
  47. package/dist/src/Assertions/StringStartsWith.js.map +1 -1
  48. package/dist/src/Assertions/Throws.js +1 -1
  49. package/dist/src/Assertions/Throws.js.map +1 -1
  50. package/dist/src/Assertions/True.js +1 -1
  51. package/dist/src/Assertions/True.js.map +1 -1
  52. package/dist/src/Assertions/Undefined.js +1 -1
  53. package/dist/src/Assertions/Undefined.js.map +1 -1
  54. package/dist/src/Assertions/index.d.ts +22 -22
  55. package/dist/src/Assertions/index.d.ts.map +1 -1
  56. package/dist/src/Assertions/index.js.map +1 -1
  57. package/dist/src/CLI.d.ts.map +1 -1
  58. package/dist/src/CLI.js +19 -8
  59. package/dist/src/CLI.js.map +1 -1
  60. package/dist/src/Factory.d.ts +4 -4
  61. package/dist/src/Factory.d.ts.map +1 -1
  62. package/dist/src/Factory.js.map +1 -1
  63. package/dist/src/Framework/ResultType.d.ts.map +1 -1
  64. package/dist/src/Framework/ResultType.js.map +1 -1
  65. package/dist/src/Framework/Test.d.ts.map +1 -1
  66. package/dist/src/Framework/Test.js.map +1 -1
  67. package/dist/src/Framework/TestName.d.ts.map +1 -1
  68. package/dist/src/Framework/TestName.js.map +1 -1
  69. package/dist/src/Framework/TestResult.d.ts.map +1 -1
  70. package/dist/src/Framework/TestResult.js.map +1 -1
  71. package/dist/src/Framework/TestSuite.d.ts +3 -2
  72. package/dist/src/Framework/TestSuite.d.ts.map +1 -1
  73. package/dist/src/Framework/TestSuite.js +12 -2
  74. package/dist/src/Framework/TestSuite.js.map +1 -1
  75. package/dist/src/Framework/TestSuiteResults.d.ts +1 -1
  76. package/dist/src/Framework/TestSuiteResults.d.ts.map +1 -1
  77. package/dist/src/Framework/TestSuiteResults.js.map +1 -1
  78. package/dist/src/IO/FileSystem.d.ts +2 -2
  79. package/dist/src/IO/FileSystem.d.ts.map +1 -1
  80. package/dist/src/IO/FileSystem.js +6 -6
  81. package/dist/src/IO/FileSystem.js.map +1 -1
  82. package/dist/src/IO/Output.d.ts.map +1 -1
  83. package/dist/src/IO/Output.js.map +1 -1
  84. package/dist/src/Reporters/ConsoleReporter.d.ts.map +1 -1
  85. package/dist/src/Reporters/ConsoleReporter.js +8 -7
  86. package/dist/src/Reporters/ConsoleReporter.js.map +1 -1
  87. package/dist/src/Reporters/FileReporter.d.ts.map +1 -1
  88. package/dist/src/Reporters/FileReporter.js +1 -0
  89. package/dist/src/Reporters/FileReporter.js.map +1 -1
  90. package/dist/src/Reporters/JUnitReporter.d.ts +2 -2
  91. package/dist/src/Reporters/JUnitReporter.d.ts.map +1 -1
  92. package/dist/src/Reporters/JUnitReporter.js +7 -7
  93. package/dist/src/Reporters/JUnitReporter.js.map +1 -1
  94. package/dist/src/Reporters/ResultReporter.d.ts +3 -3
  95. package/dist/src/Reporters/ResultReporter.d.ts.map +1 -1
  96. package/dist/src/Reporters/SonarReporter.d.ts +2 -2
  97. package/dist/src/Reporters/SonarReporter.d.ts.map +1 -1
  98. package/dist/src/Reporters/SonarReporter.js +16 -16
  99. package/dist/src/Reporters/SonarReporter.js.map +1 -1
  100. package/dist/src/Reporters/XMLReporter.d.ts.map +1 -1
  101. package/dist/src/Reporters/XMLReporter.js.map +1 -1
  102. package/dist/src/Runners/Runner.d.ts +3 -3
  103. package/dist/src/Runners/Runner.d.ts.map +1 -1
  104. package/dist/src/Runners/Runner.js +8 -8
  105. package/dist/src/Runners/Runner.js.map +1 -1
  106. package/dist/src/Runners/TestRunner.d.ts +4 -4
  107. package/dist/src/Runners/TestRunner.d.ts.map +1 -1
  108. package/dist/src/Runners/TestRunner.js +4 -4
  109. package/dist/src/Runners/TestRunner.js.map +1 -1
  110. package/dist/src/Runners/TestSuiteLoader.d.ts +4 -4
  111. package/dist/src/Runners/TestSuiteLoader.d.ts.map +1 -1
  112. package/dist/src/Runners/TestSuiteLoader.js +21 -18
  113. package/dist/src/Runners/TestSuiteLoader.js.map +1 -1
  114. package/dist/src/Runners/TestSuiteRunner.d.ts +6 -6
  115. package/dist/src/Runners/TestSuiteRunner.d.ts.map +1 -1
  116. package/dist/src/Runners/TestSuiteRunner.js +3 -3
  117. package/dist/src/Runners/TestSuiteRunner.js.map +1 -1
  118. package/dist/xunit.d.ts +3 -3
  119. package/dist/xunit.d.ts.map +1 -1
  120. package/dist/xunit.js.map +1 -1
  121. package/icon.svg +74 -75
  122. package/logo.svg +130 -130
  123. package/package.json +44 -37
  124. package/src/Assertions/Contains.ts +10 -10
  125. package/src/Assertions/Count.ts +11 -11
  126. package/src/Assertions/Defined.ts +11 -11
  127. package/src/Assertions/DoesNotContain.ts +11 -11
  128. package/src/Assertions/DoesNotThrow.ts +13 -13
  129. package/src/Assertions/Empty.ts +11 -11
  130. package/src/Assertions/Equal.ts +12 -12
  131. package/src/Assertions/False.ts +11 -11
  132. package/src/Assertions/InstanceOf.ts +13 -13
  133. package/src/Assertions/NotEmpty.ts +11 -11
  134. package/src/Assertions/NotEqual.ts +12 -12
  135. package/src/Assertions/NotNull.ts +11 -11
  136. package/src/Assertions/Null.ts +11 -11
  137. package/src/Assertions/StringContains.ts +11 -11
  138. package/src/Assertions/StringDoesNotContain.ts +12 -12
  139. package/src/Assertions/StringDoesNotEndWith.ts +13 -13
  140. package/src/Assertions/StringDoesNotStartWith.ts +12 -12
  141. package/src/Assertions/StringEndsWith.ts +13 -13
  142. package/src/Assertions/StringStartsWith.ts +12 -12
  143. package/src/Assertions/Throws.ts +11 -11
  144. package/src/Assertions/True.ts +11 -11
  145. package/src/Assertions/Undefined.ts +12 -12
  146. package/src/Assertions/index.ts +45 -45
  147. package/src/CLI.ts +96 -85
  148. package/src/Factory.ts +25 -25
  149. package/src/Framework/ResultType.ts +4 -4
  150. package/src/Framework/Test.ts +6 -6
  151. package/src/Framework/TestName.ts +7 -7
  152. package/src/Framework/TestResult.ts +3 -2
  153. package/src/Framework/TestSuite.ts +29 -18
  154. package/src/Framework/TestSuiteResults.ts +17 -16
  155. package/src/IO/FileSystem.ts +28 -29
  156. package/src/IO/Output.ts +21 -20
  157. package/src/Reporters/ConsoleReporter.ts +88 -87
  158. package/src/Reporters/FileReporter.ts +29 -29
  159. package/src/Reporters/JUnitReporter.ts +80 -80
  160. package/src/Reporters/ResultReporter.ts +20 -12
  161. package/src/Reporters/SonarReporter.ts +86 -86
  162. package/src/Reporters/XMLReporter.ts +6 -6
  163. package/src/Runners/Runner.ts +21 -21
  164. package/src/Runners/TestRunner.ts +34 -33
  165. package/src/Runners/TestSuiteLoader.ts +52 -45
  166. package/src/Runners/TestSuiteRunner.ts +27 -26
  167. package/tsconfig.json +26 -26
  168. package/xunit.ts +6 -6
@@ -1,100 +1,100 @@
1
- import TestSuiteResults from '../Framework/TestSuiteResults';
2
- import xml from 'xml';
3
- import {ResultType} from "../Framework/ResultType";
1
+ import TestSuiteResults from "../Framework/TestSuiteResults";
2
+ import xml from "xml";
3
+ import { ResultType } from "../Framework/ResultType";
4
4
  import TestResult from "../Framework/TestResult";
5
5
  import XMLReporter from "./XMLReporter";
6
6
  import path from "path";
7
7
 
8
8
  export default class SonarReporter extends XMLReporter {
9
- static readonly defaultFileName: string = 'sonar.xml';
9
+ static readonly defaultFileName: string = "sonar.xml";
10
10
 
11
- xml(results: Record<string, TestSuiteResults>): string {
12
- const data = {
13
- testExecutions: [
14
- {
15
- _attr: {
16
- version: 1
17
- }
18
- },
19
- ...Object.keys(results)
20
- .map(file => SonarReporter.testSuite(results[file], file))
21
- ]
22
- };
23
- return xml(data, {indent: ' '});
24
- }
11
+ private static testSuite(results: TestSuiteResults, file: string) {
12
+ return {
13
+ file: [
14
+ {
15
+ _attr: {
16
+ path: file.substring(file.split(path.sep)[0].length + 1).replace(/\.js$/, ".ts"),
17
+ }
18
+ },
19
+ ...Object.keys(results.results)
20
+ .map(test_name => SonarReporter.testCase(test_name, results.results[test_name]))
21
+ ]
22
+ };
23
+ }
25
24
 
26
- private static testSuite(results: TestSuiteResults, file: string) {
27
- return {
28
- file: [
29
- {
30
- _attr: {
31
- path: file.substr(file.split(path.sep)[0].length + 1).replace(/\.js$/, '.ts'),
32
- }
33
- },
34
- ...Object.keys(results.results)
35
- .map(test_name => SonarReporter.testCase(test_name, results.results[test_name]))
36
- ]
37
- };
38
- }
25
+ private static testCase(test_name: string, result: TestResult) {
26
+ const testcase: object[] = [
27
+ {
28
+ _attr: {
29
+ name: test_name,
30
+ duration: Math.round(result.duration)
31
+ }
32
+ }
33
+ ];
39
34
 
40
- private static testCase(test_name: string, result: TestResult) {
41
- const testcase: object[] = [
42
- {
43
- _attr: {
44
- name: test_name,
45
- duration: Math.round(result.duration)
46
- }
47
- }
48
- ];
35
+ const details = SonarReporter.details(result);
49
36
 
50
- const details = SonarReporter.details(result);
37
+ if (details !== null) {
38
+ testcase.push(details);
39
+ }
51
40
 
52
- if (details !== null) {
53
- testcase.push(details);
54
- }
55
-
56
-
57
- return {
58
- testCase: testcase
59
- };
60
- }
61
41
 
62
- private static details(result: TestResult): object|null {
63
- switch(result.type) {
64
- case ResultType.Incomplete:
65
- return {skipped: {}};
66
- case ResultType.Failed:
67
- return SonarReporter.failure(result);
68
- case ResultType.Error:
69
- return SonarReporter.error(result);
70
- default:
71
- return null;
72
- }
73
- }
42
+ return {
43
+ testCase: testcase
44
+ };
45
+ }
74
46
 
75
- private static failure(result: TestResult) {
76
- return {
77
- failure: [
78
- {
79
- _attr: {
80
- message: result.error?.message
81
- }
82
- },
83
- result.error?.stack
84
- ]
85
- };
86
- }
47
+ private static details(result: TestResult): object | null {
48
+ switch (result.type) {
49
+ case ResultType.Incomplete:
50
+ return { skipped: {} };
51
+ case ResultType.Failed:
52
+ return SonarReporter.failure(result);
53
+ case ResultType.Error:
54
+ return SonarReporter.error(result);
55
+ default:
56
+ return null;
57
+ }
58
+ }
87
59
 
88
- private static error(result: TestResult) {
89
- return {
90
- error: [
91
- {
92
- _attr: {
93
- message: result.error?.message
94
- }
95
- },
96
- result.error?.stack
97
- ]
98
- };
99
- }
60
+ private static failure(result: TestResult) {
61
+ return {
62
+ failure: [
63
+ {
64
+ _attr: {
65
+ message: result.error?.message
66
+ }
67
+ },
68
+ result.error?.stack
69
+ ]
70
+ };
71
+ }
72
+
73
+ private static error(result: TestResult) {
74
+ return {
75
+ error: [
76
+ {
77
+ _attr: {
78
+ message: result.error?.message
79
+ }
80
+ },
81
+ result.error?.stack
82
+ ]
83
+ };
84
+ }
85
+
86
+ xml(results: Record<string, TestSuiteResults>): string {
87
+ const data = {
88
+ testExecutions: [
89
+ {
90
+ _attr: {
91
+ version: 1
92
+ }
93
+ },
94
+ ...Object.keys(results)
95
+ .map(file => SonarReporter.testSuite(results[file], file))
96
+ ]
97
+ };
98
+ return xml(data, { indent: "\t" });
99
+ }
100
100
  }
@@ -2,10 +2,10 @@
2
2
  import TestSuiteResults from "../Framework/TestSuiteResults";
3
3
 
4
4
  export default abstract class XMLReporter extends FileReporter {
5
- async runCompleted(results: Record<string, TestSuiteResults>): Promise<void> {
6
- const xmlString = this.xml(results);
7
- await this.file_system.save(xmlString, this.path);
8
- }
9
-
10
- abstract xml(results: Record<string, TestSuiteResults>): string;
5
+ async runCompleted(results: Record<string, TestSuiteResults>): Promise<void> {
6
+ const xmlString = this.xml(results);
7
+ await this.file_system.save(xmlString, this.path);
8
+ }
9
+
10
+ abstract xml(results: Record<string, TestSuiteResults>): string;
11
11
  }
@@ -1,29 +1,29 @@
1
- import TestSuiteLoader from './TestSuiteLoader';
2
- import TestSuiteRunner from './TestSuiteRunner';
1
+ import TestSuiteLoader from "./TestSuiteLoader";
2
+ import TestSuiteRunner from "./TestSuiteRunner";
3
3
  import ResultReporter from "../Reporters/ResultReporter";
4
4
  import TestSuiteResults from "../Framework/TestSuiteResults";
5
- import {ResultType} from '../Framework/ResultType';
5
+ import { ResultType } from "../Framework/ResultType";
6
6
 
7
7
  export default class Runner {
8
8
 
9
- constructor(private readonly loader: TestSuiteLoader, private readonly runner: TestSuiteRunner, private readonly reporters: ReadonlyArray<ResultReporter>) {
10
- }
9
+ constructor(private readonly loader: TestSuiteLoader, private readonly runner: TestSuiteRunner, private readonly reporters: ReadonlyArray<ResultReporter>) {
10
+ }
11
11
 
12
- async runAll(dir: string): Promise<Record<string, TestSuiteResults>> {
13
- await Promise.all(this.reporters.map(r => r.runStarted()));
14
- const results: Record<string, TestSuiteResults> = {};
15
- const suites = await this.loader.loadTestSuites(dir);
16
- for (const file of Object.keys(suites)) {
17
- const suite = suites[file];
18
- results[file] = await this.runner.runSuite(suite);
19
- }
20
- await Promise.all(this.reporters.map(r => r.runCompleted(results)));
21
- return results;
22
- }
12
+ static allTestsPassed(results: Record<string, TestSuiteResults>): boolean {
13
+ const tests_with_results = Object.values(results).filter(result => result.total() > 0);
14
+ return tests_with_results.length > 0
15
+ && tests_with_results.filter(result => result.count(ResultType.Passed) < result.total()).length === 0;
16
+ }
23
17
 
24
- static allTestsPassed(results: Record<string, TestSuiteResults>): boolean {
25
- const tests_with_results = Object.values(results).filter(result => result.total() > 0);
26
- return tests_with_results.length > 0
27
- && tests_with_results.filter(result => result.count(ResultType.Passed) < result.total()).length === 0;
28
- }
18
+ async runAll(dir: string, filters: RegExp[]): Promise<Record<string, TestSuiteResults>> {
19
+ await Promise.all(this.reporters.map(r => r.runStarted()));
20
+ const results: Record<string, TestSuiteResults> = {};
21
+ const suites = await this.loader.loadTestSuites(dir, filters);
22
+ for (const file of Object.keys(suites)) {
23
+ const suite = suites[file];
24
+ results[file] = await this.runner.runSuite(suite, filters);
25
+ }
26
+ await Promise.all(this.reporters.map(r => r.runCompleted(results)));
27
+ return results;
28
+ }
29
29
  }
@@ -1,43 +1,44 @@
1
- import TestInfo from '../Framework/TestInfo';
2
- import TestSuite from '../Framework/TestSuite';
3
- import { ResultType } from '../Framework/ResultType';
4
- import ResultReporter from '../Reporters/ResultReporter';
1
+ import TestInfo from "../Framework/TestInfo";
2
+ import TestSuite from "../Framework/TestSuite";
3
+ import { ResultType } from "../Framework/ResultType";
4
+ import ResultReporter from "../Reporters/ResultReporter";
5
5
  import TestResult from "../Framework/TestResult";
6
- import {AssertionError} from "assert";
6
+ import { AssertionError } from "assert";
7
7
 
8
8
  export default class TestRunner {
9
9
 
10
- constructor(private readonly reporters: ReadonlyArray<ResultReporter>) { }
10
+ constructor(private readonly reporters: ReadonlyArray<ResultReporter>) {
11
+ }
11
12
 
12
- async runTest(name: string, info: TestInfo, suite: TestSuite): Promise<TestResult> {
13
- await Promise.all(this.reporters.map(r => r.testStarted(suite, name)));
14
- if (info.value === undefined) {
15
- await Promise.all(this.reporters.map(r => r.testIncomplete(suite, name)));
16
- return new TestResult(ResultType.Incomplete, 0);
17
- }
13
+ private static msSince(start: [ number, number ]) {
14
+ const duration = process.hrtime(start);
15
+ return duration[0] * 1_000 + duration[1] / 1_000_000;
16
+ }
18
17
 
19
- const start = process.hrtime();
20
- try {
21
- await info.value.call(suite);
22
- const duration = TestRunner.msSince(start);
23
- await Promise.all(this.reporters.map(r => r.testPassed(suite, name, duration)));
24
- return new TestResult(ResultType.Passed, duration);
18
+ async runTest(name: string, info: TestInfo, suite: TestSuite): Promise<TestResult> {
19
+ await Promise.all(this.reporters.map(r => r.testStarted(suite, name)));
20
+ if (info.value === undefined) {
21
+ await Promise.all(this.reporters.map(r => r.testIncomplete(suite, name)));
22
+ return new TestResult(ResultType.Incomplete, 0);
23
+ }
25
24
 
26
- } catch (error) {
27
- const duration = TestRunner.msSince(start);
28
- const typedError = error as Error;
29
- if (typedError instanceof AssertionError) {
30
- await Promise.all(this.reporters.map(r => r.testFailed(suite, name, typedError, duration)));
31
- return new TestResult(ResultType.Failed, duration, typedError);
32
- }
25
+ const start = process.hrtime();
26
+ try {
27
+ await info.value.call(suite);
28
+ const duration = TestRunner.msSince(start);
29
+ await Promise.all(this.reporters.map(r => r.testPassed(suite, name, duration)));
30
+ return new TestResult(ResultType.Passed, duration);
33
31
 
34
- await Promise.all(this.reporters.map(r => r.testErrored(suite, name, typedError, duration)));
35
- return new TestResult(ResultType.Error, duration, typedError);
36
- }
37
- }
32
+ } catch (error) {
33
+ const duration = TestRunner.msSince(start);
34
+ const typedError = error as Error;
35
+ if (typedError instanceof AssertionError) {
36
+ await Promise.all(this.reporters.map(r => r.testFailed(suite, name, typedError, duration)));
37
+ return new TestResult(ResultType.Failed, duration, typedError);
38
+ }
38
39
 
39
- private static msSince(start: [number, number]) {
40
- const duration = process.hrtime(start);
41
- return duration[0] * 1_000 + duration[1] / 1_000_000;
42
- }
40
+ await Promise.all(this.reporters.map(r => r.testErrored(suite, name, typedError, duration)));
41
+ return new TestResult(ResultType.Error, duration, typedError);
42
+ }
43
+ }
43
44
  }
@@ -1,49 +1,56 @@
1
- import TestSuite from '../Framework/TestSuite';
2
- import FileSystem from '../IO/FileSystem';
3
- import path from 'path';
1
+ import TestSuite from "../Framework/TestSuite";
2
+ import FileSystem from "../IO/FileSystem";
3
+ import path from "path";
4
4
 
5
5
  export default class TestSuiteLoader {
6
6
 
7
- constructor(private readonly file_system: FileSystem) { }
8
-
9
- async loadTestSuites(dir: string): Promise<Record<string, TestSuite>> {
10
- const files = (await this.file_system.getFiles(dir))
11
- .filter((file) => FileSystem.extension(file) === FileSystem.extension(__filename));
12
- const suites: Record<string, TestSuite> = {};
13
- for (const file of files) {
14
- const suite = await TestSuiteLoader.loadTestSuite(file);
15
- if (suite !== undefined && suite !== null) {
16
- suites[file] = suite;
17
- }
18
- }
19
- return suites;
20
- }
21
-
22
- static async loadTestSuite(file: string) {
23
- const module_path = TestSuiteLoader.getModulePath(__dirname, file);
24
- const test_class = await import(module_path);
25
- if (!(test_class.default.prototype instanceof TestSuite)) {
26
- return null;
27
- }
28
-
29
- const tests = test_class.default.prototype.getTests();
30
- const suite: TestSuite = new test_class.default();
31
- suite.setTests(tests);
32
- return suite;
33
- }
34
-
35
- static getModulePath(current_dir: string, file: string) {
36
- const root = TestSuiteLoader.isFromNodeModules(path.resolve(current_dir))
37
- ? `..${path.sep}..${path.sep}..${path.sep}..${path.sep}..`
38
- : `..${path.sep}..${path.sep}..`;
39
- const extension = FileSystem.extension(file);
40
- const module_name = extension.length > 0
41
- ? file.substr(0, file.length - extension.length - 1)
42
- : file;
43
- return `${root}${path.sep}${module_name}`;
44
- }
45
-
46
- static isFromNodeModules(dir: string) {
47
- return dir.indexOf('node_modules') !== -1;
48
- }
7
+ constructor(private readonly file_system: FileSystem) {
8
+ }
9
+
10
+ static async loadTestSuite(file: string, filters: RegExp[]) {
11
+ const module_path = TestSuiteLoader.getModulePath(__dirname, file);
12
+ const test_class = await import(module_path);
13
+ if (!(test_class.default.prototype instanceof TestSuite)) {
14
+ return null;
15
+ }
16
+
17
+ const tests = test_class.default.prototype.getTests(filters);
18
+ if (Object.keys(tests).length === 0) {
19
+ return null;
20
+ }
21
+
22
+ const suite: TestSuite = new test_class.default();
23
+ suite.setTests(tests);
24
+ return suite;
25
+ }
26
+
27
+ static getModulePath(current_dir: string, file: string) {
28
+ const root = TestSuiteLoader.isFromNodeModules(path.resolve(current_dir))
29
+ ? `..${path.sep}..${path.sep}..${path.sep}..${path.sep}..`
30
+ : `..${path.sep}..${path.sep}..`;
31
+ const extension = FileSystem.extension(file);
32
+ const module_name = extension.length > 0
33
+ ? file.substring(0, file.length - extension.length - 1)
34
+ : file;
35
+ return `${root}${path.sep}${module_name}`;
36
+ }
37
+
38
+ static isFromNodeModules(dir: string) {
39
+ return dir.indexOf("node_modules") !== -1;
40
+ }
41
+
42
+ async loadTestSuites(dir: string, filters: RegExp[]): Promise<Record<string, TestSuite>> {
43
+ const suites: Record<string, TestSuite> = {};
44
+
45
+ const files = (await this.file_system.getFiles(dir))
46
+ .filter((file) => FileSystem.extension(file) === FileSystem.extension(__filename));
47
+
48
+ for (const file of files) {
49
+ const suite = await TestSuiteLoader.loadTestSuite(file, filters);
50
+ if (suite !== undefined && suite !== null) {
51
+ suites[file] = suite;
52
+ }
53
+ }
54
+ return suites;
55
+ }
49
56
  }
@@ -1,34 +1,35 @@
1
- import ResultReporter from '../Reporters/ResultReporter';
2
- import TestSuite from '../Framework/TestSuite';
3
- import TestSuiteResults from '../Framework/TestSuiteResults';
4
- import TestInfo from '../Framework/TestInfo';
5
- import TestRunner from './TestRunner';
1
+ import ResultReporter from "../Reporters/ResultReporter";
2
+ import TestSuite from "../Framework/TestSuite";
3
+ import TestSuiteResults from "../Framework/TestSuiteResults";
4
+ import TestInfo from "../Framework/TestInfo";
5
+ import TestRunner from "./TestRunner";
6
6
 
7
7
  export default class TestSuiteRunner {
8
8
 
9
- constructor(private readonly runner: TestRunner, private readonly reporters: ReadonlyArray<ResultReporter>) { }
9
+ constructor(private readonly runner: TestRunner, private readonly reporters: ReadonlyArray<ResultReporter>) {
10
+ }
10
11
 
11
- async runSuite(suite: TestSuite) {
12
- await Promise.all(this.reporters.map(r => r.suiteStarted(suite)));
13
- const tests = suite.getTests();
14
- const results = await this.runTests(suite, tests);
15
- await Promise.all(this.reporters.map(r => r.suiteCompleted(suite, results)));
16
- return results;
17
- }
12
+ async runSuite(suite: TestSuite, filters: RegExp[]) {
13
+ await Promise.all(this.reporters.map(r => r.suiteStarted(suite)));
14
+ const tests = suite.getTests(filters);
15
+ const results = await this.runTests(suite, tests);
16
+ await Promise.all(this.reporters.map(r => r.suiteCompleted(suite, results)));
17
+ return results;
18
+ }
18
19
 
19
- async runTests(suite: TestSuite, tests: Record<string, TestInfo>) {
20
- const results = new TestSuiteResults(suite);
21
- if (tests === undefined || tests === null || Object.keys(tests).length === 0) {
22
- await Promise.all(this.reporters.map(r => r.testIncomplete(suite, '(no tests found)')));
23
- return results;
24
- }
20
+ async runTests(suite: TestSuite, tests: Record<string, TestInfo>) {
21
+ const results = new TestSuiteResults(suite);
22
+ if (tests === undefined || tests === null || Object.keys(tests).length === 0) {
23
+ await Promise.all(this.reporters.map(r => r.testIncomplete(suite, "(no tests found)")));
24
+ return results;
25
+ }
25
26
 
26
- const test_names = Object.keys(tests);
27
- for (const name of test_names) {
28
- const result = await this.runner.runTest(name, tests[name], suite);
29
- results.addResult(name, result);
30
- }
27
+ const test_names = Object.keys(tests);
28
+ for (const name of test_names) {
29
+ const result = await this.runner.runTest(name, tests[name], suite);
30
+ results.addResult(name, result);
31
+ }
31
32
 
32
- return results;
33
- }
33
+ return results;
34
+ }
34
35
  }
package/tsconfig.json CHANGED
@@ -1,28 +1,28 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ES2015",
4
- "module": "CommonJS",
5
- "outDir": "./dist/",
6
- "strict": true,
7
- "sourceMap": true,
8
- "declaration": true,
9
- "declarationMap": true,
10
- "esModuleInterop": true,
11
- "experimentalDecorators": true,
12
- "emitDecoratorMetadata": true
13
- },
14
- "files": [
15
- "xunit.ts",
16
- "cli.ts",
17
- "tsdoc.ts"
18
- ],
19
- "include": [
20
- "src/**/*.ts",
21
- "tests/**/*.ts",
22
- "TSDoc/**/*.ts"
23
- ],
24
- "exclude": [
25
- "node_modules",
26
- "dist"
27
- ]
2
+ "compilerOptions": {
3
+ "target": "ES2015",
4
+ "module": "CommonJS",
5
+ "outDir": "./dist/",
6
+ "strict": true,
7
+ "sourceMap": true,
8
+ "declaration": true,
9
+ "declarationMap": true,
10
+ "esModuleInterop": true,
11
+ "experimentalDecorators": true,
12
+ "emitDecoratorMetadata": true
13
+ },
14
+ "files": [
15
+ "xunit.ts",
16
+ "cli.ts",
17
+ "tsdoc.ts"
18
+ ],
19
+ "include": [
20
+ "src/**/*.ts",
21
+ "tests/**/*.ts",
22
+ "TSDoc/**/*.ts"
23
+ ],
24
+ "exclude": [
25
+ "node_modules",
26
+ "dist"
27
+ ]
28
28
  }
package/xunit.ts CHANGED
@@ -1,9 +1,9 @@
1
- import Test from './src/Framework/Test';
2
- import TestSuite from './src/Framework/TestSuite';
3
- import Assert from './src/Assertions';
1
+ import Test from "./src/Framework/Test";
2
+ import TestSuite from "./src/Framework/TestSuite";
3
+ import Assert from "./src/Assertions";
4
4
 
5
5
  export {
6
- Test,
7
- TestSuite,
8
- Assert
6
+ Test,
7
+ TestSuite,
8
+ Assert
9
9
  };