1
1
namespace ts {
2
2
describe ( "unittests:: tsbuild:: with resolveJsonModule option on project resolveJsonModuleAndComposite" , ( ) => {
3
3
let projFs : vfs . FileSystem ;
4
- const allExpectedOutputs = [ "/src/dist/src/index.js" , "/src/dist/src/index.d.ts" , "/src/dist/src/hello.json" ] ;
5
4
before ( ( ) => {
6
5
projFs = loadProjectFromDisk ( "tests/projects/resolveJsonModuleAndComposite" ) ;
7
6
} ) ;
@@ -10,108 +9,64 @@ namespace ts {
10
9
projFs = undefined ! ; // Release the contents
11
10
} ) ;
12
11
13
- function verifyProjectWithResolveJsonModule ( configFile : string , ...expectedDiagnosticMessages : fakes . ExpectedDiagnostic [ ] ) {
14
- const fs = projFs . shadow ( ) ;
15
- verifyProjectWithResolveJsonModuleWithFs ( fs , configFile , allExpectedOutputs , ...expectedDiagnosticMessages ) ;
16
- }
17
-
18
- function verifyProjectWithResolveJsonModuleWithFs ( fs : vfs . FileSystem , configFile : string , allExpectedOutputs : readonly string [ ] , ...expectedDiagnosticMessages : fakes . ExpectedDiagnostic [ ] ) {
19
- const host = fakes . SolutionBuilderHost . create ( fs ) ;
20
- const builder = createSolutionBuilder ( host , [ configFile ] , { dry : false , force : false , verbose : false } ) ;
21
- builder . build ( ) ;
22
- host . assertDiagnosticMessages ( ...expectedDiagnosticMessages ) ;
23
- if ( ! expectedDiagnosticMessages . length ) {
24
- // Check for outputs. Not an exhaustive list
25
- verifyOutputsPresent ( fs , allExpectedOutputs ) ;
26
- }
27
- }
28
-
29
- it ( "with resolveJsonModule and include only" , ( ) => {
30
- verifyProjectWithResolveJsonModule (
31
- "/src/tsconfig_withInclude.json" ,
32
- {
33
- message : [
34
- Diagnostics . File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern ,
35
- "/src/src/hello.json" ,
36
- "/src/tsconfig_withInclude.json"
37
- ] ,
38
- location : expectedLocationIndexOf ( projFs , "/src/src/index.ts" , `"./hello.json"` )
39
- }
40
- ) ;
12
+ verifyTsc ( {
13
+ scenario : "resolveJsonModule" ,
14
+ subScenario : "include only" ,
15
+ fs : ( ) => projFs ,
16
+ commandLineArgs : [ "--b" , "/src/tsconfig_withInclude.json" ] ,
41
17
} ) ;
42
18
43
- it ( "with resolveJsonModule and include of *.json along with other include" , ( ) => {
44
- verifyProjectWithResolveJsonModule ( "/src/tsconfig_withIncludeOfJson.json" ) ;
19
+ verifyTsc ( {
20
+ scenario : "resolveJsonModule" ,
21
+ subScenario : "include of json along with other include" ,
22
+ fs : ( ) => projFs ,
23
+ commandLineArgs : [ "--b" , "/src/tsconfig_withIncludeOfJson.json" ] ,
45
24
} ) ;
46
25
47
- it ( "with resolveJsonModule and include of *.json along with other include and file name matches ts file" , ( ) => {
48
- const fs = projFs . shadow ( ) ;
49
- fs . rimrafSync ( "/src/src/hello.json" ) ;
50
- fs . writeFileSync ( "/src/src/index.json" , JSON . stringify ( { hello : "world" } ) ) ;
51
- fs . writeFileSync ( "/src/src/index.ts" , `import hello from "./index.json"
26
+ verifyTsc ( {
27
+ scenario : "resolveJsonModule" ,
28
+ subScenario : "include of json along with other include and file name matches ts file" ,
29
+ fs : ( ) => projFs ,
30
+ commandLineArgs : [ "--b" , "/src/tsconfig_withIncludeOfJson.json" ] ,
31
+ modifyFs : fs => {
32
+ fs . rimrafSync ( "/src/src/hello.json" ) ;
33
+ fs . writeFileSync ( "/src/src/index.json" , JSON . stringify ( { hello : "world" } ) ) ;
34
+ fs . writeFileSync ( "/src/src/index.ts" , `import hello from "./index.json"
52
35
53
36
export default hello.hello` ) ;
54
- const allExpectedOutputs = [ "/src/dist/src/index.js" , "/src/dist/src/index.d.ts" , "/src/dist/src/index.json" ] ;
55
- verifyProjectWithResolveJsonModuleWithFs (
56
- fs ,
57
- "/src/tsconfig_withIncludeOfJson.json" ,
58
- allExpectedOutputs ,
59
- errorDiagnostic ( [ Diagnostics . Cannot_write_file_0_because_it_would_be_overwritten_by_multiple_input_files , "/src/dist/src/index.d.ts" ] )
60
- ) ;
37
+ } ,
61
38
} ) ;
62
39
63
- it ( "with resolveJsonModule and files containing json file" , ( ) => {
64
- verifyProjectWithResolveJsonModule ( "/src/tsconfig_withFiles.json" ) ;
40
+ verifyTsc ( {
41
+ scenario : "resolveJsonModule" ,
42
+ subScenario : "files containing json file" ,
43
+ fs : ( ) => projFs ,
44
+ commandLineArgs : [ "--b" , "/src/tsconfig_withFiles.json" ] ,
65
45
} ) ;
66
46
67
- it ( "with resolveJsonModule and include and files" , ( ) => {
68
- verifyProjectWithResolveJsonModule ( "/src/tsconfig_withIncludeAndFiles.json" ) ;
47
+ verifyTsc ( {
48
+ scenario : "resolveJsonModule" ,
49
+ subScenario : "include and files" ,
50
+ fs : ( ) => projFs ,
51
+ commandLineArgs : [ "--b" , "/src/tsconfig_withIncludeAndFiles.json" ] ,
69
52
} ) ;
70
53
71
- it ( "with resolveJsonModule and sourceMap" , ( ) => {
72
- const { fs, tick } = getFsWithTime ( projFs ) ;
73
- const configFile = "src/tsconfig_withFiles.json" ;
74
- replaceText ( fs , configFile , `"composite": true,` , `"composite": true, "sourceMap": true,` ) ;
75
- const host = fakes . SolutionBuilderHost . create ( fs ) ;
76
- let builder = createSolutionBuilder ( host , [ configFile ] , { verbose : true } ) ;
77
- builder . build ( ) ;
78
- host . assertDiagnosticMessages (
79
- getExpectedDiagnosticForProjectsInBuild ( configFile ) ,
80
- [ Diagnostics . Project_0_is_out_of_date_because_output_file_1_does_not_exist , configFile , "src/dist/src/index.js" ] ,
81
- [ Diagnostics . Building_project_0 , `/${ configFile } ` ]
82
- ) ;
83
- verifyOutputsPresent ( fs , [ ...allExpectedOutputs , "/src/dist/src/index.js.map" ] ) ;
84
- host . clearDiagnostics ( ) ;
85
- builder = createSolutionBuilder ( host , [ configFile ] , { verbose : true } ) ;
86
- tick ( ) ;
87
- builder . build ( ) ;
88
- host . assertDiagnosticMessages (
89
- getExpectedDiagnosticForProjectsInBuild ( configFile ) ,
90
- [ Diagnostics . Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2 , configFile , "src/src/index.ts" , "src/dist/src/index.js" ]
91
- ) ;
54
+ verifyTscIncrementalEdits ( {
55
+ scenario : "resolveJsonModule" ,
56
+ subScenario : "sourcemap" ,
57
+ fs : ( ) => projFs ,
58
+ commandLineArgs : [ "--b" , "src/tsconfig_withFiles.json" , "--verbose" ] ,
59
+ modifyFs : fs => replaceText ( fs , "src/tsconfig_withFiles.json" , `"composite": true,` , `"composite": true, "sourceMap": true,` ) ,
60
+ incrementalScenarios : [ noChangeRun ]
92
61
} ) ;
93
62
94
- it ( "with resolveJsonModule and without outDir" , ( ) => {
95
- const { fs, tick } = getFsWithTime ( projFs ) ;
96
- const configFile = "src/tsconfig_withFiles.json" ;
97
- replaceText ( fs , configFile , `"outDir": "dist",` , "" ) ;
98
- const host = fakes . SolutionBuilderHost . create ( fs ) ;
99
- let builder = createSolutionBuilder ( host , [ configFile ] , { verbose : true } ) ;
100
- builder . build ( ) ;
101
- host . assertDiagnosticMessages (
102
- getExpectedDiagnosticForProjectsInBuild ( configFile ) ,
103
- [ Diagnostics . Project_0_is_out_of_date_because_output_file_1_does_not_exist , configFile , "src/src/index.js" ] ,
104
- [ Diagnostics . Building_project_0 , `/${ configFile } ` ]
105
- ) ;
106
- verifyOutputsPresent ( fs , [ "/src/src/index.js" , "/src/src/index.d.ts" ] ) ;
107
- host . clearDiagnostics ( ) ;
108
- builder = createSolutionBuilder ( host , [ configFile ] , { verbose : true } ) ;
109
- tick ( ) ;
110
- builder . build ( ) ;
111
- host . assertDiagnosticMessages (
112
- getExpectedDiagnosticForProjectsInBuild ( configFile ) ,
113
- [ Diagnostics . Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2 , configFile , "src/src/index.ts" , "src/src/index.js" ]
114
- ) ;
63
+ verifyTscIncrementalEdits ( {
64
+ scenario : "resolveJsonModule" ,
65
+ subScenario : "without outDir" ,
66
+ fs : ( ) => projFs ,
67
+ commandLineArgs : [ "--b" , "src/tsconfig_withFiles.json" , "--verbose" ] ,
68
+ modifyFs : fs => replaceText ( fs , "src/tsconfig_withFiles.json" , `"outDir": "dist",` , "" ) ,
69
+ incrementalScenarios : [ noChangeRun ]
115
70
} ) ;
116
71
} ) ;
117
72
@@ -125,32 +80,12 @@ export default hello.hello`);
125
80
projFs = undefined ! ; // Release the contents
126
81
} ) ;
127
82
128
- it ( "when importing json module from project reference" , ( ) => {
129
- const expectedOutput = "/src/main/index.js" ;
130
- const { fs, tick } = getFsWithTime ( projFs ) ;
131
- const configFile = "src/tsconfig.json" ;
132
- const stringsConfigFile = "src/strings/tsconfig.json" ;
133
- const mainConfigFile = "src/main/tsconfig.json" ;
134
- const host = fakes . SolutionBuilderHost . create ( fs ) ;
135
- let builder = createSolutionBuilder ( host , [ configFile ] , { verbose : true } ) ;
136
- builder . build ( ) ;
137
- host . assertDiagnosticMessages (
138
- getExpectedDiagnosticForProjectsInBuild ( stringsConfigFile , mainConfigFile , configFile ) ,
139
- [ Diagnostics . Project_0_is_out_of_date_because_output_file_1_does_not_exist , stringsConfigFile , "src/strings/tsconfig.tsbuildinfo" ] ,
140
- [ Diagnostics . Building_project_0 , `/${ stringsConfigFile } ` ] ,
141
- [ Diagnostics . Project_0_is_out_of_date_because_output_file_1_does_not_exist , mainConfigFile , "src/main/index.js" ] ,
142
- [ Diagnostics . Building_project_0 , `/${ mainConfigFile } ` ] ,
143
- ) ;
144
- verifyOutputsPresent ( fs , [ expectedOutput ] ) ;
145
- host . clearDiagnostics ( ) ;
146
- builder = createSolutionBuilder ( host , [ configFile ] , { verbose : true } ) ;
147
- tick ( ) ;
148
- builder . build ( ) ;
149
- host . assertDiagnosticMessages (
150
- getExpectedDiagnosticForProjectsInBuild ( stringsConfigFile , mainConfigFile , configFile ) ,
151
- [ Diagnostics . Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2 , stringsConfigFile , "src/strings/foo.json" , "src/strings/tsconfig.tsbuildinfo" ] ,
152
- [ Diagnostics . Project_0_is_up_to_date_because_newest_input_1_is_older_than_oldest_output_2 , mainConfigFile , "src/main/index.ts" , "src/main/index.js" ] ,
153
- ) ;
83
+ verifyTscIncrementalEdits ( {
84
+ scenario : "resolveJsonModule" ,
85
+ subScenario : "importing json module from project reference" ,
86
+ fs : ( ) => projFs ,
87
+ commandLineArgs : [ "--b" , "src/tsconfig.json" , "--verbose" ] ,
88
+ incrementalScenarios : [ noChangeRun ]
154
89
} ) ;
155
90
} ) ;
156
91
}
0 commit comments