1
+ import { TSDocConfiguration } from '@microsoft/tsdoc' ;
1
2
import * as path from 'path' ;
2
3
3
4
import { TSDocConfigFile } from '../TSDocConfigFile' ;
4
5
5
6
interface ISnapshot {
6
- _0_filePath : string ;
7
- _1_fileNotFound : boolean ;
8
- _2_hasErrors : boolean ;
9
- _3_errorSummary : string ;
10
- _4_log : string [ ] ;
11
- _5_extends : ISnapshot [ ] ;
7
+ s0_filePath : string ;
8
+ s1_fileNotFound : boolean ;
9
+ s2_hasErrors : boolean ;
10
+ s3_errorSummary : string ;
11
+ s4_log : string [ ] ;
12
+ s5_extends : ISnapshot [ ] ;
12
13
}
13
14
14
15
// To make the unit tests deterministic, we need to replace all OS-dependent absolute paths
@@ -22,9 +23,12 @@ function makeStablePath(testPath: string): string {
22
23
23
24
// Build a map from absolute path --> stable path, for each TSDocConfigFile.filePath value
24
25
function buildStablePathMap ( stablePathMap : Map < string , string > , configFile : TSDocConfigFile ) : void {
25
- if ( ! stablePathMap . has ( configFile . filePath ) ) {
26
- stablePathMap . set ( configFile . filePath , makeStablePath ( configFile . filePath ) ) ;
26
+ for ( const absolutePath of [ configFile . filePath , path . dirname ( configFile . filePath ) ] ) {
27
+ if ( ! stablePathMap . has ( absolutePath ) ) {
28
+ stablePathMap . set ( absolutePath , makeStablePath ( absolutePath ) ) ;
29
+ }
27
30
}
31
+
28
32
for ( const extendsFile of configFile . extendsFiles ) {
29
33
buildStablePathMap ( stablePathMap , extendsFile ) ;
30
34
}
@@ -41,12 +45,12 @@ function convertToStablePaths(text: string, stablePathMap: Map<string, string>):
41
45
42
46
function createSnapshot ( configFile : TSDocConfigFile , pathFixupMap : Map < string , string > ) : ISnapshot {
43
47
return {
44
- _0_filePath : convertToStablePaths ( configFile . filePath , pathFixupMap ) ,
45
- _1_fileNotFound : configFile . fileNotFound ,
46
- _2_hasErrors : configFile . hasErrors ,
47
- _4_log : configFile . log . messages . map ( ( x ) => `[${ x . messageId } ] ${ convertToStablePaths ( x . text , pathFixupMap ) } ` ) ,
48
- _5_extends : configFile . extendsFiles . map ( ( x ) => createSnapshot ( x , pathFixupMap ) ) ,
49
- _3_errorSummary : convertToStablePaths ( configFile . getErrorSummary ( ) , pathFixupMap ) ,
48
+ s0_filePath : convertToStablePaths ( configFile . filePath , pathFixupMap ) ,
49
+ s1_fileNotFound : configFile . fileNotFound ,
50
+ s2_hasErrors : configFile . hasErrors ,
51
+ s4_log : configFile . log . messages . map ( ( x ) => `[${ x . messageId } ] ${ convertToStablePaths ( x . text , pathFixupMap ) } ` ) ,
52
+ s5_extends : configFile . extendsFiles . map ( ( x ) => createSnapshot ( x , pathFixupMap ) ) ,
53
+ s3_errorSummary : convertToStablePaths ( configFile . getErrorSummary ( ) , pathFixupMap ) ,
50
54
} ;
51
55
}
52
56
@@ -62,139 +66,198 @@ function testLoadingFolder(assetPath: string): ISnapshot {
62
66
test ( 'Load e1' , ( ) => {
63
67
expect ( testLoadingFolder ( 'assets/e1' ) ) . toMatchInlineSnapshot ( `
64
68
Object {
65
- "_0_filePath ": ".../assets/e1/tsdoc.json",
66
- "_1_fileNotFound ": false,
67
- "_2_hasErrors ": true,
68
- "_3_errorSummary ": "Error encountered for .../assets/e1/tsdoc.json:
69
+ "s0_filePath ": ".../assets/e1/tsdoc.json",
70
+ "s1_fileNotFound ": false,
71
+ "s2_hasErrors ": true,
72
+ "s3_errorSummary ": "Error encountered for .../assets/e1/tsdoc.json:
69
73
Error loading config file: data should NOT have additional properties
70
74
",
71
- "_4_log ": Array [
75
+ "s4_log ": Array [
72
76
"[tsdoc-config-schema-error] Error loading config file: data should NOT have additional properties",
73
77
],
74
- "_5_extends ": Array [],
78
+ "s5_extends ": Array [],
75
79
}
76
80
` ) ;
77
81
} ) ;
78
82
79
83
test ( 'Load e2' , ( ) => {
80
84
expect ( testLoadingFolder ( 'assets/e2' ) ) . toMatchInlineSnapshot ( `
81
85
Object {
82
- "_0_filePath ": ".../assets/e2/tsdoc.json",
83
- "_1_fileNotFound ": false,
84
- "_2_hasErrors ": true,
85
- "_3_errorSummary ": "Error encountered for .../assets/e2/tsdoc.json:
86
+ "s0_filePath ": ".../assets/e2/tsdoc.json",
87
+ "s1_fileNotFound ": false,
88
+ "s2_hasErrors ": true,
89
+ "s3_errorSummary ": "Error encountered for .../assets/e2/tsdoc.json:
86
90
Error parsing JSON input: Unexpected token '\\\\n' at 3:12
87
91
\\"invalid
88
92
^
89
93
",
90
- "_4_log ": Array [
94
+ "s4_log ": Array [
91
95
"[tsdoc-config-invalid-json] Error parsing JSON input: Unexpected token '\\\\n' at 3:12
92
96
\\"invalid
93
97
^",
94
98
],
95
- "_5_extends ": Array [],
99
+ "s5_extends ": Array [],
96
100
}
97
101
` ) ;
98
102
} ) ;
99
103
100
104
test ( 'Load e3' , ( ) => {
101
105
expect ( testLoadingFolder ( 'assets/e3' ) ) . toMatchInlineSnapshot ( `
102
106
Object {
103
- "_0_filePath ": ".../assets/e3/tsdoc.json",
104
- "_1_fileNotFound ": false,
105
- "_2_hasErrors ": true,
106
- "_3_errorSummary ": "Error encountered for .../assets/e3/tsdoc.json:
107
+ "s0_filePath ": ".../assets/e3/tsdoc.json",
108
+ "s1_fileNotFound ": false,
109
+ "s2_hasErrors ": true,
110
+ "s3_errorSummary ": "Error encountered for .../assets/e3/tsdoc.json:
107
111
Unsupported JSON \\"$schema\\" value; expecting \\"https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json\\"
108
112
",
109
- "_4_log ": Array [
113
+ "s4_log ": Array [
110
114
"[tsdoc-config-unsupported-schema] Unsupported JSON \\"$schema\\" value; expecting \\"https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json\\"",
111
115
],
112
- "_5_extends ": Array [],
116
+ "s5_extends ": Array [],
113
117
}
114
118
` ) ;
115
119
} ) ;
116
120
117
121
test ( 'Load e4' , ( ) => {
118
122
expect ( testLoadingFolder ( 'assets/e4' ) ) . toMatchInlineSnapshot ( `
119
123
Object {
120
- "_0_filePath ": ".../assets/e4/tsdoc.json",
121
- "_1_fileNotFound ": false,
122
- "_2_hasErrors ": true,
123
- "_3_errorSummary ": "Error encountered for .../assets/e4/tsdoc.json:
124
+ "s0_filePath ": ".../assets/e4/tsdoc.json",
125
+ "s1_fileNotFound ": false,
126
+ "s2_hasErrors ": true,
127
+ "s3_errorSummary ": "Error encountered for .../assets/e4/tsdoc.json:
124
128
The \\"tagDefinitions\\" field specifies more than one tag with the name \\"@dupe\\"
125
129
",
126
- "_4_log ": Array [
130
+ "s4_log ": Array [
127
131
"[tsdoc-config-duplicate-tag-name] The \\"tagDefinitions\\" field specifies more than one tag with the name \\"@dupe\\"",
128
132
],
129
- "_5_extends ": Array [],
133
+ "s5_extends ": Array [],
130
134
}
131
135
` ) ;
132
136
} ) ;
133
137
134
138
test ( 'Load e5' , ( ) => {
135
139
expect ( testLoadingFolder ( 'assets/e5' ) ) . toMatchInlineSnapshot ( `
136
140
Object {
137
- "_0_filePath ": ".../assets/e5/tsdoc.json",
138
- "_1_fileNotFound ": false,
139
- "_2_hasErrors ": true,
140
- "_3_errorSummary ": "Error encountered for .../assets/e5/ tsdoc-a.json:
141
- Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"
141
+ "s0_filePath ": ".../assets/e5/tsdoc.json",
142
+ "s1_fileNotFound ": false,
143
+ "s2_hasErrors ": true,
144
+ "s3_errorSummary ": "Error encountered for .../assets/e5\\\\ tsdoc-a.json:
145
+ Circular reference encountered for \\"extends\\" field of \\".../assets/e5\\\\ tsdoc-b.json\\"
142
146
143
- Error encountered for .../assets/e5/ tsdoc-c.json:
147
+ Error encountered for .../assets/e5\\\\ tsdoc-c.json:
144
148
Error loading config file: data should NOT have additional properties
145
149
",
146
- "_4_log ": Array [],
147
- "_5_extends ": Array [
150
+ "s4_log ": Array [],
151
+ "s5_extends ": Array [
148
152
Object {
149
- "_0_filePath ": ".../assets/e5/ tsdoc-a.json",
150
- "_1_fileNotFound ": false,
151
- "_2_hasErrors ": true,
152
- "_3_errorSummary ": "Error encountered for .../assets/e5/ tsdoc-a.json:
153
- Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"
153
+ "s0_filePath ": ".../assets/e5\\\\ tsdoc-a.json",
154
+ "s1_fileNotFound ": false,
155
+ "s2_hasErrors ": true,
156
+ "s3_errorSummary ": "Error encountered for .../assets/e5\\\\ tsdoc-a.json:
157
+ Circular reference encountered for \\"extends\\" field of \\".../assets/e5\\\\ tsdoc-b.json\\"
154
158
155
- Error encountered for .../assets/e5/ tsdoc-c.json:
159
+ Error encountered for .../assets/e5\\\\ tsdoc-c.json:
156
160
Error loading config file: data should NOT have additional properties
157
161
",
158
- "_4_log ": Array [],
159
- "_5_extends ": Array [
162
+ "s4_log ": Array [],
163
+ "s5_extends ": Array [
160
164
Object {
161
- "_0_filePath ": ".../assets/e5/ tsdoc-b.json",
162
- "_1_fileNotFound ": false,
163
- "_2_hasErrors ": true,
164
- "_3_errorSummary ": "Error encountered for .../assets/e5/ tsdoc-a.json:
165
- Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"
165
+ "s0_filePath ": ".../assets/e5\\\\ tsdoc-b.json",
166
+ "s1_fileNotFound ": false,
167
+ "s2_hasErrors ": true,
168
+ "s3_errorSummary ": "Error encountered for .../assets/e5\\\\ tsdoc-a.json:
169
+ Circular reference encountered for \\"extends\\" field of \\".../assets/e5\\\\ tsdoc-b.json\\"
166
170
",
167
- "_4_log ": Array [],
168
- "_5_extends ": Array [
171
+ "s4_log ": Array [],
172
+ "s5_extends ": Array [
169
173
Object {
170
- "_0_filePath ": ".../assets/e5/ tsdoc-a.json",
171
- "_1_fileNotFound ": false,
172
- "_2_hasErrors ": true,
173
- "_3_errorSummary ": "Error encountered for .../assets/e5/ tsdoc-a.json:
174
- Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"
174
+ "s0_filePath ": ".../assets/e5\\\\ tsdoc-a.json",
175
+ "s1_fileNotFound ": false,
176
+ "s2_hasErrors ": true,
177
+ "s3_errorSummary ": "Error encountered for .../assets/e5\\\\ tsdoc-a.json:
178
+ Circular reference encountered for \\"extends\\" field of \\".../assets/e5\\\\ tsdoc-b.json\\"
175
179
",
176
- "_4_log ": Array [
177
- "[tsdoc-config-cyclic-extends] Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"",
180
+ "s4_log ": Array [
181
+ "[tsdoc-config-cyclic-extends] Circular reference encountered for \\"extends\\" field of \\".../assets/e5\\\\ tsdoc-b.json\\"",
178
182
],
179
- "_5_extends ": Array [],
183
+ "s5_extends ": Array [],
180
184
},
181
185
],
182
186
},
183
187
Object {
184
- "_0_filePath ": ".../assets/e5/ tsdoc-c.json",
185
- "_1_fileNotFound ": false,
186
- "_2_hasErrors ": true,
187
- "_3_errorSummary ": "Error encountered for .../assets/e5/ tsdoc-c.json:
188
+ "s0_filePath ": ".../assets/e5\\\\ tsdoc-c.json",
189
+ "s1_fileNotFound ": false,
190
+ "s2_hasErrors ": true,
191
+ "s3_errorSummary ": "Error encountered for .../assets/e5\\\\ tsdoc-c.json:
188
192
Error loading config file: data should NOT have additional properties
189
193
",
190
- "_4_log ": Array [
194
+ "s4_log ": Array [
191
195
"[tsdoc-config-schema-error] Error loading config file: data should NOT have additional properties",
192
196
],
193
- "_5_extends ": Array [],
197
+ "s5_extends ": Array [],
194
198
},
195
199
],
196
200
},
197
201
],
198
202
}
199
203
` ) ;
200
204
} ) ;
205
+
206
+ test ( 'Load e6' , ( ) => {
207
+ expect ( testLoadingFolder ( 'assets/e6' ) ) . toMatchInlineSnapshot ( `
208
+ Object {
209
+ "s0_filePath": ".../assets/e6/tsdoc.json",
210
+ "s1_fileNotFound": false,
211
+ "s2_hasErrors": true,
212
+ "s3_errorSummary": "Error encountered for .../assets/e6/tsdoc.json:
213
+ Unable to resolve \\"extends\\" reference to \\"@rushstack/nonexistent-package/tsdoc.json\\": Cannot find module '@rushstack/nonexistent-package/tsdoc.json' from '.../assets/e6'
214
+ ",
215
+ "s4_log": Array [
216
+ "[tsdoc-config-unresolved-extends] Unable to resolve \\"extends\\" reference to \\"@rushstack/nonexistent-package/tsdoc.json\\": Cannot find module '@rushstack/nonexistent-package/tsdoc.json' from '.../assets/e6'",
217
+ ],
218
+ "s5_extends": Array [],
219
+ }
220
+ ` ) ;
221
+ } ) ;
222
+
223
+ test ( 'Load e7' , ( ) => {
224
+ const configFile : TSDocConfigFile = TSDocConfigFile . loadForFolder ( path . join ( __dirname , 'assets/e7' ) ) ;
225
+
226
+ const pathFixupMap : Map < string , string > = new Map ( ) ;
227
+ buildStablePathMap ( pathFixupMap , configFile ) ;
228
+
229
+ expect ( createSnapshot ( configFile , pathFixupMap ) ) . toMatchInlineSnapshot ( `
230
+ Object {
231
+ "s0_filePath": ".../assets/e7/tsdoc.json",
232
+ "s1_fileNotFound": false,
233
+ "s2_hasErrors": false,
234
+ "s3_errorSummary": "No errors.",
235
+ "s4_log": Array [],
236
+ "s5_extends": Array [],
237
+ }
238
+ ` ) ;
239
+
240
+ // The "tsdoc-config-undefined-tag" error is NOT detected by TSDocConfigFile.loadForFolder()
241
+ expect ( configFile . hasErrors ) . toBe ( false ) ;
242
+
243
+ const configuration : TSDocConfiguration = new TSDocConfiguration ( ) ;
244
+ configFile . configureParser ( configuration ) ;
245
+
246
+ expect ( createSnapshot ( configFile , pathFixupMap ) ) . toMatchInlineSnapshot ( `
247
+ Object {
248
+ "s0_filePath": ".../assets/e7/tsdoc.json",
249
+ "s1_fileNotFound": false,
250
+ "s2_hasErrors": true,
251
+ "s3_errorSummary": "Error encountered for .../assets/e7/tsdoc.json:
252
+ The \\"supportForTags\\" field refers to an undefined tag \\"@nonExistentTag\\".
253
+ ",
254
+ "s4_log": Array [
255
+ "[tsdoc-config-undefined-tag] The \\"supportForTags\\" field refers to an undefined tag \\"@nonExistentTag\\".",
256
+ ],
257
+ "s5_extends": Array [],
258
+ }
259
+ ` ) ;
260
+
261
+ // The "tsdoc-config-undefined-tag" error IS detected by TSDocConfigFile.configureParser()
262
+ expect ( configFile . hasErrors ) . toBe ( true ) ;
263
+ } ) ;
0 commit comments