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.
- package/.editorconfig +24 -0
- package/README.md +27 -269
- package/SECURITY.md +11 -0
- package/cli.ts +2 -1
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/src/Assertions/Contains.d.ts +16 -1
- package/dist/src/Assertions/Contains.d.ts.map +1 -1
- package/dist/src/Assertions/Contains.js +15 -0
- package/dist/src/Assertions/Contains.js.map +1 -1
- package/dist/src/Assertions/Count.d.ts +16 -1
- package/dist/src/Assertions/Count.d.ts.map +1 -1
- package/dist/src/Assertions/Count.js +15 -0
- package/dist/src/Assertions/Count.js.map +1 -1
- package/dist/src/Assertions/Defined.d.ts +15 -1
- package/dist/src/Assertions/Defined.d.ts.map +1 -1
- package/dist/src/Assertions/Defined.js +17 -3
- package/dist/src/Assertions/Defined.js.map +1 -1
- package/dist/src/Assertions/DoesNotContain.d.ts +17 -0
- package/dist/src/Assertions/DoesNotContain.d.ts.map +1 -0
- package/dist/src/Assertions/DoesNotContain.js +30 -0
- package/dist/src/Assertions/DoesNotContain.js.map +1 -0
- package/dist/src/Assertions/DoesNotThrow.d.ts +14 -0
- package/dist/src/Assertions/DoesNotThrow.d.ts.map +1 -1
- package/dist/src/Assertions/DoesNotThrow.js +15 -0
- package/dist/src/Assertions/DoesNotThrow.js.map +1 -1
- package/dist/src/Assertions/Empty.d.ts +15 -1
- package/dist/src/Assertions/Empty.d.ts.map +1 -1
- package/dist/src/Assertions/Empty.js +17 -3
- package/dist/src/Assertions/Empty.js.map +1 -1
- package/dist/src/Assertions/Equal.d.ts +15 -0
- package/dist/src/Assertions/Equal.d.ts.map +1 -1
- package/dist/src/Assertions/Equal.js +16 -1
- package/dist/src/Assertions/Equal.js.map +1 -1
- package/dist/src/Assertions/False.d.ts +15 -1
- package/dist/src/Assertions/False.d.ts.map +1 -1
- package/dist/src/Assertions/False.js +17 -3
- package/dist/src/Assertions/False.js.map +1 -1
- package/dist/src/Assertions/InstanceOf.d.ts +16 -1
- package/dist/src/Assertions/InstanceOf.d.ts.map +1 -1
- package/dist/src/Assertions/InstanceOf.js +19 -4
- package/dist/src/Assertions/InstanceOf.js.map +1 -1
- package/dist/src/Assertions/NotEmpty.d.ts +15 -1
- package/dist/src/Assertions/NotEmpty.d.ts.map +1 -1
- package/dist/src/Assertions/NotEmpty.js +17 -3
- package/dist/src/Assertions/NotEmpty.js.map +1 -1
- package/dist/src/Assertions/NotEqual.d.ts +15 -0
- package/dist/src/Assertions/NotEqual.d.ts.map +1 -1
- package/dist/src/Assertions/NotEqual.js +20 -1
- package/dist/src/Assertions/NotEqual.js.map +1 -1
- package/dist/src/Assertions/NotNull.d.ts +15 -1
- package/dist/src/Assertions/NotNull.d.ts.map +1 -1
- package/dist/src/Assertions/NotNull.js +17 -3
- package/dist/src/Assertions/NotNull.js.map +1 -1
- package/dist/src/Assertions/Null.d.ts +15 -1
- package/dist/src/Assertions/Null.d.ts.map +1 -1
- package/dist/src/Assertions/Null.js +17 -3
- package/dist/src/Assertions/Null.js.map +1 -1
- package/dist/src/Assertions/StringContains.d.ts +15 -0
- package/dist/src/Assertions/StringContains.d.ts.map +1 -1
- package/dist/src/Assertions/StringContains.js +16 -1
- package/dist/src/Assertions/StringContains.js.map +1 -1
- package/dist/src/Assertions/StringDoesNotContain.d.ts +17 -0
- package/dist/src/Assertions/StringDoesNotContain.d.ts.map +1 -0
- package/dist/src/Assertions/StringDoesNotContain.js +30 -0
- package/dist/src/Assertions/StringDoesNotContain.js.map +1 -0
- package/dist/src/Assertions/StringDoesNotEndWith.d.ts +17 -0
- package/dist/src/Assertions/StringDoesNotEndWith.d.ts.map +1 -0
- package/dist/src/Assertions/StringDoesNotEndWith.js +32 -0
- package/dist/src/Assertions/StringDoesNotEndWith.js.map +1 -0
- package/dist/src/Assertions/StringDoesNotStartWith.d.ts +17 -0
- package/dist/src/Assertions/StringDoesNotStartWith.d.ts.map +1 -0
- package/dist/src/Assertions/StringDoesNotStartWith.js +30 -0
- package/dist/src/Assertions/StringDoesNotStartWith.js.map +1 -0
- package/dist/src/Assertions/StringEndsWith.d.ts +15 -0
- package/dist/src/Assertions/StringEndsWith.d.ts.map +1 -1
- package/dist/src/Assertions/StringEndsWith.js +18 -1
- package/dist/src/Assertions/StringEndsWith.js.map +1 -1
- package/dist/src/Assertions/StringStartsWith.d.ts +15 -0
- package/dist/src/Assertions/StringStartsWith.d.ts.map +1 -1
- package/dist/src/Assertions/StringStartsWith.js +15 -0
- package/dist/src/Assertions/StringStartsWith.js.map +1 -1
- package/dist/src/Assertions/Throws.d.ts +14 -0
- package/dist/src/Assertions/Throws.d.ts.map +1 -1
- package/dist/src/Assertions/Throws.js +14 -0
- package/dist/src/Assertions/Throws.js.map +1 -1
- package/dist/src/Assertions/True.d.ts +15 -1
- package/dist/src/Assertions/True.d.ts.map +1 -1
- package/dist/src/Assertions/True.js +17 -3
- package/dist/src/Assertions/True.js.map +1 -1
- package/dist/src/Assertions/Undefined.d.ts +15 -1
- package/dist/src/Assertions/Undefined.d.ts.map +1 -1
- package/dist/src/Assertions/Undefined.js +17 -3
- package/dist/src/Assertions/Undefined.js.map +1 -1
- package/dist/src/Assertions/index.d.ts +4 -4
- package/dist/src/Assertions/index.d.ts.map +1 -1
- package/dist/src/Assertions/index.js +8 -8
- package/dist/src/Assertions/index.js.map +1 -1
- package/dist/src/CLI.d.ts +4 -1
- package/dist/src/CLI.d.ts.map +1 -1
- package/dist/src/CLI.js +9 -7
- package/dist/src/CLI.js.map +1 -1
- package/dist/src/Factory.d.ts +3 -2
- package/dist/src/Factory.d.ts.map +1 -1
- package/dist/src/Factory.js +4 -4
- package/dist/src/Factory.js.map +1 -1
- package/dist/src/Framework/Test.d.ts +14 -0
- package/dist/src/Framework/Test.d.ts.map +1 -1
- package/dist/src/Framework/Test.js +14 -0
- package/dist/src/Framework/Test.js.map +1 -1
- package/dist/src/Framework/TestSuite.d.ts +13 -4
- package/dist/src/Framework/TestSuite.d.ts.map +1 -1
- package/dist/src/Framework/TestSuite.js +9 -0
- package/dist/src/Framework/TestSuite.js.map +1 -1
- package/dist/src/Reporters/JUnitReporter.js +1 -1
- package/dist/src/Reporters/JUnitReporter.js.map +1 -1
- package/dist/src/Reporters/SonarReporter.d.ts.map +1 -1
- package/dist/src/Reporters/SonarReporter.js +3 -2
- package/dist/src/Reporters/SonarReporter.js.map +1 -1
- package/dist/src/Runners/Runner.d.ts +1 -1
- package/dist/src/Runners/Runner.d.ts.map +1 -1
- package/dist/src/Runners/Runner.js.map +1 -1
- package/dist/src/Runners/TestRunner.d.ts +1 -1
- package/dist/src/Runners/TestRunner.d.ts.map +1 -1
- package/dist/src/Runners/TestRunner.js +6 -5
- package/dist/src/Runners/TestRunner.js.map +1 -1
- package/dist/src/Runners/TestSuiteRunner.d.ts +1 -1
- package/dist/src/Runners/TestSuiteRunner.d.ts.map +1 -1
- package/dist/src/Runners/TestSuiteRunner.js.map +1 -1
- package/icon.svg +83 -0
- package/logo.svg +154 -0
- package/package.json +15 -9
- package/sonar-project.properties +1 -1
- package/src/Assertions/Contains.ts +16 -1
- package/src/Assertions/Count.ts +16 -1
- package/src/Assertions/Defined.ts +17 -3
- package/src/Assertions/DoesNotContain.ts +28 -0
- package/src/Assertions/DoesNotThrow.ts +15 -0
- package/src/Assertions/Empty.ts +17 -3
- package/src/Assertions/Equal.ts +15 -0
- package/src/Assertions/False.ts +17 -3
- package/src/Assertions/InstanceOf.ts +19 -4
- package/src/Assertions/NotEmpty.ts +17 -3
- package/src/Assertions/NotEqual.ts +17 -1
- package/src/Assertions/NotNull.ts +17 -3
- package/src/Assertions/Null.ts +17 -3
- package/src/Assertions/StringContains.ts +17 -2
- package/src/Assertions/StringDoesNotContain.ts +28 -0
- package/src/Assertions/StringDoesNotEndWith.ts +30 -0
- package/src/Assertions/StringDoesNotStartWith.ts +28 -0
- package/src/Assertions/StringEndsWith.ts +19 -2
- package/src/Assertions/StringStartsWith.ts +15 -0
- package/src/Assertions/Throws.ts +14 -0
- package/src/Assertions/True.ts +17 -3
- package/src/Assertions/Undefined.ts +17 -3
- package/src/Assertions/index.ts +4 -4
- package/src/CLI.ts +6 -5
- package/src/Factory.ts +6 -6
- package/src/Framework/Test.ts +14 -0
- package/src/Framework/TestSuite.ts +9 -0
- package/src/Reporters/SonarReporter.ts +2 -1
- package/src/Runners/Runner.ts +1 -1
- package/src/Runners/TestRunner.ts +7 -6
- package/src/Runners/TestSuiteRunner.ts +1 -1
- package/tsconfig.json +4 -2
- package/dist/src/Assertions/NotContains.d.ts +0 -2
- package/dist/src/Assertions/NotContains.d.ts.map +0 -1
- package/dist/src/Assertions/NotContains.js +0 -15
- package/dist/src/Assertions/NotContains.js.map +0 -1
- package/dist/src/Assertions/StringNotContains.d.ts +0 -2
- package/dist/src/Assertions/StringNotContains.d.ts.map +0 -1
- package/dist/src/Assertions/StringNotContains.js +0 -15
- package/dist/src/Assertions/StringNotContains.js.map +0 -1
- package/dist/src/Assertions/StringNotEndsWith.d.ts +0 -2
- package/dist/src/Assertions/StringNotEndsWith.d.ts.map +0 -1
- package/dist/src/Assertions/StringNotEndsWith.js +0 -15
- package/dist/src/Assertions/StringNotEndsWith.js.map +0 -1
- package/dist/src/Assertions/StringNotStartsWith.d.ts +0 -2
- package/dist/src/Assertions/StringNotStartsWith.d.ts.map +0 -1
- package/dist/src/Assertions/StringNotStartsWith.js +0 -15
- package/dist/src/Assertions/StringNotStartsWith.js.map +0 -1
- package/src/Assertions/NotContains.ts +0 -13
- package/src/Assertions/StringNotContains.ts +0 -13
- package/src/Assertions/StringNotEndsWith.ts +0 -13
- package/src/Assertions/StringNotStartsWith.ts +0 -13
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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:
|
|
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',
|
package/src/Assertions/Empty.ts
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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:
|
|
25
|
+
actual: array
|
|
12
26
|
})
|
|
13
27
|
}
|
package/src/Assertions/Equal.ts
CHANGED
|
@@ -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;
|
package/src/Assertions/False.ts
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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:
|
|
25
|
+
actual: expression
|
|
12
26
|
});
|
|
13
27
|
}
|
|
@@ -1,13 +1,28 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
24
|
+
message: message || `Expected expression of type, but was ${typeof expression}`,
|
|
10
25
|
expected: type,
|
|
11
|
-
actual: typeof
|
|
26
|
+
actual: typeof expression
|
|
12
27
|
})
|
|
13
28
|
}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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:
|
|
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
|
|
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
|
-
|
|
4
|
-
|
|
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:
|
|
25
|
+
actual: expression
|
|
12
26
|
});
|
|
13
27
|
}
|
package/src/Assertions/Null.ts
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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:
|
|
25
|
+
actual: expression
|
|
12
26
|
});
|
|
13
27
|
}
|
|
@@ -1,7 +1,22 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
4
|
-
|
|
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;
|
package/src/Assertions/Throws.ts
CHANGED
|
@@ -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();
|
package/src/Assertions/True.ts
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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:
|
|
25
|
+
actual: expression
|
|
12
26
|
});
|
|
13
27
|
}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { AssertionError } from "assert";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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:
|
|
25
|
+
actual: expression
|
|
12
26
|
});
|
|
13
27
|
}
|
package/src/Assertions/index.ts
CHANGED
|
@@ -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 './
|
|
19
|
+
import not_contains from './DoesNotContain';
|
|
20
20
|
|
|
21
21
|
import string_contains from './StringContains';
|
|
22
|
-
import string_not_contains from './
|
|
22
|
+
import string_not_contains from './StringDoesNotContain';
|
|
23
23
|
|
|
24
24
|
import string_starts from './StringStartsWith';
|
|
25
|
-
import string_not_starts from './
|
|
25
|
+
import string_not_starts from './StringDoesNotStartWith';
|
|
26
26
|
|
|
27
27
|
import string_ends from './StringEndsWith';
|
|
28
|
-
import string_not_ends from './
|
|
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 =
|
|
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
|
-
|
|
94
|
-
|
|
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
|
-
|
|
15
|
+
static readonly file_system = new FileSystem(fs);
|
|
16
16
|
|
|
17
17
|
static Runner(args: Args.CommandLineOptions) {
|
|
18
|
-
const loader = new TestSuiteLoader(
|
|
19
|
-
const reporters =
|
|
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(
|
|
30
|
-
args.sonar !== undefined ? new SonarReporter(
|
|
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
|
}
|