@dialecte/cli 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -2003
- package/dist/cli.js +67190 -40066
- package/dist/corpus/manifest.json +692 -0
- package/dist/corpus/overrides/fhir-xhtml.xsd +17 -0
- package/dist/corpus/overrides/xlink.xsd +102 -0
- package/dist/corpus/overrides/xml.xsd +35 -0
- package/dist/dialecte_tdd_pytest.py +792 -0
- package/dist/lookups.d.ts +367 -13
- package/dist/lookups.js +2330 -26
- package/dist/schemas/config-list.schema.json +121 -0
- package/dist/schemas/config-yml.schema.json +52 -0
- package/dist/schemas/dialecterc.schema.json +33 -0
- package/dist/schemas/lot-risk.schema.json +32 -0
- package/dist/schemas/risk-line.schema.json +49 -0
- package/dist/schemas/rules.schema.json +51 -0
- package/dist/schemas/scope-change.schema.json +103 -0
- package/dist/tdd-node-reporter.js +167 -0
- package/dist/tdd-reporter.js +2 -0
- package/package.json +43 -5
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "config-list.schema.json",
|
|
4
|
+
"$comment": "Output of `dialecte config list --json`, `config get <key> --json` and `config check --json`, schema version 1.",
|
|
5
|
+
"title": "The answer of config list|get|check --json",
|
|
6
|
+
"oneOf": [{ "$ref": "#/$defs/list" }, { "$ref": "#/$defs/get" }, { "$ref": "#/$defs/check" }],
|
|
7
|
+
"$defs": {
|
|
8
|
+
"schema": { "type": "integer", "const": 1, "enum": [1] },
|
|
9
|
+
"list": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"required": ["schema", "projectFile", "personalFile", "repo", "values", "findings", "notes"],
|
|
12
|
+
"additionalProperties": false,
|
|
13
|
+
"properties": {
|
|
14
|
+
"schema": { "$ref": "#/$defs/schema" },
|
|
15
|
+
"projectFile": { "type": "string" },
|
|
16
|
+
"personalFile": { "type": "string" },
|
|
17
|
+
"repo": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"required": ["key", "from"],
|
|
20
|
+
"additionalProperties": false,
|
|
21
|
+
"properties": {
|
|
22
|
+
"key": { "type": "string" },
|
|
23
|
+
"from": { "enum": ["remote", "path"] }
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"values": { "type": "array", "items": { "$ref": "#/$defs/value" } },
|
|
27
|
+
"findings": { "type": "array", "items": { "$ref": "#/$defs/finding" } },
|
|
28
|
+
"notes": { "type": "array", "items": { "type": "string" } }
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"get": {
|
|
32
|
+
"type": "object",
|
|
33
|
+
"required": ["schema", "key", "value", "source"],
|
|
34
|
+
"additionalProperties": false,
|
|
35
|
+
"properties": {
|
|
36
|
+
"schema": { "$ref": "#/$defs/schema" },
|
|
37
|
+
"key": { "type": "string" },
|
|
38
|
+
"value": { "$comment": "Any value; null with a null source when the key is not set." },
|
|
39
|
+
"source": { "oneOf": [{ "$ref": "#/$defs/source" }, { "type": "null" }] },
|
|
40
|
+
"findings": { "type": "array", "items": { "$ref": "#/$defs/finding" } }
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"check": {
|
|
44
|
+
"type": "object",
|
|
45
|
+
"required": ["schema", "ok", "findings", "notes"],
|
|
46
|
+
"additionalProperties": false,
|
|
47
|
+
"properties": {
|
|
48
|
+
"schema": { "$ref": "#/$defs/schema" },
|
|
49
|
+
"ok": { "type": "boolean" },
|
|
50
|
+
"findings": { "type": "array", "items": { "$ref": "#/$defs/finding" } },
|
|
51
|
+
"notes": { "type": "array", "items": { "type": "string" } }
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"value": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"required": ["key", "value", "source"],
|
|
57
|
+
"additionalProperties": false,
|
|
58
|
+
"properties": {
|
|
59
|
+
"key": { "type": "string" },
|
|
60
|
+
"value": { "$comment": "Any value." },
|
|
61
|
+
"source": { "$ref": "#/$defs/source" }
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"source": {
|
|
65
|
+
"oneOf": [
|
|
66
|
+
{
|
|
67
|
+
"type": "object",
|
|
68
|
+
"required": ["kind", "file", "line"],
|
|
69
|
+
"additionalProperties": false,
|
|
70
|
+
"properties": {
|
|
71
|
+
"kind": { "enum": ["project"] },
|
|
72
|
+
"file": { "type": "string" },
|
|
73
|
+
"line": { "type": "integer", "minimum": 1 }
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"type": "object",
|
|
78
|
+
"required": ["kind", "file", "line"],
|
|
79
|
+
"additionalProperties": false,
|
|
80
|
+
"properties": {
|
|
81
|
+
"kind": { "enum": ["personal"] },
|
|
82
|
+
"file": { "type": "string" },
|
|
83
|
+
"line": { "type": "integer", "minimum": 1 }
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
"type": "object",
|
|
88
|
+
"required": ["kind", "file", "line", "repo"],
|
|
89
|
+
"additionalProperties": false,
|
|
90
|
+
"properties": {
|
|
91
|
+
"kind": { "enum": ["repo"] },
|
|
92
|
+
"file": { "type": "string" },
|
|
93
|
+
"line": { "type": "integer", "minimum": 1 },
|
|
94
|
+
"repo": { "type": "string" }
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"type": "object",
|
|
99
|
+
"required": ["kind", "variable"],
|
|
100
|
+
"additionalProperties": false,
|
|
101
|
+
"properties": {
|
|
102
|
+
"kind": { "enum": ["environment"] },
|
|
103
|
+
"variable": { "type": "string" }
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
"finding": {
|
|
109
|
+
"type": "object",
|
|
110
|
+
"required": ["file", "line", "problem", "refused"],
|
|
111
|
+
"additionalProperties": false,
|
|
112
|
+
"properties": {
|
|
113
|
+
"file": { "type": "string" },
|
|
114
|
+
"line": { "type": "integer", "minimum": 0 },
|
|
115
|
+
"key": { "type": "string" },
|
|
116
|
+
"problem": { "type": "string" },
|
|
117
|
+
"refused": { "type": "boolean" }
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "config-yml.schema.json",
|
|
4
|
+
"$comment": "The personal settings file config.yml, schema version 1",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["schema"],
|
|
7
|
+
"$defs": {
|
|
8
|
+
"editor": { "type": "string" },
|
|
9
|
+
"load": {
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": { "budget": { "type": "integer", "minimum": 1 } },
|
|
12
|
+
"additionalProperties": false
|
|
13
|
+
},
|
|
14
|
+
"words": { "type": "array", "items": { "type": "string" } },
|
|
15
|
+
"repoOverride": {
|
|
16
|
+
"type": "object",
|
|
17
|
+
"properties": {
|
|
18
|
+
"editor": { "$ref": "#/$defs/editor" },
|
|
19
|
+
"load": { "$ref": "#/$defs/load" },
|
|
20
|
+
"personProcesses": { "$ref": "#/$defs/words" },
|
|
21
|
+
"forbiddenWords": { "$ref": "#/$defs/words" },
|
|
22
|
+
"consumerNames": { "$ref": "#/$defs/words" }
|
|
23
|
+
},
|
|
24
|
+
"additionalProperties": false
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"properties": {
|
|
28
|
+
"schema": { "const": 1 },
|
|
29
|
+
"editor": { "$ref": "#/$defs/editor" },
|
|
30
|
+
"load": { "$ref": "#/$defs/load" },
|
|
31
|
+
"personProcesses": { "$ref": "#/$defs/words" },
|
|
32
|
+
"forbiddenWords": { "$ref": "#/$defs/words" },
|
|
33
|
+
"consumerNames": { "$ref": "#/$defs/words" },
|
|
34
|
+
"corpora": {
|
|
35
|
+
"type": "object",
|
|
36
|
+
"additionalProperties": {
|
|
37
|
+
"type": "object",
|
|
38
|
+
"required": ["xsd"],
|
|
39
|
+
"properties": {
|
|
40
|
+
"xsd": { "type": "string" },
|
|
41
|
+
"instances": { "type": "string" }
|
|
42
|
+
},
|
|
43
|
+
"additionalProperties": false
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"repos": {
|
|
47
|
+
"type": "object",
|
|
48
|
+
"additionalProperties": { "$ref": "#/$defs/repoOverride" }
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"additionalProperties": false
|
|
52
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "dialecterc.schema.json",
|
|
4
|
+
"$comment": "The project settings file .dialecterc, schema version 1",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["schema"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"schema": { "const": 1 },
|
|
9
|
+
"profile": { "type": "string" },
|
|
10
|
+
"baseBranch": { "type": "string" },
|
|
11
|
+
"gate": { "type": "object" },
|
|
12
|
+
"contrib": { "type": "object" },
|
|
13
|
+
"tdd": { "type": "object" },
|
|
14
|
+
"references": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"properties": {
|
|
17
|
+
"allow": { "type": "array", "items": { "type": "string" } },
|
|
18
|
+
"patterns": { "type": "array", "items": { "type": "string" } }
|
|
19
|
+
},
|
|
20
|
+
"additionalProperties": false
|
|
21
|
+
},
|
|
22
|
+
"mutation": { "type": "object" },
|
|
23
|
+
"generatedDocs": { "type": "array", "items": { "type": "string" } },
|
|
24
|
+
"risk": { "type": "object" },
|
|
25
|
+
"rebuiltIgnored": { "type": "array", "items": { "type": "string" } },
|
|
26
|
+
"tsconfig": { "type": "string" },
|
|
27
|
+
"namespace": { "type": "string" },
|
|
28
|
+
"entry": { "type": "string" },
|
|
29
|
+
"constantsDir": { "type": "string" },
|
|
30
|
+
"out": { "type": "string" }
|
|
31
|
+
},
|
|
32
|
+
"additionalProperties": false
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "lot-risk.schema.json",
|
|
4
|
+
"$comment": "Output of `dialecte lot risk <id|folder> --json`, schema version 1.",
|
|
5
|
+
"title": "The answer of lot risk --json",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["class", "reasons", "effort", "below", "cap"],
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"class": { "oneOf": [{ "$ref": "#/$defs/class" }, { "type": "null" }] },
|
|
11
|
+
"reasons": { "type": "array", "items": { "$ref": "#/$defs/reason" } },
|
|
12
|
+
"effort": { "oneOf": [{ "enum": ["low", "medium", "high"] }, { "type": "null" }] },
|
|
13
|
+
"below": { "type": "boolean" },
|
|
14
|
+
"cap": { "type": "integer", "minimum": 1 }
|
|
15
|
+
},
|
|
16
|
+
"$defs": {
|
|
17
|
+
"class": { "enum": ["light", "medium", "high"] },
|
|
18
|
+
"reason": {
|
|
19
|
+
"type": "object",
|
|
20
|
+
"required": ["kind", "detail"],
|
|
21
|
+
"additionalProperties": false,
|
|
22
|
+
"properties": {
|
|
23
|
+
"kind": {
|
|
24
|
+
"enum": ["declared", "destructive", "api", "broad-scope", "size", "docs", "more"]
|
|
25
|
+
},
|
|
26
|
+
"file": { "type": "string" },
|
|
27
|
+
"line": { "type": "integer" },
|
|
28
|
+
"detail": { "type": "string" }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "risk-line.schema.json",
|
|
4
|
+
"title": "A line of risk.jsonl",
|
|
5
|
+
"oneOf": [{ "$ref": "#/$defs/effortLine" }, { "$ref": "#/$defs/derivedLine" }],
|
|
6
|
+
"$defs": {
|
|
7
|
+
"class": { "enum": ["light", "medium", "high"] },
|
|
8
|
+
"reason": {
|
|
9
|
+
"type": "object",
|
|
10
|
+
"required": ["kind", "detail"],
|
|
11
|
+
"additionalProperties": false,
|
|
12
|
+
"properties": {
|
|
13
|
+
"kind": {
|
|
14
|
+
"enum": ["declared", "destructive", "api", "broad-scope", "size", "docs", "more"]
|
|
15
|
+
},
|
|
16
|
+
"file": { "type": "string" },
|
|
17
|
+
"line": { "type": "integer" },
|
|
18
|
+
"detail": { "type": "string" }
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"effortLine": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"required": ["schema", "kind", "at", "effort", "by"],
|
|
24
|
+
"additionalProperties": false,
|
|
25
|
+
"properties": {
|
|
26
|
+
"schema": { "const": 1 },
|
|
27
|
+
"kind": { "const": "effort" },
|
|
28
|
+
"at": { "type": "string" },
|
|
29
|
+
"effort": { "enum": ["low", "medium", "high"] },
|
|
30
|
+
"class": { "$ref": "#/$defs/class" },
|
|
31
|
+
"by": { "type": "string" },
|
|
32
|
+
"reason": { "type": "string" }
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"derivedLine": {
|
|
36
|
+
"type": "object",
|
|
37
|
+
"required": ["schema", "kind", "at", "class", "reasons", "from"],
|
|
38
|
+
"additionalProperties": false,
|
|
39
|
+
"properties": {
|
|
40
|
+
"schema": { "const": 1 },
|
|
41
|
+
"kind": { "const": "derived" },
|
|
42
|
+
"at": { "type": "string" },
|
|
43
|
+
"class": { "$ref": "#/$defs/class" },
|
|
44
|
+
"reasons": { "type": "array", "items": { "$ref": "#/$defs/reason" } },
|
|
45
|
+
"from": { "enum": ["start", "snapshot", "handover-write"] }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "rules.schema.json",
|
|
4
|
+
"$comment": "Output of `dialecte rules [<files...>] --json`, schema version 1.",
|
|
5
|
+
"title": "The answer of rules --json",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"required": ["files", "errors", "warnings", "findings"],
|
|
8
|
+
"additionalProperties": false,
|
|
9
|
+
"properties": {
|
|
10
|
+
"files": { "type": "array", "items": { "type": "string" } },
|
|
11
|
+
"errors": { "type": "integer", "minimum": 0 },
|
|
12
|
+
"warnings": { "type": "integer", "minimum": 0 },
|
|
13
|
+
"findings": { "type": "array", "items": { "$ref": "#/$defs/finding" } },
|
|
14
|
+
"allowed": {
|
|
15
|
+
"type": "object",
|
|
16
|
+
"additionalProperties": { "type": "integer", "minimum": 1 }
|
|
17
|
+
},
|
|
18
|
+
"noForbiddenWordsList": { "type": "string" },
|
|
19
|
+
"queryInLoopNotRun": { "type": "string" },
|
|
20
|
+
"dialecteChanges": { "type": "array", "items": { "$ref": "#/$defs/dialecteChange" } },
|
|
21
|
+
"notJudged": { "type": "integer", "minimum": 1 },
|
|
22
|
+
"baseLine": { "type": "string" }
|
|
23
|
+
},
|
|
24
|
+
"$defs": {
|
|
25
|
+
"finding": {
|
|
26
|
+
"type": "object",
|
|
27
|
+
"required": ["file", "line", "column", "rule", "severity", "message"],
|
|
28
|
+
"additionalProperties": false,
|
|
29
|
+
"properties": {
|
|
30
|
+
"file": { "type": "string" },
|
|
31
|
+
"line": { "type": "integer", "minimum": 1 },
|
|
32
|
+
"column": { "type": "integer", "minimum": 1 },
|
|
33
|
+
"rule": { "type": "string" },
|
|
34
|
+
"severity": { "enum": ["error", "warning"] },
|
|
35
|
+
"message": { "type": "string" }
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"dialecteChange": {
|
|
39
|
+
"type": "object",
|
|
40
|
+
"required": ["file", "dialecteChange", "rule"],
|
|
41
|
+
"additionalProperties": false,
|
|
42
|
+
"properties": {
|
|
43
|
+
"file": { "type": "string" },
|
|
44
|
+
"dialecteChange": { "type": "boolean" },
|
|
45
|
+
"rule": {
|
|
46
|
+
"enum": ["package-source", "template", "import", "own-import", "cli", "file-kind", "none"]
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "scope-change.schema.json",
|
|
4
|
+
"title": "A line of scope-changes.jsonl",
|
|
5
|
+
"oneOf": [
|
|
6
|
+
{
|
|
7
|
+
"$ref": "#/$defs/dropLine"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"$ref": "#/$defs/addLine"
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
"$ref": "#/$defs/undoLine"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"$defs": {
|
|
17
|
+
"dropLine": {
|
|
18
|
+
"type": "object",
|
|
19
|
+
"required": ["schema", "at", "op", "paths"],
|
|
20
|
+
"additionalProperties": false,
|
|
21
|
+
"properties": {
|
|
22
|
+
"schema": {
|
|
23
|
+
"const": 1
|
|
24
|
+
},
|
|
25
|
+
"at": {
|
|
26
|
+
"type": "string"
|
|
27
|
+
},
|
|
28
|
+
"op": {
|
|
29
|
+
"const": "drop"
|
|
30
|
+
},
|
|
31
|
+
"paths": {
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "string"
|
|
35
|
+
},
|
|
36
|
+
"minItems": 1
|
|
37
|
+
},
|
|
38
|
+
"by": {
|
|
39
|
+
"type": "string"
|
|
40
|
+
},
|
|
41
|
+
"reason": {
|
|
42
|
+
"type": "string"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"dependentRequired": {
|
|
46
|
+
"by": ["reason"],
|
|
47
|
+
"reason": ["by"]
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"addLine": {
|
|
51
|
+
"type": "object",
|
|
52
|
+
"required": ["schema", "at", "op", "paths", "by", "reason"],
|
|
53
|
+
"additionalProperties": false,
|
|
54
|
+
"properties": {
|
|
55
|
+
"schema": {
|
|
56
|
+
"const": 1
|
|
57
|
+
},
|
|
58
|
+
"at": {
|
|
59
|
+
"type": "string"
|
|
60
|
+
},
|
|
61
|
+
"op": {
|
|
62
|
+
"const": "add"
|
|
63
|
+
},
|
|
64
|
+
"paths": {
|
|
65
|
+
"type": "array",
|
|
66
|
+
"items": {
|
|
67
|
+
"type": "string"
|
|
68
|
+
},
|
|
69
|
+
"minItems": 1
|
|
70
|
+
},
|
|
71
|
+
"by": {
|
|
72
|
+
"type": "string"
|
|
73
|
+
},
|
|
74
|
+
"reason": {
|
|
75
|
+
"type": "string"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"undoLine": {
|
|
80
|
+
"type": "object",
|
|
81
|
+
"required": ["schema", "at", "op", "paths"],
|
|
82
|
+
"additionalProperties": false,
|
|
83
|
+
"properties": {
|
|
84
|
+
"schema": {
|
|
85
|
+
"const": 1
|
|
86
|
+
},
|
|
87
|
+
"at": {
|
|
88
|
+
"type": "string"
|
|
89
|
+
},
|
|
90
|
+
"op": {
|
|
91
|
+
"const": "undo"
|
|
92
|
+
},
|
|
93
|
+
"paths": {
|
|
94
|
+
"type": "array",
|
|
95
|
+
"items": {
|
|
96
|
+
"type": "string"
|
|
97
|
+
},
|
|
98
|
+
"minItems": 1
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// src/lib/tdd/tdd-node-reporter.ts
|
|
2
|
+
import { writeFileSync } from "fs";
|
|
3
|
+
import { resolve, sep } from "path";
|
|
4
|
+
|
|
5
|
+
// src/lib/tdd/tdd.constants.ts
|
|
6
|
+
var NODE_EVENT_TYPES = {
|
|
7
|
+
start: "test:start",
|
|
8
|
+
pass: "test:pass",
|
|
9
|
+
fail: "test:fail",
|
|
10
|
+
stderr: "test:stderr"
|
|
11
|
+
};
|
|
12
|
+
var NODE_TEST_EVENT_TYPES = [
|
|
13
|
+
NODE_EVENT_TYPES.start,
|
|
14
|
+
NODE_EVENT_TYPES.pass,
|
|
15
|
+
NODE_EVENT_TYPES.fail
|
|
16
|
+
];
|
|
17
|
+
var NODE_CODE_FAILURE = "testCodeFailure";
|
|
18
|
+
var NODE_TIMEOUT_FAILURE = "testTimeoutFailure";
|
|
19
|
+
var NODE_TIMEOUT_BOUND_PATTERN = /(\d+)\s*ms/;
|
|
20
|
+
var NODE_TIMEOUT_MESSAGE = "Test timed out in {ms}ms";
|
|
21
|
+
var V8_FRAME_PATTERN = /^\s*at (?:.*? \()?(.+?):(\d+):(\d+)\)?$/;
|
|
22
|
+
var NODE_INTERNAL_FRAME_PREFIX = "node:";
|
|
23
|
+
var BASE_COPY_PYTEST_ARGUMENTS = [
|
|
24
|
+
"-c",
|
|
25
|
+
[
|
|
26
|
+
"import os, sys",
|
|
27
|
+
"folder = sys.argv[1]",
|
|
28
|
+
'current = {"", os.getcwd(), folder}',
|
|
29
|
+
"sys.path[:] = [folder] + [entry for entry in sys.path if entry not in current]",
|
|
30
|
+
'sys.argv = ["pytest"] + sys.argv[2:]',
|
|
31
|
+
"try:",
|
|
32
|
+
" import pytest",
|
|
33
|
+
"except ImportError:",
|
|
34
|
+
' sys.exit("No module named pytest")',
|
|
35
|
+
"sys.exit(pytest.console_main())"
|
|
36
|
+
].join("\n")
|
|
37
|
+
];
|
|
38
|
+
var EDITABLE_PROBE_SCRIPT = [
|
|
39
|
+
"import json, sys",
|
|
40
|
+
"from importlib import metadata",
|
|
41
|
+
"try:",
|
|
42
|
+
" found = metadata.distribution(sys.argv[1])",
|
|
43
|
+
"except metadata.PackageNotFoundError:",
|
|
44
|
+
" sys.exit(0)",
|
|
45
|
+
'direct = json.loads(found.read_text("direct_url.json") or "{}")',
|
|
46
|
+
"paths = [str(path) for path in (found.files or [])]",
|
|
47
|
+
'editable = direct.get("dir_info", {}).get("editable") or any(',
|
|
48
|
+
' "__editable__" in path or path.endswith(".pth") for path in paths',
|
|
49
|
+
")",
|
|
50
|
+
'print("editable" if editable else "installed")'
|
|
51
|
+
].join("\n");
|
|
52
|
+
var CASE_NAME_SEPARATOR = " > ";
|
|
53
|
+
var REPORT_ENVIRONMENT_VARIABLE = "DIALECTE_TDD_REPORT";
|
|
54
|
+
|
|
55
|
+
// src/lib/tdd/tdd-node-reporter.ts
|
|
56
|
+
function readNodeEvents(events) {
|
|
57
|
+
const printed = stderrByFile(events);
|
|
58
|
+
return [...eventsByFile(events)].map(function moduleOf([file, fileEvents]) {
|
|
59
|
+
return readFileEvents({ file, events: fileEvents, printed: printed.get(file) ?? "" });
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function* tddNodeReporter(source) {
|
|
63
|
+
const events = [];
|
|
64
|
+
for await (const event of source) events.push(event);
|
|
65
|
+
const path = process.env[REPORT_ENVIRONMENT_VARIABLE];
|
|
66
|
+
if (path) writeFileSync(path, JSON.stringify(readNodeEvents(events)));
|
|
67
|
+
yield* [];
|
|
68
|
+
}
|
|
69
|
+
function stderrByFile(events) {
|
|
70
|
+
const printed = /* @__PURE__ */ new Map();
|
|
71
|
+
for (const { type, data } of events) {
|
|
72
|
+
if (type !== NODE_EVENT_TYPES.stderr || data.message === void 0) continue;
|
|
73
|
+
const path = data.entryFile ?? (data.file === void 0 ? void 0 : resolve(data.file));
|
|
74
|
+
if (path !== void 0) printed.set(path, `${printed.get(path) ?? ""}${data.message}`);
|
|
75
|
+
}
|
|
76
|
+
return printed;
|
|
77
|
+
}
|
|
78
|
+
function eventsByFile(events) {
|
|
79
|
+
const byFile = /* @__PURE__ */ new Map();
|
|
80
|
+
for (const event of events) {
|
|
81
|
+
const { file } = event.data;
|
|
82
|
+
if (file === void 0 || event.data.nesting === void 0) continue;
|
|
83
|
+
if (!NODE_TEST_EVENT_TYPES.includes(event.type)) continue;
|
|
84
|
+
const known = byFile.get(file);
|
|
85
|
+
if (known) known.push(event);
|
|
86
|
+
else byFile.set(file, [event]);
|
|
87
|
+
}
|
|
88
|
+
return byFile;
|
|
89
|
+
}
|
|
90
|
+
function readFileEvents(params) {
|
|
91
|
+
const { file } = params;
|
|
92
|
+
const testModule = { file, runner: "node", errors: [], cases: [] };
|
|
93
|
+
const titles = [];
|
|
94
|
+
const casesAtStart = [];
|
|
95
|
+
for (const { type, data } of params.events) {
|
|
96
|
+
const nesting = data.nesting ?? 0;
|
|
97
|
+
if (type === NODE_EVENT_TYPES.start) {
|
|
98
|
+
titles.splice(nesting, titles.length, data.name ?? "");
|
|
99
|
+
casesAtStart.splice(nesting, casesAtStart.length, testModule.cases.length);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const failed = type === NODE_EVENT_TYPES.fail;
|
|
103
|
+
const error = data.details?.error;
|
|
104
|
+
if (isFileTest({ data, file })) {
|
|
105
|
+
if (failed) testModule.errors.push(loadError({ printed: params.printed, error }));
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (data.details?.type === "suite") {
|
|
109
|
+
const casesUnder = testModule.cases.length - (casesAtStart[nesting] ?? 0);
|
|
110
|
+
if (failed && error?.failureType === NODE_CODE_FAILURE && casesUnder === 0)
|
|
111
|
+
testModule.errors.push(reportError(error));
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
testModule.cases.push({
|
|
115
|
+
name: [...titles.slice(0, nesting), data.name ?? ""].join(CASE_NAME_SEPARATOR),
|
|
116
|
+
state: caseStateOf({ data, failed }),
|
|
117
|
+
project: "",
|
|
118
|
+
...data.line !== void 0 && data.column !== void 0 && { location: { line: data.line, column: data.column } },
|
|
119
|
+
errors: failed && error ? [reportError(error)] : []
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return testModule;
|
|
123
|
+
}
|
|
124
|
+
function isFileTest(params) {
|
|
125
|
+
const { data, file } = params;
|
|
126
|
+
if (data.nesting !== 0 || data.details?.type !== "test" || data.name === void 0) return false;
|
|
127
|
+
return file === data.name || file.endsWith(`${sep}${data.name}`) || resolve(data.name) === file;
|
|
128
|
+
}
|
|
129
|
+
function loadError(params) {
|
|
130
|
+
const { printed, error } = params;
|
|
131
|
+
if (printed.trim() !== "") return { message: printed, frames: [] };
|
|
132
|
+
return error ? reportError(error) : { message: "", frames: [] };
|
|
133
|
+
}
|
|
134
|
+
function caseStateOf(params) {
|
|
135
|
+
const { data } = params;
|
|
136
|
+
if (data.todo) return "pending";
|
|
137
|
+
if (data.skip) return "skipped";
|
|
138
|
+
return params.failed ? "failed" : "passed";
|
|
139
|
+
}
|
|
140
|
+
function reportError(error) {
|
|
141
|
+
const { cause } = error;
|
|
142
|
+
const message = typeof cause === "string" ? cause : cause?.message ?? error.message ?? "";
|
|
143
|
+
const name = typeof cause === "object" ? cause.name : void 0;
|
|
144
|
+
const code = typeof cause === "object" ? cause.code : void 0;
|
|
145
|
+
const stack = typeof cause === "object" ? cause.stack : void 0;
|
|
146
|
+
return {
|
|
147
|
+
...name && { name },
|
|
148
|
+
...typeof code === "string" && { code },
|
|
149
|
+
message: error.failureType === NODE_TIMEOUT_FAILURE ? timeoutMessage(message) : message,
|
|
150
|
+
frames: stack === void 0 ? [] : framesOf(stack)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function timeoutMessage(message) {
|
|
154
|
+
const bound = NODE_TIMEOUT_BOUND_PATTERN.exec(message)?.[1] ?? "0";
|
|
155
|
+
return NODE_TIMEOUT_MESSAGE.replace("{ms}", bound);
|
|
156
|
+
}
|
|
157
|
+
function framesOf(stack) {
|
|
158
|
+
return stack.split("\n").flatMap(function frameOf(line) {
|
|
159
|
+
const matched = V8_FRAME_PATTERN.exec(line);
|
|
160
|
+
if (!matched || matched[1].startsWith(NODE_INTERNAL_FRAME_PREFIX)) return [];
|
|
161
|
+
return [{ file: matched[1], line: Number(matched[2]), column: Number(matched[3]) }];
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
export {
|
|
165
|
+
tddNodeReporter as default,
|
|
166
|
+
readNodeEvents
|
|
167
|
+
};
|
package/dist/tdd-reporter.js
CHANGED
|
@@ -10,6 +10,7 @@ var TddReporter = class {
|
|
|
10
10
|
function reportModule(testModule) {
|
|
11
11
|
return {
|
|
12
12
|
file: testModule.moduleId,
|
|
13
|
+
runner: "vitest",
|
|
13
14
|
errors: testModule.errors().map(reportError),
|
|
14
15
|
cases: [...testModule.children.allTests()].map(function reportCase(testCase) {
|
|
15
16
|
const result = testCase.result();
|
|
@@ -26,6 +27,7 @@ function reportModule(testModule) {
|
|
|
26
27
|
function reportError(error) {
|
|
27
28
|
return {
|
|
28
29
|
...error.name && { name: error.name },
|
|
30
|
+
...typeof error.code === "string" && { code: error.code },
|
|
29
31
|
message: error.message ?? "",
|
|
30
32
|
frames: (error.stacks ?? []).map((frame) => ({
|
|
31
33
|
file: frame.file,
|