xunit.ts 0.12.0 → 1.0.1

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 (185) hide show
  1. package/.editorconfig +24 -0
  2. package/README.md +27 -269
  3. package/SECURITY.md +11 -0
  4. package/cli.ts +2 -1
  5. package/dist/cli.js +2 -1
  6. package/dist/cli.js.map +1 -1
  7. package/dist/src/Assertions/Contains.d.ts +16 -1
  8. package/dist/src/Assertions/Contains.d.ts.map +1 -1
  9. package/dist/src/Assertions/Contains.js +15 -0
  10. package/dist/src/Assertions/Contains.js.map +1 -1
  11. package/dist/src/Assertions/Count.d.ts +16 -1
  12. package/dist/src/Assertions/Count.d.ts.map +1 -1
  13. package/dist/src/Assertions/Count.js +15 -0
  14. package/dist/src/Assertions/Count.js.map +1 -1
  15. package/dist/src/Assertions/Defined.d.ts +15 -1
  16. package/dist/src/Assertions/Defined.d.ts.map +1 -1
  17. package/dist/src/Assertions/Defined.js +17 -3
  18. package/dist/src/Assertions/Defined.js.map +1 -1
  19. package/dist/src/Assertions/DoesNotContain.d.ts +17 -0
  20. package/dist/src/Assertions/DoesNotContain.d.ts.map +1 -0
  21. package/dist/src/Assertions/DoesNotContain.js +30 -0
  22. package/dist/src/Assertions/DoesNotContain.js.map +1 -0
  23. package/dist/src/Assertions/DoesNotThrow.d.ts +14 -0
  24. package/dist/src/Assertions/DoesNotThrow.d.ts.map +1 -1
  25. package/dist/src/Assertions/DoesNotThrow.js +15 -0
  26. package/dist/src/Assertions/DoesNotThrow.js.map +1 -1
  27. package/dist/src/Assertions/Empty.d.ts +15 -1
  28. package/dist/src/Assertions/Empty.d.ts.map +1 -1
  29. package/dist/src/Assertions/Empty.js +17 -3
  30. package/dist/src/Assertions/Empty.js.map +1 -1
  31. package/dist/src/Assertions/Equal.d.ts +15 -0
  32. package/dist/src/Assertions/Equal.d.ts.map +1 -1
  33. package/dist/src/Assertions/Equal.js +16 -1
  34. package/dist/src/Assertions/Equal.js.map +1 -1
  35. package/dist/src/Assertions/False.d.ts +15 -1
  36. package/dist/src/Assertions/False.d.ts.map +1 -1
  37. package/dist/src/Assertions/False.js +17 -3
  38. package/dist/src/Assertions/False.js.map +1 -1
  39. package/dist/src/Assertions/InstanceOf.d.ts +16 -1
  40. package/dist/src/Assertions/InstanceOf.d.ts.map +1 -1
  41. package/dist/src/Assertions/InstanceOf.js +19 -4
  42. package/dist/src/Assertions/InstanceOf.js.map +1 -1
  43. package/dist/src/Assertions/NotEmpty.d.ts +15 -1
  44. package/dist/src/Assertions/NotEmpty.d.ts.map +1 -1
  45. package/dist/src/Assertions/NotEmpty.js +17 -3
  46. package/dist/src/Assertions/NotEmpty.js.map +1 -1
  47. package/dist/src/Assertions/NotEqual.d.ts +15 -0
  48. package/dist/src/Assertions/NotEqual.d.ts.map +1 -1
  49. package/dist/src/Assertions/NotEqual.js +20 -1
  50. package/dist/src/Assertions/NotEqual.js.map +1 -1
  51. package/dist/src/Assertions/NotNull.d.ts +15 -1
  52. package/dist/src/Assertions/NotNull.d.ts.map +1 -1
  53. package/dist/src/Assertions/NotNull.js +17 -3
  54. package/dist/src/Assertions/NotNull.js.map +1 -1
  55. package/dist/src/Assertions/Null.d.ts +15 -1
  56. package/dist/src/Assertions/Null.d.ts.map +1 -1
  57. package/dist/src/Assertions/Null.js +17 -3
  58. package/dist/src/Assertions/Null.js.map +1 -1
  59. package/dist/src/Assertions/StringContains.d.ts +15 -0
  60. package/dist/src/Assertions/StringContains.d.ts.map +1 -1
  61. package/dist/src/Assertions/StringContains.js +16 -1
  62. package/dist/src/Assertions/StringContains.js.map +1 -1
  63. package/dist/src/Assertions/StringDoesNotContain.d.ts +17 -0
  64. package/dist/src/Assertions/StringDoesNotContain.d.ts.map +1 -0
  65. package/dist/src/Assertions/StringDoesNotContain.js +30 -0
  66. package/dist/src/Assertions/StringDoesNotContain.js.map +1 -0
  67. package/dist/src/Assertions/StringDoesNotEndWith.d.ts +17 -0
  68. package/dist/src/Assertions/StringDoesNotEndWith.d.ts.map +1 -0
  69. package/dist/src/Assertions/StringDoesNotEndWith.js +32 -0
  70. package/dist/src/Assertions/StringDoesNotEndWith.js.map +1 -0
  71. package/dist/src/Assertions/StringDoesNotStartWith.d.ts +17 -0
  72. package/dist/src/Assertions/StringDoesNotStartWith.d.ts.map +1 -0
  73. package/dist/src/Assertions/StringDoesNotStartWith.js +30 -0
  74. package/dist/src/Assertions/StringDoesNotStartWith.js.map +1 -0
  75. package/dist/src/Assertions/StringEndsWith.d.ts +15 -0
  76. package/dist/src/Assertions/StringEndsWith.d.ts.map +1 -1
  77. package/dist/src/Assertions/StringEndsWith.js +18 -1
  78. package/dist/src/Assertions/StringEndsWith.js.map +1 -1
  79. package/dist/src/Assertions/StringStartsWith.d.ts +15 -0
  80. package/dist/src/Assertions/StringStartsWith.d.ts.map +1 -1
  81. package/dist/src/Assertions/StringStartsWith.js +15 -0
  82. package/dist/src/Assertions/StringStartsWith.js.map +1 -1
  83. package/dist/src/Assertions/Throws.d.ts +14 -0
  84. package/dist/src/Assertions/Throws.d.ts.map +1 -1
  85. package/dist/src/Assertions/Throws.js +14 -0
  86. package/dist/src/Assertions/Throws.js.map +1 -1
  87. package/dist/src/Assertions/True.d.ts +15 -1
  88. package/dist/src/Assertions/True.d.ts.map +1 -1
  89. package/dist/src/Assertions/True.js +17 -3
  90. package/dist/src/Assertions/True.js.map +1 -1
  91. package/dist/src/Assertions/Undefined.d.ts +15 -1
  92. package/dist/src/Assertions/Undefined.d.ts.map +1 -1
  93. package/dist/src/Assertions/Undefined.js +17 -3
  94. package/dist/src/Assertions/Undefined.js.map +1 -1
  95. package/dist/src/Assertions/index.d.ts +4 -4
  96. package/dist/src/Assertions/index.d.ts.map +1 -1
  97. package/dist/src/Assertions/index.js +8 -8
  98. package/dist/src/Assertions/index.js.map +1 -1
  99. package/dist/src/CLI.d.ts +4 -1
  100. package/dist/src/CLI.d.ts.map +1 -1
  101. package/dist/src/CLI.js +9 -7
  102. package/dist/src/CLI.js.map +1 -1
  103. package/dist/src/Factory.d.ts +3 -2
  104. package/dist/src/Factory.d.ts.map +1 -1
  105. package/dist/src/Factory.js +4 -4
  106. package/dist/src/Factory.js.map +1 -1
  107. package/dist/src/Framework/Test.d.ts +14 -0
  108. package/dist/src/Framework/Test.d.ts.map +1 -1
  109. package/dist/src/Framework/Test.js +14 -0
  110. package/dist/src/Framework/Test.js.map +1 -1
  111. package/dist/src/Framework/TestSuite.d.ts +13 -4
  112. package/dist/src/Framework/TestSuite.d.ts.map +1 -1
  113. package/dist/src/Framework/TestSuite.js +9 -0
  114. package/dist/src/Framework/TestSuite.js.map +1 -1
  115. package/dist/src/Reporters/JUnitReporter.js +1 -1
  116. package/dist/src/Reporters/JUnitReporter.js.map +1 -1
  117. package/dist/src/Reporters/SonarReporter.d.ts.map +1 -1
  118. package/dist/src/Reporters/SonarReporter.js +3 -2
  119. package/dist/src/Reporters/SonarReporter.js.map +1 -1
  120. package/dist/src/Runners/Runner.d.ts +1 -1
  121. package/dist/src/Runners/Runner.d.ts.map +1 -1
  122. package/dist/src/Runners/Runner.js.map +1 -1
  123. package/dist/src/Runners/TestRunner.d.ts +1 -1
  124. package/dist/src/Runners/TestRunner.d.ts.map +1 -1
  125. package/dist/src/Runners/TestRunner.js +6 -5
  126. package/dist/src/Runners/TestRunner.js.map +1 -1
  127. package/dist/src/Runners/TestSuiteRunner.d.ts +1 -1
  128. package/dist/src/Runners/TestSuiteRunner.d.ts.map +1 -1
  129. package/dist/src/Runners/TestSuiteRunner.js.map +1 -1
  130. package/icon.svg +83 -0
  131. package/logo.svg +154 -0
  132. package/package.json +15 -9
  133. package/sonar-project.properties +1 -1
  134. package/src/Assertions/Contains.ts +16 -1
  135. package/src/Assertions/Count.ts +16 -1
  136. package/src/Assertions/Defined.ts +17 -3
  137. package/src/Assertions/DoesNotContain.ts +28 -0
  138. package/src/Assertions/DoesNotThrow.ts +15 -0
  139. package/src/Assertions/Empty.ts +17 -3
  140. package/src/Assertions/Equal.ts +15 -0
  141. package/src/Assertions/False.ts +17 -3
  142. package/src/Assertions/InstanceOf.ts +19 -4
  143. package/src/Assertions/NotEmpty.ts +17 -3
  144. package/src/Assertions/NotEqual.ts +17 -1
  145. package/src/Assertions/NotNull.ts +17 -3
  146. package/src/Assertions/Null.ts +17 -3
  147. package/src/Assertions/StringContains.ts +17 -2
  148. package/src/Assertions/StringDoesNotContain.ts +28 -0
  149. package/src/Assertions/StringDoesNotEndWith.ts +30 -0
  150. package/src/Assertions/StringDoesNotStartWith.ts +28 -0
  151. package/src/Assertions/StringEndsWith.ts +19 -2
  152. package/src/Assertions/StringStartsWith.ts +15 -0
  153. package/src/Assertions/Throws.ts +14 -0
  154. package/src/Assertions/True.ts +17 -3
  155. package/src/Assertions/Undefined.ts +17 -3
  156. package/src/Assertions/index.ts +4 -4
  157. package/src/CLI.ts +6 -5
  158. package/src/Factory.ts +6 -6
  159. package/src/Framework/Test.ts +14 -0
  160. package/src/Framework/TestSuite.ts +9 -0
  161. package/src/Reporters/SonarReporter.ts +2 -1
  162. package/src/Runners/Runner.ts +1 -1
  163. package/src/Runners/TestRunner.ts +7 -6
  164. package/src/Runners/TestSuiteRunner.ts +1 -1
  165. package/tsconfig.json +4 -2
  166. package/dist/src/Assertions/NotContains.d.ts +0 -2
  167. package/dist/src/Assertions/NotContains.d.ts.map +0 -1
  168. package/dist/src/Assertions/NotContains.js +0 -15
  169. package/dist/src/Assertions/NotContains.js.map +0 -1
  170. package/dist/src/Assertions/StringNotContains.d.ts +0 -2
  171. package/dist/src/Assertions/StringNotContains.d.ts.map +0 -1
  172. package/dist/src/Assertions/StringNotContains.js +0 -15
  173. package/dist/src/Assertions/StringNotContains.js.map +0 -1
  174. package/dist/src/Assertions/StringNotEndsWith.d.ts +0 -2
  175. package/dist/src/Assertions/StringNotEndsWith.d.ts.map +0 -1
  176. package/dist/src/Assertions/StringNotEndsWith.js +0 -15
  177. package/dist/src/Assertions/StringNotEndsWith.js.map +0 -1
  178. package/dist/src/Assertions/StringNotStartsWith.d.ts +0 -2
  179. package/dist/src/Assertions/StringNotStartsWith.d.ts.map +0 -1
  180. package/dist/src/Assertions/StringNotStartsWith.js +0 -15
  181. package/dist/src/Assertions/StringNotStartsWith.js.map +0 -1
  182. package/src/Assertions/NotContains.ts +0 -13
  183. package/src/Assertions/StringNotContains.ts +0 -13
  184. package/src/Assertions/StringNotEndsWith.ts +0 -13
  185. package/src/Assertions/StringNotStartsWith.ts +0 -13
