@@ -12,13 +12,19 @@ interface ISnapshot {
12
12
s5_extends : ISnapshot [ ] ;
13
13
}
14
14
15
+ function replaceAll ( text : string , search : string , replace : string ) : string {
16
+ return text . split ( search ) . join ( replace ) ;
17
+ }
18
+
15
19
// To make the unit tests deterministic, we need to replace all OS-dependent absolute paths
16
20
// with OS-independent paths that are relative to the unit test folder.
17
21
function makeStablePath ( testPath : string ) : string {
18
22
if ( testPath . length === 0 ) {
19
23
return '' ;
20
24
}
21
- return '.../' + path . relative ( __dirname , testPath ) . split ( '\\' ) . join ( '/' ) ;
25
+ console . log ( 'IN: ' + testPath ) ;
26
+ console . log ( 'OUT: ' + replaceAll ( path . relative ( __dirname , testPath ) , '\\' , '/' ) ) ;
27
+ return '.../' + replaceAll ( path . relative ( __dirname , testPath ) , '\\' , '/' ) ;
22
28
}
23
29
24
30
// Build a map from absolute path --> stable path, for each TSDocConfigFile.filePath value
@@ -37,9 +43,14 @@ function buildStablePathMap(stablePathMap: Map<string, string>, configFile: TSDo
37
43
// Search and replace all absolute paths with the corresponding stable path.
38
44
// For example, "Found C:\A\B\C.txt in C:\A\D\E.txt" becomes "Found .../B/C.txt in .../D/E.txt".
39
45
function convertToStablePaths ( text : string , stablePathMap : Map < string , string > ) : string {
40
- for ( const pair of Array . from ( stablePathMap . entries ( ) ) ) {
41
- text = text . split ( pair [ 0 ] ) . join ( pair [ 1 ] ) ;
46
+ // Sort the [key,value] pairs by key length from longest to shortest.
47
+ // This ensures that a shorter path does not replace a subpath of a longer path.
48
+ const pairs : [ string , string ] [ ] = Array . from ( stablePathMap . entries ( ) ) . sort ( ( x , y ) => y [ 0 ] . length - x [ 0 ] . length ) ;
49
+ for ( const pair of pairs ) {
50
+ text = replaceAll ( text , pair [ 0 ] , pair [ 1 ] ) ;
42
51
}
52
+ // Also convert any loose backslashes to slashes
53
+ //text = replaceAll(text, '\\', '/');
43
54
return text ;
44
55
}
45
56
@@ -141,54 +152,54 @@ test('Load e5', () => {
141
152
"s0_filePath": ".../assets/e5/tsdoc.json",
142
153
"s1_fileNotFound": false,
143
154
"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\\"
155
+ "s3_errorSummary": "Error encountered for .../assets/e5/ tsdoc-a.json:
156
+ Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"
146
157
147
- Error encountered for .../assets/e5\\\\ tsdoc-c.json:
158
+ Error encountered for .../assets/e5/ tsdoc-c.json:
148
159
Error loading config file: data should NOT have additional properties
149
160
",
150
161
"s4_log": Array [],
151
162
"s5_extends": Array [
152
163
Object {
153
- "s0_filePath": ".../assets/e5\\\\ tsdoc-a.json",
164
+ "s0_filePath": ".../assets/e5/ tsdoc-a.json",
154
165
"s1_fileNotFound": false,
155
166
"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\\"
167
+ "s3_errorSummary": "Error encountered for .../assets/e5/ tsdoc-a.json:
168
+ Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"
158
169
159
- Error encountered for .../assets/e5\\\\ tsdoc-c.json:
170
+ Error encountered for .../assets/e5/ tsdoc-c.json:
160
171
Error loading config file: data should NOT have additional properties
161
172
",
162
173
"s4_log": Array [],
163
174
"s5_extends": Array [
164
175
Object {
165
- "s0_filePath": ".../assets/e5\\\\ tsdoc-b.json",
176
+ "s0_filePath": ".../assets/e5/ tsdoc-b.json",
166
177
"s1_fileNotFound": false,
167
178
"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\\"
179
+ "s3_errorSummary": "Error encountered for .../assets/e5/ tsdoc-a.json:
180
+ Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"
170
181
",
171
182
"s4_log": Array [],
172
183
"s5_extends": Array [
173
184
Object {
174
- "s0_filePath": ".../assets/e5\\\\ tsdoc-a.json",
185
+ "s0_filePath": ".../assets/e5/ tsdoc-a.json",
175
186
"s1_fileNotFound": false,
176
187
"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\\"
188
+ "s3_errorSummary": "Error encountered for .../assets/e5/ tsdoc-a.json:
189
+ Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"
179
190
",
180
191
"s4_log": Array [
181
- "[tsdoc-config-cyclic-extends] Circular reference encountered for \\"extends\\" field of \\".../assets/e5\\\\ tsdoc-b.json\\"",
192
+ "[tsdoc-config-cyclic-extends] Circular reference encountered for \\"extends\\" field of \\".../assets/e5/ tsdoc-b.json\\"",
182
193
],
183
194
"s5_extends": Array [],
184
195
},
185
196
],
186
197
},
187
198
Object {
188
- "s0_filePath": ".../assets/e5\\\\ tsdoc-c.json",
199
+ "s0_filePath": ".../assets/e5/ tsdoc-c.json",
189
200
"s1_fileNotFound": false,
190
201
"s2_hasErrors": true,
191
- "s3_errorSummary": "Error encountered for .../assets/e5\\\\ tsdoc-c.json:
202
+ "s3_errorSummary": "Error encountered for .../assets/e5/ tsdoc-c.json:
192
203
Error loading config file: data should NOT have additional properties
193
204
",
194
205
"s4_log": Array [
0 commit comments