xunit.ts 0.13.0 → 1.0.2
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 +2 -1
- 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/Equal.js +1 -1
- package/dist/src/Assertions/Equal.js.map +1 -1
- package/dist/src/Assertions/InstanceOf.js +1 -1
- package/dist/src/Assertions/InstanceOf.js.map +1 -1
- package/dist/src/Assertions/NotEqual.js +1 -1
- package/dist/src/Assertions/NotEqual.js.map +1 -1
- package/dist/src/Assertions/StringContains.d.ts.map +1 -1
- package/dist/src/Assertions/StringContains.js +1 -1
- package/dist/src/Assertions/StringContains.js.map +1 -1
- package/dist/src/Assertions/StringDoesNotEndWith.d.ts.map +1 -1
- package/dist/src/Assertions/StringDoesNotEndWith.js +3 -1
- package/dist/src/Assertions/StringDoesNotEndWith.js.map +1 -1
- package/dist/src/Assertions/StringEndsWith.d.ts.map +1 -1
- package/dist/src/Assertions/StringEndsWith.js +3 -1
- package/dist/src/Assertions/StringEndsWith.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 +2 -3
- package/dist/src/Factory.d.ts.map +1 -1
- package/dist/src/Factory.js +4 -11
- package/dist/src/Factory.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.js +1 -1
- package/dist/src/Reporters/SonarReporter.js.map +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/icon.svg +83 -0
- package/logo.svg +154 -0
- package/package.json +8 -6
- package/sonar-project.properties +1 -1
- package/src/Assertions/InstanceOf.ts +12 -12
- package/src/Assertions/StringContains.ts +2 -2
- package/src/Assertions/StringDoesNotEndWith.ts +4 -2
- package/src/Assertions/StringEndsWith.ts +4 -2
- package/src/CLI.ts +6 -5
- package/src/Factory.ts +5 -14
- package/src/Runners/TestRunner.ts +6 -5
- package/tsconfig.json +4 -2
- package/dist/src/TSDoc/Generator.d.ts +0 -14
- package/dist/src/TSDoc/Generator.d.ts.map +0 -1
- package/dist/src/TSDoc/Generator.js +0 -59
- package/dist/src/TSDoc/Generator.js.map +0 -1
- package/dist/src/TSDoc/Markdown.d.ts +0 -4
- package/dist/src/TSDoc/Markdown.d.ts.map +0 -1
- package/dist/src/TSDoc/Markdown.js +0 -23
- package/dist/src/TSDoc/Markdown.js.map +0 -1
- package/dist/src/TSDoc/Parser.d.ts +0 -9
- package/dist/src/TSDoc/Parser.d.ts.map +0 -1
- package/dist/src/TSDoc/Parser.js +0 -45
- package/dist/src/TSDoc/Parser.js.map +0 -1
- package/src/TSDoc/Generator.ts +0 -45
- package/src/TSDoc/Markdown.ts +0 -19
- package/src/TSDoc/Parser.ts +0 -33
- package/tsdoc.ts +0 -6
package/logo.svg
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
|
2
|
+
<svg
|
|
3
|
+
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
|
4
|
+
xmlns:cc="http://creativecommons.org/ns#"
|
|
5
|
+
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
|
6
|
+
xmlns:svg="http://www.w3.org/2000/svg"
|
|
7
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
8
|
+
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
|
9
|
+
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
|
10
|
+
inkscape:export-ydpi="96"
|
|
11
|
+
inkscape:export-xdpi="96"
|
|
12
|
+
inkscape:export-filename="X:\ecoAPM\xunit.ts\logo-black.png"
|
|
13
|
+
sodipodi:docname="logo.svg"
|
|
14
|
+
inkscape:version="1.0 (4035a4fb49, 2020-05-01)"
|
|
15
|
+
id="svg8"
|
|
16
|
+
version="1.1"
|
|
17
|
+
viewBox="0 0 400 128"
|
|
18
|
+
height="128"
|
|
19
|
+
width="400">
|
|
20
|
+
<defs
|
|
21
|
+
id="defs2">
|
|
22
|
+
<rect
|
|
23
|
+
id="rect2858"
|
|
24
|
+
height="56"
|
|
25
|
+
width="61.5"
|
|
26
|
+
y="39"
|
|
27
|
+
x="127.5" />
|
|
28
|
+
<rect
|
|
29
|
+
id="rect2746"
|
|
30
|
+
height="38.364582"
|
|
31
|
+
width="5.0270834"
|
|
32
|
+
y="94.720833"
|
|
33
|
+
x="102.39375" />
|
|
34
|
+
</defs>
|
|
35
|
+
<sodipodi:namedview
|
|
36
|
+
inkscape:window-maximized="1"
|
|
37
|
+
inkscape:window-y="-8"
|
|
38
|
+
inkscape:window-x="-8"
|
|
39
|
+
inkscape:window-height="1137"
|
|
40
|
+
inkscape:window-width="1920"
|
|
41
|
+
inkscape:pagecheckerboard="false"
|
|
42
|
+
units="px"
|
|
43
|
+
showgrid="false"
|
|
44
|
+
inkscape:document-rotation="0"
|
|
45
|
+
inkscape:current-layer="layer1"
|
|
46
|
+
inkscape:document-units="px"
|
|
47
|
+
inkscape:cy="111.1524"
|
|
48
|
+
inkscape:cx="243.86486"
|
|
49
|
+
inkscape:zoom="2"
|
|
50
|
+
inkscape:pageshadow="2"
|
|
51
|
+
inkscape:pageopacity="0"
|
|
52
|
+
borderopacity="1.0"
|
|
53
|
+
bordercolor="#666666"
|
|
54
|
+
pagecolor="#000000"
|
|
55
|
+
id="base" />
|
|
56
|
+
<metadata
|
|
57
|
+
id="metadata5">
|
|
58
|
+
<rdf:RDF>
|
|
59
|
+
<cc:Work
|
|
60
|
+
rdf:about="">
|
|
61
|
+
<dc:format>image/svg+xml</dc:format>
|
|
62
|
+
<dc:type
|
|
63
|
+
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
|
64
|
+
<dc:title></dc:title>
|
|
65
|
+
</cc:Work>
|
|
66
|
+
</rdf:RDF>
|
|
67
|
+
</metadata>
|
|
68
|
+
<g
|
|
69
|
+
id="layer1"
|
|
70
|
+
inkscape:groupmode="layer"
|
|
71
|
+
inkscape:label="Layer 1">
|
|
72
|
+
<text
|
|
73
|
+
id="text2742"
|
|
74
|
+
y="168.27499"
|
|
75
|
+
x="-11.377083"
|
|
76
|
+
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:127px;line-height:1.25;font-family:'Noto Sans';-inkscape-font-specification:'Noto Sans';fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
|
|
77
|
+
xml:space="preserve"><tspan
|
|
78
|
+
sodipodi:role="line"
|
|
79
|
+
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:127px;font-family:'Noto Sans';-inkscape-font-specification:'Noto Sans';stroke-width:0.264583"
|
|
80
|
+
y="168.27499"
|
|
81
|
+
x="-11.377083"
|
|
82
|
+
id="tspan2740" /><tspan
|
|
83
|
+
id="tspan2754"
|
|
84
|
+
sodipodi:role="line"
|
|
85
|
+
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:127px;font-family:'Noto Sans';-inkscape-font-specification:'Noto Sans';stroke-width:0.264583"
|
|
86
|
+
y="327.02499"
|
|
87
|
+
x="-11.377083" /></text>
|
|
88
|
+
<text
|
|
89
|
+
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;white-space:pre;shape-inside:url(#rect2746);fill:#000000;fill-opacity:1;stroke:none;"
|
|
90
|
+
id="text2744"
|
|
91
|
+
xml:space="preserve" />
|
|
92
|
+
<text
|
|
93
|
+
id="text2752"
|
|
94
|
+
y="26.987499"
|
|
95
|
+
x="35.983334"
|
|
96
|
+
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
|
|
97
|
+
xml:space="preserve"><tspan
|
|
98
|
+
style="stroke-width:0.264583"
|
|
99
|
+
y="26.987499"
|
|
100
|
+
x="35.983334"
|
|
101
|
+
id="tspan2750"
|
|
102
|
+
sodipodi:role="line" /></text>
|
|
103
|
+
<text
|
|
104
|
+
transform="scale(0.99994519,1.0000548)"
|
|
105
|
+
id="text2758"
|
|
106
|
+
y="98.652382"
|
|
107
|
+
x="112.43309"
|
|
108
|
+
style="font-style:normal;font-weight:normal;font-size:95.8669px;line-height:0;font-family:sans-serif;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.264216"
|
|
109
|
+
xml:space="preserve"><tspan
|
|
110
|
+
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:95.8669px;line-height:1;font-family:'Noto Sans';-inkscape-font-specification:'Noto Sans';fill:#000000;fill-opacity:1;stroke-width:0.264216"
|
|
111
|
+
y="98.652382"
|
|
112
|
+
x="112.43309"
|
|
113
|
+
id="tspan2756"
|
|
114
|
+
sodipodi:role="line"><tspan
|
|
115
|
+
id="tspan3014"
|
|
116
|
+
style="fill:#ffffff;fill-opacity:1">unit</tspan><tspan
|
|
117
|
+
id="tspan3000"
|
|
118
|
+
style="fill:#808080;fill-opacity:1">.</tspan><tspan
|
|
119
|
+
id="tspan3016"
|
|
120
|
+
style="fill:#ffffff;fill-opacity:1">ts</tspan></tspan></text>
|
|
121
|
+
<text
|
|
122
|
+
style="fill:black;fill-opacity:1;line-height:1.25;stroke:none;font-family:sans-serif;font-style:normal;font-weight:normal;font-size:40px;white-space:pre;shape-inside:url(#rect2858);"
|
|
123
|
+
id="text2856"
|
|
124
|
+
xml:space="preserve" />
|
|
125
|
+
</g>
|
|
126
|
+
<g
|
|
127
|
+
inkscape:label="Layer 2"
|
|
128
|
+
id="layer2"
|
|
129
|
+
inkscape:groupmode="layer">
|
|
130
|
+
<g
|
|
131
|
+
transform="matrix(-3.7140083,0,0,3.7296903,884.38712,-159.89914)"
|
|
132
|
+
style="font-style:normal;font-weight:normal;font-size:50.8px;line-height:1.25;font-family:sans-serif;fill:#bfbfbf;fill-opacity:1;stroke:none;stroke-width:0.264583"
|
|
133
|
+
id="text2766-0"
|
|
134
|
+
aria-label="🗸">
|
|
135
|
+
<path
|
|
136
|
+
sodipodi:nodetypes="ccsccccc"
|
|
137
|
+
id="path2805"
|
|
138
|
+
style="font-size:50.8px;fill:#bfbfbf;fill-opacity:1;stroke-width:0.264583"
|
|
139
|
+
d="m 231.8494,43.408198 0.74414,1.289843 c -4.84518,3.423047 -9.33483,7.755599 -13.46894,12.997656 -4.13412,5.242057 -7.11895,10.376628 -8.9545,15.403711 l -1.0914,0.719336 c -0.94258,0.611849 -1.75287,1.223698 -2.43086,1.835547 -1.21639,-4.400349 7.20052,-16.248511 12.05508,-21.480859 4.15065,-4.415235 8.53281,-8.003646 13.14648,-10.765234 z" />
|
|
140
|
+
</g>
|
|
141
|
+
<text
|
|
142
|
+
transform="scale(0.99789547,1.002109)"
|
|
143
|
+
xml:space="preserve"
|
|
144
|
+
style="font-style:normal;font-weight:normal;font-size:189.07px;line-height:1.25;font-family:sans-serif;fill:#538d43;fill-opacity:1;stroke:none;stroke-width:0.984736"
|
|
145
|
+
x="-11.659009"
|
|
146
|
+
y="150.47635"
|
|
147
|
+
id="text2766"><tspan
|
|
148
|
+
sodipodi:role="line"
|
|
149
|
+
id="tspan2764"
|
|
150
|
+
x="-11.659009"
|
|
151
|
+
y="150.47635"
|
|
152
|
+
style="font-size:189.07px;fill:#538d43;fill-opacity:1;stroke-width:0.984736">🗸</tspan></text>
|
|
153
|
+
</g>
|
|
154
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xunit.ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A unit testing framework for TypeScript, following standard xUnit patterns",
|
|
5
5
|
"main": "dist/xunit.js",
|
|
6
6
|
"author": "ecoAPM LLC",
|
|
7
|
+
"homepage": "https://github.com/ecoAPM/xunit.ts",
|
|
8
|
+
"bugs": "https://github.com/ecoAPM/xunit.ts/issues",
|
|
7
9
|
"license": "MIT",
|
|
8
10
|
"dependencies": {
|
|
9
11
|
"colors": "1.4.0",
|
|
10
12
|
"command-line-args": "5.2.0",
|
|
11
13
|
"command-line-usage": "6.1.1",
|
|
12
14
|
"lodash.isequal": "4.5.0",
|
|
13
|
-
"typescript": "4.
|
|
15
|
+
"typescript": "4.5.2",
|
|
14
16
|
"xml": "1.0.1"
|
|
15
17
|
},
|
|
16
18
|
"devDependencies": {
|
|
@@ -18,17 +20,17 @@
|
|
|
18
20
|
"@types/command-line-args": "5.2.0",
|
|
19
21
|
"@types/command-line-usage": "5.0.2",
|
|
20
22
|
"@types/lodash.isequal": "4.5.5",
|
|
21
|
-
"@types/node": "16.
|
|
23
|
+
"@types/node": "16.11.10",
|
|
22
24
|
"@types/xml": "1.0.6",
|
|
23
|
-
"notosans": "
|
|
25
|
+
"notosans": "5.0.0",
|
|
24
26
|
"ts-mockito": "2.6.1",
|
|
25
|
-
"ts-node": "10.
|
|
27
|
+
"ts-node": "10.4.0"
|
|
26
28
|
},
|
|
27
29
|
"scripts": {
|
|
28
30
|
"clean": "rm -rf dist",
|
|
29
31
|
"build": "tsc",
|
|
30
32
|
"test": "node dist/cli.js dist/tests",
|
|
31
|
-
"tsdoc": "cp -r node_modules/notosans
|
|
33
|
+
"tsdoc": "cp -r node_modules/notosans/* docs/assets && ts-node tsdoc.ts"
|
|
32
34
|
},
|
|
33
35
|
"bin": {
|
|
34
36
|
"xunit": "dist/cli.js"
|
package/sonar-project.properties
CHANGED
|
@@ -2,27 +2,27 @@ import { AssertionError } from "assert";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Asserts that a value is an instance of a certain type
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* @remarks
|
|
7
7
|
* Passes if `object`'s type matches `type`
|
|
8
|
-
*
|
|
9
|
-
* Fails if `object`'s type does not match `type`
|
|
8
|
+
*
|
|
9
|
+
* Fails if `object`'s type does not match `type`
|
|
10
10
|
*
|
|
11
11
|
* @param type the expected type of the value
|
|
12
12
|
* @param expression the value to check
|
|
13
13
|
* @param message (optional) message to display on failure
|
|
14
|
-
*
|
|
14
|
+
*
|
|
15
15
|
* @example
|
|
16
16
|
* this.assert.instanceOf(type, object);
|
|
17
17
|
*/
|
|
18
18
|
export default function InstanceOf<T>(type: any, expression: any, message?: string) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
if (expression instanceof type) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
throw new AssertionError({
|
|
24
|
+
message: message || `Expected expression of type, but was ${typeof expression}`,
|
|
25
|
+
expected: type.name,
|
|
26
|
+
actual: typeof expression
|
|
27
|
+
})
|
|
28
28
|
}
|
|
@@ -15,8 +15,8 @@ import { AssertionError } from "assert";
|
|
|
15
15
|
* @example
|
|
16
16
|
* this.assert.stringContains(needle, haystack);
|
|
17
17
|
*/
|
|
18
|
-
export default function StringContains(needle: string, haystack: string|null, message?: string) {
|
|
19
|
-
if(haystack !== undefined && haystack !== null && haystack.indexOf(needle)
|
|
18
|
+
export default function StringContains(needle: string, haystack: string | null, message?: string) {
|
|
19
|
+
if (haystack !== undefined && haystack !== null && haystack.indexOf(needle) > -1) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -15,8 +15,10 @@ import { AssertionError } from "assert";
|
|
|
15
15
|
* @example
|
|
16
16
|
* this.assert.stringDoesNotEndWith(needle, haystack);
|
|
17
17
|
*/
|
|
18
|
-
export default function StringDoesNotEndWith(needle: string, haystack: string|null, message?: string) {
|
|
19
|
-
if(haystack === undefined || haystack === null
|
|
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) {
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -15,8 +15,10 @@ import { AssertionError } from "assert";
|
|
|
15
15
|
* @example
|
|
16
16
|
* this.assert.stringEndsWith(needle, haystack);
|
|
17
17
|
*/
|
|
18
|
-
export default function StringEndsWith(needle: string, haystack: string|null, message?: string) {
|
|
19
|
-
if(haystack !== undefined && haystack !== null
|
|
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) {
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
24
|
|
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
|
@@ -10,16 +10,13 @@ import TestSuiteLoader from './Runners/TestSuiteLoader';
|
|
|
10
10
|
import TestSuiteRunner from './Runners/TestSuiteRunner';
|
|
11
11
|
import fs from "fs/promises";
|
|
12
12
|
import SonarReporter from "./Reporters/SonarReporter";
|
|
13
|
-
import Parser from "./TSDoc/Parser";
|
|
14
|
-
import {TSDocParser} from "@microsoft/tsdoc";
|
|
15
|
-
import Generator from "./TSDoc/Generator";
|
|
16
13
|
|
|
17
14
|
export default class Factory {
|
|
18
|
-
|
|
15
|
+
static readonly file_system = new FileSystem(fs);
|
|
19
16
|
|
|
20
17
|
static Runner(args: Args.CommandLineOptions) {
|
|
21
|
-
const loader = new TestSuiteLoader(
|
|
22
|
-
const reporters =
|
|
18
|
+
const loader = new TestSuiteLoader(Factory.file_system);
|
|
19
|
+
const reporters = Factory.Reporters(args);
|
|
23
20
|
const test_runner = new TestRunner(reporters);
|
|
24
21
|
const test_suite_runner = new TestSuiteRunner(test_runner, reporters);
|
|
25
22
|
|
|
@@ -29,14 +26,8 @@ export default class Factory {
|
|
|
29
26
|
static Reporters(args: Args.CommandLineOptions): ReadonlyArray<ResultReporter> {
|
|
30
27
|
return [
|
|
31
28
|
!args.quiet ? new ConsoleReporter(new Output(process.stdout)) : null,
|
|
32
|
-
args.junit !== undefined ? new JUnitReporter(
|
|
33
|
-
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
|
|
34
31
|
].filter(r => r !== null) as ResultReporter[];
|
|
35
32
|
}
|
|
36
|
-
|
|
37
|
-
static TSDocGenerator() {
|
|
38
|
-
const parser = new Parser(new TSDocParser());
|
|
39
|
-
return new Generator(this.file_system, fs, parser);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
33
|
}
|
|
@@ -25,13 +25,14 @@ export default class TestRunner {
|
|
|
25
25
|
|
|
26
26
|
} catch (error) {
|
|
27
27
|
const duration = TestRunner.msSince(start);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
await Promise.all(this.reporters.map(r => r.testErrored(suite, name,
|
|
34
|
-
return new TestResult(ResultType.Error, duration,
|
|
34
|
+
await Promise.all(this.reporters.map(r => r.testErrored(suite, name, typedError, duration)));
|
|
35
|
+
return new TestResult(ResultType.Error, duration, typedError);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
|
package/tsconfig.json
CHANGED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import FileSystem from "../IO/FileSystem";
|
|
3
|
-
import FSPromises from "fs/promises";
|
|
4
|
-
import Parser from "./Parser";
|
|
5
|
-
export default class Generator {
|
|
6
|
-
private readonly fs;
|
|
7
|
-
private readonly fs_promises;
|
|
8
|
-
private readonly parser;
|
|
9
|
-
constructor(fs: FileSystem, fs_promises: typeof FSPromises, parser: Parser);
|
|
10
|
-
run(dir: string, out_dir: string): Promise<void>;
|
|
11
|
-
private generate;
|
|
12
|
-
private static getMarkdown;
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=Generator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Generator.d.ts","sourceRoot":"","sources":["../../../src/TSDoc/Generator.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,MAAM,MAAM,UAAU,CAAC;AAM9B,MAAM,CAAC,OAAO,OAAO,SAAS;IACd,OAAO,CAAC,QAAQ,CAAC,EAAE;IAAc,OAAO,CAAC,QAAQ,CAAC,WAAW;IAAqB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAxF,EAAE,EAAE,UAAU,EAAmB,WAAW,EAAE,OAAO,UAAU,EAAmB,MAAM,EAAE,MAAM;IAGvH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAMxC,QAAQ;IActB,OAAO,CAAC,MAAM,CAAC,WAAW;CAY7B"}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const Parser_1 = __importDefault(require("./Parser"));
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const TestName_1 = __importDefault(require("../Framework/TestName"));
|
|
18
|
-
const Markdown_1 = __importDefault(require("./Markdown"));
|
|
19
|
-
class Generator {
|
|
20
|
-
constructor(fs, fs_promises, parser) {
|
|
21
|
-
this.fs = fs;
|
|
22
|
-
this.fs_promises = fs_promises;
|
|
23
|
-
this.parser = parser;
|
|
24
|
-
}
|
|
25
|
-
run(dir, out_dir) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const files = yield this.fs.getFiles(dir);
|
|
28
|
-
const tasks = files.map(file => this.generate(file, out_dir));
|
|
29
|
-
yield Promise.all(tasks);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
generate(file, out_path) {
|
|
33
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
const code = yield this.fs_promises.readFile(file);
|
|
35
|
-
const doc = yield this.parser.findDoc(code.toString());
|
|
36
|
-
const [base, dir, filename] = file.split(path_1.default.sep);
|
|
37
|
-
const md = Generator.getMarkdown(filename, doc);
|
|
38
|
-
if (md !== null) {
|
|
39
|
-
const out = path_1.default.join(out_path, file.substr(base.length + 1)).replace(/\.ts$/, '.md');
|
|
40
|
-
yield this.fs_promises.mkdir(path_1.default.join(out_path, dir), { recursive: true });
|
|
41
|
-
yield this.fs_promises.writeFile(out, md);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
static getMarkdown(filename, doc) {
|
|
46
|
-
var _a, _b, _c, _d, _e;
|
|
47
|
-
const summary = Parser_1.default.renderNodes(doc.summarySection.nodes);
|
|
48
|
-
if (!summary) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
const title = TestName_1.default.toSentenceCase((_a = filename === null || filename === void 0 ? void 0 : filename.split('.')[0]) !== null && _a !== void 0 ? _a : '');
|
|
52
|
-
const example = Parser_1.default.renderNodes((_c = (_b = doc.customBlocks.filter(b => b.blockTag.tagName == '@example')[0]) === null || _b === void 0 ? void 0 : _b.content.nodes) !== null && _c !== void 0 ? _c : []);
|
|
53
|
-
const remarks = Parser_1.default.renderNodes((_e = (_d = doc.remarksBlock) === null || _d === void 0 ? void 0 : _d.content.nodes) !== null && _e !== void 0 ? _e : []);
|
|
54
|
-
const params = doc.params.blocks.map(p => `| \`${p.parameterName}\` | ${Parser_1.default.renderNodes(p.content.nodes)} |`).join('\n');
|
|
55
|
-
return Markdown_1.default.render(title, summary, example, remarks, params);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.default = Generator;
|
|
59
|
-
//# sourceMappingURL=Generator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Generator.js","sourceRoot":"","sources":["../../../src/TSDoc/Generator.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.d.ts","sourceRoot":"","sources":["../../../src/TSDoc/Markdown.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,QAAQ;IACzB,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;CAiB1G"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
class Markdown {
|
|
4
|
-
static render(title, summary, example, remarks, params) {
|
|
5
|
-
return `---\n`
|
|
6
|
-
+ `title: ${title} \n`
|
|
7
|
-
+ `---\n\n`
|
|
8
|
-
+ `## Assertion: ${title} \n\n`
|
|
9
|
-
+ `${summary} \n\n`
|
|
10
|
-
+ (example ? '### Example \n\n' : '')
|
|
11
|
-
+ (example ? '```ts \n' : '')
|
|
12
|
-
+ example
|
|
13
|
-
+ (example ? '\n``` \n\n' : '')
|
|
14
|
-
+ (remarks ? '### Conditions \n\n' : '')
|
|
15
|
-
+ (remarks ? `${remarks} \n\n` : '')
|
|
16
|
-
+ (params ? '### Parameters \n\n' : '')
|
|
17
|
-
+ (params ? '| Name | Description | \n' : '')
|
|
18
|
-
+ (params ? '|---|---| \n' : '')
|
|
19
|
-
+ params;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.default = Markdown;
|
|
23
|
-
//# sourceMappingURL=Markdown.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../../../src/TSDoc/Markdown.ts"],"names":[],"mappings":";;AAAA,MAAqB,QAAQ;IACzB,MAAM,CAAC,MAAM,CAAC,KAAa,EAAE,OAAe,EAAE,OAAe,EAAE,OAAe,EAAE,MAAc;QAC1F,OAAO,OAAO;cACR,UAAU,KAAK,KAAK;cACpB,SAAS;cACT,iBAAiB,KAAK,OAAO;cAC7B,GAAG,OAAO,OAAO;cACjB,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,EAAE,CAAC;cACnC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;cAC3B,OAAO;cACP,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC;cAC7B,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC;cACtC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;cAClC,CAAC,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC;cACrC,CAAC,MAAM,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,EAAE,CAAC;cAC3C,CAAC,MAAM,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;cAC9B,MAAM,CAAC;IACjB,CAAC;CACJ;AAlBD,2BAkBC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DocComment, DocNode, TSDocParser } from "@microsoft/tsdoc";
|
|
2
|
-
export default class Parser {
|
|
3
|
-
private readonly parser;
|
|
4
|
-
constructor(parser: TSDocParser);
|
|
5
|
-
findDoc(code: string): Promise<DocComment>;
|
|
6
|
-
private static renderNode;
|
|
7
|
-
static renderNodes(docNodes: ReadonlyArray<DocNode>): string;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=Parser.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Parser.d.ts","sourceRoot":"","sources":["../../../src/TSDoc/Parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAc,OAAO,EAAE,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAE9E,MAAM,CAAC,OAAO,OAAO,MAAM;IACX,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,WAAW;IAG1C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAMhD,OAAO,CAAC,MAAM,CAAC,UAAU;IAazB,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,MAAM;CAO/D"}
|
package/dist/src/TSDoc/Parser.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
const tsdoc_1 = require("@microsoft/tsdoc");
|
|
13
|
-
class Parser {
|
|
14
|
-
constructor(parser) {
|
|
15
|
-
this.parser = parser;
|
|
16
|
-
}
|
|
17
|
-
findDoc(code) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const comment = code.substring(code.indexOf('/**'), code.indexOf('*/') + 2);
|
|
20
|
-
const context = this.parser.parseString(comment);
|
|
21
|
-
return context.docComment;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
static renderNode(docNode) {
|
|
25
|
-
let result = '';
|
|
26
|
-
if (docNode) {
|
|
27
|
-
if (docNode instanceof tsdoc_1.DocExcerpt) {
|
|
28
|
-
result += docNode.content.toString();
|
|
29
|
-
}
|
|
30
|
-
for (const childNode of docNode.getChildNodes()) {
|
|
31
|
-
result += this.renderNode(childNode);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
static renderNodes(docNodes) {
|
|
37
|
-
let result = '';
|
|
38
|
-
for (const docNode of docNodes) {
|
|
39
|
-
result += this.renderNode(docNode);
|
|
40
|
-
}
|
|
41
|
-
return result.trim();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.default = Parser;
|
|
45
|
-
//# sourceMappingURL=Parser.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Parser.js","sourceRoot":"","sources":["../../../src/TSDoc/Parser.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,4CAA8E;AAE9E,MAAqB,MAAM;IACvB,YAA6B,MAAmB;QAAnB,WAAM,GAAN,MAAM,CAAa;IAChD,CAAC;IAEK,OAAO,CAAC,IAAY;;YACtB,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5E,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YACjD,OAAO,OAAO,CAAC,UAAU,CAAC;QAC9B,CAAC;KAAA;IAEO,MAAM,CAAC,UAAU,CAAC,OAAgB;QACtC,IAAI,MAAM,GAAW,EAAE,CAAC;QACxB,IAAI,OAAO,EAAE;YACT,IAAI,OAAO,YAAY,kBAAU,EAAE;gBAC/B,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;aACxC;YACD,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,aAAa,EAAE,EAAE;gBAC7C,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;aACxC;SACJ;QACD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,QAAgC;QAC/C,IAAI,MAAM,GAAW,EAAE,CAAC;QACxB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE;YAC5B,MAAM,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;SACtC;QACD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CACJ;AA9BD,yBA8BC"}
|
package/src/TSDoc/Generator.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import FileSystem from "../IO/FileSystem";
|
|
2
|
-
import FSPromises from "fs/promises";
|
|
3
|
-
import Parser from "./Parser";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import TestName from "../Framework/TestName";
|
|
6
|
-
import Markdown from "./Markdown";
|
|
7
|
-
import {DocComment} from "@microsoft/tsdoc";
|
|
8
|
-
|
|
9
|
-
export default class Generator {
|
|
10
|
-
constructor(private readonly fs: FileSystem, private readonly fs_promises: typeof FSPromises, private readonly parser: Parser) {
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async run(dir: string, out_dir: string): Promise<void> {
|
|
14
|
-
const files = await this.fs.getFiles(dir);
|
|
15
|
-
const tasks = files.map(file => this.generate(file, out_dir));
|
|
16
|
-
await Promise.all(tasks);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
private async generate(file: string, out_path: string) {
|
|
20
|
-
const code = await this.fs_promises.readFile(file);
|
|
21
|
-
const doc = await this.parser.findDoc(code.toString());
|
|
22
|
-
|
|
23
|
-
const [base, dir, filename] = file.split(path.sep);
|
|
24
|
-
const md = Generator.getMarkdown(filename, doc);
|
|
25
|
-
|
|
26
|
-
if (md !== null) {
|
|
27
|
-
const out = path.join(out_path, file.substr(base.length + 1)).replace(/\.ts$/, '.md');
|
|
28
|
-
await this.fs_promises.mkdir(path.join(out_path, dir), {recursive: true});
|
|
29
|
-
await this.fs_promises.writeFile(out, md);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
private static getMarkdown(filename: string, doc: DocComment): string | null {
|
|
34
|
-
const summary = Parser.renderNodes(doc.summarySection.nodes);
|
|
35
|
-
if (!summary) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const title = TestName.toSentenceCase(filename?.split('.')[0] ?? '');
|
|
40
|
-
const example = Parser.renderNodes(doc.customBlocks.filter(b => b.blockTag.tagName == '@example')[0]?.content.nodes ?? []);
|
|
41
|
-
const remarks = Parser.renderNodes(doc.remarksBlock?.content.nodes ?? []);
|
|
42
|
-
const params = doc.params.blocks.map(p => `| \`${p.parameterName}\` | ${Parser.renderNodes(p.content.nodes)} |`).join('\n');
|
|
43
|
-
return Markdown.render(title, summary, example, remarks, params);
|
|
44
|
-
}
|
|
45
|
-
}
|