@@ -1,13 +1,27 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function Defined(value: any, message?: string) {
4
- if(value !== undefined) {
3
+ /**
4
+ * Asserts that a value is defined (any value other than `undefined`)
5
+ *
6
+ * @remarks
7
+ * Passes if `expression` does not evaluate to `undefined`
8
+ *
9
+ * Fails if `expression` evaluates to `undefined`
10
+ *
11
+ * @param expression the value to check
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.defined(expression);
16
+ */
17
+ export default function Defined(expression: any, message?: string) {
18
+ if(expression !== undefined) {
5
19
  return;
6
20
  }
7
21
 
8
22
  throw new AssertionError({
9
23
  message: message || 'Expected expression to be defined, but expression is undefined',
10
24
  expected: '(not undefined expression)',
11
- actual: value
25
+ actual: expression
12
26
  });
13
27
  }
@@ -0,0 +1,28 @@
1
+ import { AssertionError } from "assert";
2
+
3
+ /**
4
+ * Asserts that an array does not contain a given element
5
+ *
6
+ * @remarks
7
+ * Passes if array `haystack` does not contain an element with a value of `needle`
8
+ *
9
+ * Fails if array `haystack` contains an element with a value of `needle`
10
+ *
11
+ * @param needle the element to find
12
+ * @param haystack the array to search
13
+ * @param message (optional) message to display on failure
14
+ *
15
+ * @example
16
+ * this.assert.doesNotContain(needle, haystack);
17
+ */
18
+ export default function DoesNotContain<T>(needle: T, haystack: ReadonlyArray<T>, message?: string) {
19
+ if(!haystack.includes(needle)) {
20
+ return;
21
+ }
22
+
23
+ throw new AssertionError({
24
+ message: message || 'Expected array not containing expression, but array contained expression',
25
+ expected: needle,
26
+ actual: haystack
27
+ });
28
+ }
@@ -1,8 +1,23 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
+ /**
4
+ * Asserts that an expression does not throw an error/exception
5
+ *
6
+ * @remarks
7
+ * Passes if calling `expression` does not throw an error/exception
8
+ *
9
+ * Fails if calling `expression` throws an error/exception
10
+ *
11
+ * @param expression the expression to run
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.doesNotThrow(() => expression);
16
+ */
3
17
  export default function DoesNotThrow(expression: () => any, message?: string) {
4
18
  try {
5
19
  expression();
20
+ return;
6
21
  } catch (exception) {
7
22
  throw new AssertionError({
8
23
  message: message || 'Expected expression to not throw exception, but expression did throw exception',
@@ -1,13 +1,27 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function Empty(value: any, message?: string) {
4
- if(value.length === 0) {
3
+ /**
4
+ * Asserts that an array is empty
5
+ *
6
+ * @remarks
7
+ * Passes if `array` contains zero elements
8
+ *
9
+ * Fails if `array` contains any elements
10
+ *
11
+ * @param array the array to check
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.empty(array);
16
+ */
17
+ export default function Empty(array: ReadonlyArray<any>, message?: string) {
18
+ if(array.length === 0) {
5
19
  return;
6
20
  }
7
21
 
8
22
  throw new AssertionError({
9
23
  message: message || 'Expected expression to be empty, but expression was not empty',
10
24
  expected: [],
11
- actual: value
25
+ actual: array
12
26
  })
13
27
  }
@@ -1,6 +1,21 @@
1
1
  import { AssertionError } from "assert";
2
2
  import equal from 'lodash.isequal';
3
3
 
4
+ /**
5
+ * Asserts that two values are equal
6
+ *
7
+ * @remarks
8
+ * Passes if `actual` and `expected` evaluate to equal values
9
+ *
10
+ * Fails if `actual` and `expected` do not evaluate to equal values
11
+ *
12
+ * @param expected the expected value
13
+ * @param actual the actual value
14
+ * @param message (optional) message to display on failure
15
+ *
16
+ * @example
17
+ * this.assert.equal(expected, actual);
18
+ */
4
19
  export default function Equal(expected: any, actual: any, message?: string) {
5
20
  if(equal(actual, expected)) {
6
21
  return;
@@ -1,13 +1,27 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function False(value: any, message?: string) {
4
- if(value === false) {
3
+ /**
4
+ * Asserts that a given value is equal to `false`
5
+ *
6
+ * @remarks
7
+ * Passes if `expression` evaluates to `false`
8
+ *
9
+ * Fails if `expression` does not evaluate to `false`
10
+ *
11
+ * @param expression the value to check
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.false(expression);
16
+ */
17
+ export default function False(expression: any, message?: string) {
18
+ if(expression === false) {
5
19
  return;
6
20
  }
7
21
 
8
22
  throw new AssertionError({
9
23
  message: message || 'Expected expression to be false, but expression is not false',
10
24
  expected: false,
11
- actual: value
25
+ actual: expression
12
26
  });
13
27
  }
@@ -1,13 +1,28 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function InstanceOf<T>(type: any, value: any, message?: string) {
4
- if (value instanceof type) {
3
+ /**
4
+ * Asserts that a value is an instance of a certain type
5
+ *
6
+ * @remarks
7
+ * Passes if `object`'s type matches `type`
8
+ *
9
+ * Fails if `object`'s type does not match `type`
10
+ *
11
+ * @param type the expected type of the value
12
+ * @param expression the value to check
13
+ * @param message (optional) message to display on failure
14
+ *
15
+ * @example
16
+ * this.assert.instanceOf(type, object);
17
+ */
18
+ export default function InstanceOf<T>(type: any, expression: any, message?: string) {
19
+ if (expression instanceof type) {
5
20
  return;
6
21
  }
7
22
 
8
23
  throw new AssertionError({
9
- message: message || `Expected expression of type, but was ${typeof value}`,
24
+ message: message || `Expected expression of type, but was ${typeof expression}`,
10
25
  expected: type,
11
- actual: typeof value
26
+ actual: typeof expression
12
27
  })
13
28
  }
@@ -1,13 +1,27 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function NotEmpty(value: any, message?: string) {
4
- if(value.length > 0) {
3
+ /**
4
+ * Asserts that an array is not empty
5
+ *
6
+ * @remarks
7
+ * Passes if `array` contains any elements
8
+ *
9
+ * Fails if `array` contains zero elements
10
+ *
11
+ * @param array the array to check
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.notEmpty(array);
16
+ */
17
+ export default function NotEmpty(array: ReadonlyArray<any>, message?: string) {
18
+ if(array.length > 0) {
5
19
  return;
6
20
  }
7
21
 
8
22
  throw new AssertionError({
9
23
  message: message || 'Expected expression to be not empty, but expression was empty',
10
24
  expected: '(non-empty expression)',
11
- actual: value
25
+ actual: array
12
26
  })
13
27
  }
@@ -1,7 +1,23 @@
1
1
  import { AssertionError } from "assert";
2
+ import equal from 'lodash.isequal';
2
3
 
4
+ /**
5
+ * Asserts that two values are not equal
6
+ *
7
+ * @remarks
8
+ * Passes if `actual` and `expected` do not evaluate to equal values
9
+ *
10
+ * Fails if `actual` and `expected` evaluate to equal values
11
+ *
12
+ * @param expected the expected value
13
+ * @param actual the actual value
14
+ * @param message (optional) message to display on failure
15
+ *
16
+ * @example
17
+ * this.assert.notEqual(expected, actual);
18
+ */
3
19
  export default function NotEqual(expected: any, actual: any, message?: string) {
4
- if(actual !== expected) {
20
+ if(!equal(actual, expected)) {
5
21
  return;
6
22
  }
7
23
 
@@ -1,13 +1,27 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function NotNull(value: any, message?: string) {
4
- if(value !== null) {
3
+ /**
4
+ * Asserts that a value is not `null`
5
+ *
6
+ * @remarks
7
+ * Passes if `expression` does not evaluate to `null`
8
+ *
9
+ * Fails if `expression` evaluates to `null`
10
+ *
11
+ * @param expression the value to check
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.notNull(expression);
16
+ */
17
+ export default function NotNull(expression: any, message?: string) {
18
+ if(expression !== null) {
5
19
  return;
6
20
  }
7
21
 
8
22
  throw new AssertionError({
9
23
  message: message || 'Expected expression to be not null, but expression is null',
10
24
  expected: '(non-null expression)',
11
- actual: value
25
+ actual: expression
12
26
  });
13
27
  }
@@ -1,13 +1,27 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function Null(value: any, message?: string) {
4
- if(value === null) {
3
+ /**
4
+ * Asserts that a value is `null`
5
+ *
6
+ * @remarks
7
+ * Passes if `expression` evaluates to `null`
8
+ *
9
+ * Fails if `expression` does not evaluate to `null`
10
+ *
11
+ * @param expression the value to check
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.null(expression);
16
+ */
17
+ export default function Null(expression: any, message?: string) {
18
+ if(expression === null) {
5
19
  return;
6
20
  }
7
21
 
8
22
  throw new AssertionError({
9
23
  message: message || 'Expected expression to be null, but expression is not null',
10
24
  expected: null,
11
- actual: value
25
+ actual: expression
12
26
  });
13
27
  }
@@ -1,7 +1,22 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function StringContains(needle: string, haystack: string|null, message?: string) {
4
- if(haystack !== undefined && haystack !== null && haystack.indexOf(needle) !== -1) {
3
+ /**
4
+ * Asserts that a string contains a given substring
5
+ *
6
+ * @remarks
7
+ * Passes if `needle` is a substring of `haystack`
8
+ *
9
+ * Fails if `needle` is not a substring of `haystack`
10
+ *
11
+ * @param needle the substring to find
12
+ * @param haystack the string to search
13
+ * @param message (optional) message to display on failure
14
+ *
15
+ * @example
16
+ * this.assert.stringContains(needle, haystack);
17
+ */
18
+ export default function StringContains(needle: string, haystack: string | null, message?: string) {
19
+ if (haystack !== undefined && haystack !== null && haystack.indexOf(needle) > -1) {
5
20
  return;
6
21
  }
7
22
 
@@ -0,0 +1,28 @@
1
+ import { AssertionError } from "assert";
2
+
3
+ /**
4
+ * Asserts that a string does not contain a given substring
5
+ *
6
+ * @remarks
7
+ * Passes if `needle` is not a substring of `haystack`
8
+ *
9
+ * Fails if `needle` is a substring of `haystack`
10
+ *
11
+ * @param needle the substring to find
12
+ * @param haystack the string to search
13
+ * @param message (optional) message to display on failure
14
+ *
15
+ * @example
16
+ * this.assert.stringDoesNotContain(needle, haystack);
17
+ */
18
+ export default function StringDoesNotContain(needle: string, haystack: string|null, message?: string) {
19
+ if(haystack === undefined || haystack === null || haystack.indexOf(needle) === -1) {
20
+ return;
21
+ }
22
+
23
+ throw new AssertionError({
24
+ message: message || 'Expected string not containing expression, but string did contain expression',
25
+ expected: needle,
26
+ actual: haystack
27
+ });
28
+ }
@@ -0,0 +1,30 @@
1
+ import { AssertionError } from "assert";
2
+
3
+ /**
4
+ * Asserts that a string does not end with a given substring
5
+ *
6
+ * @remarks
7
+ * Passes if the final characters of `haystack` do not match `needle`
8
+ *
9
+ * Fails if the final characters of `haystack` match `needle`
10
+ *
11
+ * @param needle the substring to find
12
+ * @param haystack the string to search
13
+ * @param message (optional) message to display on failure
14
+ *
15
+ * @example
16
+ * this.assert.stringDoesNotEndWith(needle, haystack);
17
+ */
18
+ export default function StringDoesNotEndWith(needle: string, haystack: string | null, message?: string) {
19
+ if (haystack === undefined || haystack === null
20
+ || haystack.indexOf(needle) === -1
21
+ || haystack.indexOf(needle) !== haystack.length - needle.length) {
22
+ return;
23
+ }
24
+
25
+ throw new AssertionError({
26
+ message: message || 'Expected string containing expression, but string did not contain expression',
27
+ expected: needle,
28
+ actual: haystack
29
+ });
30
+ }
@@ -0,0 +1,28 @@
1
+ import { AssertionError } from "assert";
2
+
3
+ /**
4
+ * Asserts that a string does not begin with a given substring
5
+ *
6
+ * @remarks
7
+ * Passes if the first characters of `haystack` do not match `needle`
8
+ *
9
+ * Fails if the first characters of `haystack` match `needle`
10
+ *
11
+ * @param needle the substring to find
12
+ * @param haystack the string to search
13
+ * @param message (optional) message to display on failure
14
+ *
15
+ * @example
16
+ * this.assert.stringDoesNotStartWith(needle, haystack);
17
+ */
18
+ export default function StringDoesNotStartWith(needle: string, haystack: string|null, message?: string) {
19
+ if(haystack === undefined || haystack === null || haystack.indexOf(needle) !== 0) {
20
+ return;
21
+ }
22
+
23
+ throw new AssertionError({
24
+ message: message || 'Expected string containing expression, but string did not contain expression',
25
+ expected: needle,
26
+ actual: haystack
27
+ });
28
+ }
@@ -1,7 +1,24 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function StringEndsWith(needle: string, haystack: string|null, message?: string) {
4
- if(haystack !== undefined && haystack !== null && haystack.indexOf(needle) === haystack.length - needle.length) {
3
+ /**
4
+ * Asserts that a string ends with a given substring
5
+ *
6
+ * @remarks
7
+ * Passes if the final characters of `haystack` match `needle`
8
+ *
9
+ * Fails if the final characters of `haystack` do not match `needle`
10
+ *
11
+ * @param needle the substring to find
12
+ * @param haystack the string to search
13
+ * @param message (optional) message to display on failure
14
+ *
15
+ * @example
16
+ * this.assert.stringEndsWith(needle, haystack);
17
+ */
18
+ export default function StringEndsWith(needle: string, haystack: string | null, message?: string) {
19
+ if (haystack !== undefined && haystack !== null
20
+ && haystack.indexOf(needle) > -1
21
+ && haystack.indexOf(needle) === haystack.length - needle.length) {
5
22
  return;
6
23
  }
7
24
 
@@ -1,5 +1,20 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
+ /**
4
+ * Asserts that a string begins with a given substring
5
+ *
6
+ * @remarks
7
+ * Passes if the first characters of `haystack` match `needle`
8
+ *
9
+ * Fails if the first characters of `haystack` do not match `needle`
10
+ *
11
+ * @param needle the substring to find
12
+ * @param haystack the string to search
13
+ * @param message (optional) message to display on failure
14
+ *
15
+ * @example
16
+ * this.assert.stringStartsWith(needle, haystack);
17
+ */
3
18
  export default function StringStartsWith(needle: string, haystack: string|null, message?: string) {
4
19
  if(haystack !== undefined && haystack !== null && haystack.indexOf(needle) === 0) {
5
20
  return;
@@ -1,5 +1,19 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
+ /**
4
+ * Asserts that an expression throws an error/exception
5
+ *
6
+ * @remarks
7
+ * Passes if calling `expression` throws an error/exception
8
+ *
9
+ * Fails if calling `expression` does not throw an error/exception
10
+ *
11
+ * @param expression the expression to run
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.throws(() => expression);
16
+ */
3
17
  export default function Throws(expression: () => any, message?: string) {
4
18
  try {
5
19
  expression();
@@ -1,13 +1,27 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function True(value: any, message?: string) {
4
- if(value === true) {
3
+ /**
4
+ * Asserts that a given expression evaluates to `true`
5
+ *
6
+ * @remarks
7
+ * Passes if `expression` evaluates to `true`
8
+ *
9
+ * Fails if `expression` does not evaluate to `true`
10
+ *
11
+ * @param expression the value to check
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.true(expression);
16
+ */
17
+ export default function True(expression: any, message?: string) {
18
+ if(expression === true) {
5
19
  return;
6
20
  }
7
21
 
8
22
  throw new AssertionError({
9
23
  message: message || 'Expected expression to be true, but expression is not true',
10
24
  expected: true,
11
- actual: value
25
+ actual: expression
12
26
  });
13
27
  }
@@ -1,13 +1,27 @@
1
1
  import { AssertionError } from "assert";
2
2
 
3
- export default function Undefined(value: any, message?: string) {
4
- if(value === undefined) {
3
+ /**
4
+ * Asserts that a given value is equal to `undefined`
5
+ *
6
+ * @remarks
7
+ * Passes if `expression` evaluates to `undefined`
8
+ *
9
+ * Fails if `expression` does not evaluate to `undefined`
10
+ *
11
+ * @param expression the value to check
12
+ * @param message (optional) message to display on failure
13
+ *
14
+ * @example
15
+ * this.assert.undefined(expression);
16
+ */
17
+ export default function Undefined(expression: any, message?: string) {
18
+ if(expression === undefined) {
5
19
  return;
6
20
  }
7
21
 
8
22
  throw new AssertionError({
9
23
  message: message || 'Expected expression to be undefined, but expression is not undefined',
10
24
  expected: undefined,
11
- actual: value
25
+ actual: expression
12
26
  });
13
27
  }
@@ -16,16 +16,16 @@ import not_empty from './NotEmpty';
16
16
  import count from './Count';
17
17
 
18
18
  import contains from './Contains';
19
- import not_contains from './NotContains';
19
+ import not_contains from './DoesNotContain';
20
20
 
21
21
  import string_contains from './StringContains';
22
- import string_not_contains from './StringNotContains';
22
+ import string_not_contains from './StringDoesNotContain';
23
23
 
24
24
  import string_starts from './StringStartsWith';
25
- import string_not_starts from './StringNotStartsWith';
25
+ import string_not_starts from './StringDoesNotStartWith';
26
26
 
27
27
  import string_ends from './StringEndsWith';
28
- import string_not_ends from './StringNotEndsWith';
28
+ import string_not_ends from './StringDoesNotEndWith';
29
29
 
30
30
  import instance_of from './InstanceOf';
31
31
 
package/src/CLI.ts CHANGED
@@ -2,7 +2,6 @@ import Usage from 'command-line-usage';
2
2
  import JUnitReporter from './Reporters/JUnitReporter';
3
3
  import Process from "process";
4
4
  import Args from "command-line-args";
5
- import Factory from "./Factory";
6
5
  import Runner from "./Runners/Runner";
7
6
  import SonarReporter from "./Reporters/SonarReporter";
8
7
 
@@ -72,7 +71,7 @@ export default class CLI {
72
71
 
73
72
  private static readonly usage = Usage(CLI.sections);
74
73
 
75
- constructor(private readonly process: typeof Process) {
74
+ constructor(private readonly runnerFactory: (args: Args.CommandLineOptions) => Runner, private readonly process: typeof Process) {
76
75
  }
77
76
 
78
77
  async run(): Promise<boolean> {
@@ -84,14 +83,16 @@ export default class CLI {
84
83
  return true;
85
84
  }
86
85
 
87
- const runner = Factory.Runner(args);
86
+ const runner = this.runnerFactory(args);
88
87
 
89
88
  try {
90
89
  const results = await runner.runAll(args.dir);
91
90
  return Runner.allTestsPassed(results);
92
91
  } catch (error) {
93
- this.process.stderr.write(`An unhandled ${error.name} occurred: ${error.message}\n`);
94
- this.process.stderr.write(error.stack?.toString() || '(no call stack)\n');
92
+ if (error instanceof Error) {
93
+ this.process.stderr.write(`An unhandled ${error.name} occurred: ${error.message}\n`);
94
+ this.process.stderr.write(error.stack?.toString() || '(no call stack)\n');
95
+ }
95
96
  return false;
96
97
  }
97
98
  }
package/src/Factory.ts CHANGED
@@ -12,22 +12,22 @@ 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
17
  static Runner(args: Args.CommandLineOptions) {
18
- const loader = new TestSuiteLoader(this.file_system);
19
- const reporters = this.Reporters(args);
18
+ const loader = new TestSuiteLoader(Factory.file_system);
19
+ const reporters = Factory.Reporters(args);
20
20
  const test_runner = new TestRunner(reporters);
21
21
  const test_suite_runner = new TestSuiteRunner(test_runner, reporters);
22
22
 
23
23
  return new Runner(loader, test_suite_runner, reporters);
24
24
  }
25
25
 
26
- static Reporters(args: Args.CommandLineOptions): ResultReporter[] {
26
+ static Reporters(args: Args.CommandLineOptions): ReadonlyArray<ResultReporter> {
27
27
  return [
28
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
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
31
  ].filter(r => r !== null) as ResultReporter[];
32
32
  }
33
33
  }