Skip to content

Commit 5b694f8

Browse files
Add tests for module and esModuleInterop affectsEmit change
1 parent 4195f1a commit 5b694f8

File tree

5 files changed

+427
-1
lines changed

5 files changed

+427
-1
lines changed

src/testRunner/unittests/tsbuild/sample.ts

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ class someClass { }`),
906906
"target": "esnext",
907907
}
908908
}`);
909-
},
909+
},
910910
expectedDiagnostics: [
911911
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"),
912912
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.js"],
@@ -931,6 +931,88 @@ class someClass { }`),
931931
baselineOnly: true,
932932
verifyDiagnostics: true
933933
});
934+
935+
verifyTsbuildOutput({
936+
scenario: "when module option changes",
937+
projFs: () => projFs,
938+
time,
939+
tick,
940+
proj: "sample1",
941+
rootNames: ["/src/core"],
942+
expectedMapFileNames: emptyArray,
943+
lastProjectOutputJs: "/src/core/index.js",
944+
initialBuild: {
945+
modifyFs: fs => fs.writeFileSync("/src/core/tsconfig.json", `{
946+
"compilerOptions": {
947+
"incremental": true,
948+
"module": "commonjs"
949+
}
950+
}`),
951+
expectedDiagnostics: [
952+
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"),
953+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/core/tsconfig.json", "src/core/anotherModule.js"],
954+
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"],
955+
]
956+
},
957+
incrementalDtsChangedBuild: {
958+
modifyFs: fs => replaceText(fs, "/src/core/tsconfig.json", `"module": "commonjs"`, `"module": "amd"`),
959+
expectedDiagnostics: [
960+
getExpectedDiagnosticForProjectsInBuild("src/core/tsconfig.json"),
961+
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/core/tsconfig.json", "src/core/anotherModule.js", "src/core/tsconfig.json"],
962+
[Diagnostics.Building_project_0, "/src/core/tsconfig.json"]
963+
]
964+
},
965+
outputFiles: [
966+
"/src/core/anotherModule.js",
967+
"/src/core/index.js",
968+
"/src/core/tsconfig.tsbuildinfo",
969+
],
970+
baselineOnly: true,
971+
verifyDiagnostics: true
972+
});
973+
974+
verifyTsbuildOutput({
975+
scenario: "when esModuleInterop option changes",
976+
projFs: () => projFs,
977+
time,
978+
tick,
979+
proj: "sample1",
980+
rootNames: ["/src/tests"],
981+
expectedMapFileNames: emptyArray,
982+
lastProjectOutputJs: "/src/tests/index.js",
983+
initialBuild: {
984+
modifyFs: fs => fs.writeFileSync("/src/tests/tsconfig.json", `{
985+
"compilerOptions": {
986+
"incremental": true,
987+
"module": "commonjs",
988+
"esModuleInterop": false
989+
}
990+
}`),
991+
expectedDiagnostics: [
992+
getExpectedDiagnosticForProjectsInBuild("src/tests/tsconfig.json"),
993+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/tests/tsconfig.json", "src/tests/index.js"],
994+
[Diagnostics.Building_project_0, "/src/tests/tsconfig.json"],
995+
]
996+
},
997+
incrementalDtsChangedBuild: {
998+
modifyFs: fs => replaceText(fs, "/src/tests/tsconfig.json", `"esModuleInterop": false`, `"esModuleInterop": true`),
999+
expectedDiagnostics: [
1000+
getExpectedDiagnosticForProjectsInBuild("src/tests/tsconfig.json"),
1001+
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tests/tsconfig.json", "src/tests/index.js", "src/tests/tsconfig.json"],
1002+
[Diagnostics.Building_project_0, "/src/tests/tsconfig.json"]
1003+
]
1004+
},
1005+
outputFiles: [
1006+
"/src/core/anotherModule.js",
1007+
"/src/core/index.js",
1008+
"/src/logic/index.js",
1009+
"/src/tests/index.js",
1010+
"/src/tests/tsconfig.json",
1011+
"/src/tests/tsconfig.tsbuildinfo"
1012+
],
1013+
baselineOnly: true,
1014+
verifyDiagnostics: true
1015+
});
9341016
});
9351017
});
9361018
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//// [/src/logic/index.js]
2+
"use strict";
3+
var __importStar = (this && this.__importStar) || function (mod) {
4+
if (mod && mod.__esModule) return mod;
5+
var result = {};
6+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
7+
result["default"] = mod;
8+
return result;
9+
};
10+
exports.__esModule = true;
11+
var c = __importStar(require("../core/index"));
12+
function getSecondsInDay() {
13+
return c.multiply(10, 15);
14+
}
15+
exports.getSecondsInDay = getSecondsInDay;
16+
var mod = __importStar(require("../core/anotherModule"));
17+
exports.m = mod;
18+
19+
20+
//// [/src/tests/index.js]
21+
"use strict";
22+
var __importStar = (this && this.__importStar) || function (mod) {
23+
if (mod && mod.__esModule) return mod;
24+
var result = {};
25+
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
26+
result["default"] = mod;
27+
return result;
28+
};
29+
exports.__esModule = true;
30+
var c = __importStar(require("../core/index"));
31+
var logic = __importStar(require("../logic/index"));
32+
c.leftPad("", 10);
33+
logic.getSecondsInDay();
34+
var mod = __importStar(require("../core/anotherModule"));
35+
exports.m = mod;
36+
37+
38+
//// [/src/tests/tsconfig.json]
39+
{
40+
"compilerOptions": {
41+
"incremental": true,
42+
"module": "commonjs",
43+
"esModuleInterop": true
44+
}
45+
}
46+
47+
//// [/src/tests/tsconfig.tsbuildinfo]
48+
{
49+
"program": {
50+
"fileInfos": {
51+
"../../lib/lib.d.ts": {
52+
"version": "-15964756381",
53+
"signature": "-15964756381"
54+
},
55+
"../core/index.ts": {
56+
"version": "-18749805970",
57+
"signature": "1874987148"
58+
},
59+
"../core/anothermodule.ts": {
60+
"version": "-2676574883",
61+
"signature": "-8396256275"
62+
},
63+
"../logic/index.ts": {
64+
"version": "-5786964698",
65+
"signature": "-6548680073"
66+
},
67+
"./index.ts": {
68+
"version": "12336236525",
69+
"signature": "-9209611"
70+
}
71+
},
72+
"options": {
73+
"incremental": true,
74+
"module": 1,
75+
"esModuleInterop": true,
76+
"configFilePath": "./tsconfig.json"
77+
},
78+
"referencedMap": {
79+
"../logic/index.ts": [
80+
"../core/anothermodule.ts",
81+
"../core/index.ts"
82+
],
83+
"./index.ts": [
84+
"../core/anothermodule.ts",
85+
"../core/index.ts",
86+
"../logic/index.ts"
87+
]
88+
},
89+
"exportedModulesMap": {
90+
"../logic/index.ts": [
91+
"../core/anothermodule.ts"
92+
],
93+
"./index.ts": [
94+
"../core/anothermodule.ts"
95+
]
96+
},
97+
"semanticDiagnosticsPerFile": [
98+
"../../lib/lib.d.ts",
99+
"../core/anothermodule.ts",
100+
"../core/index.ts",
101+
"../logic/index.ts",
102+
"./index.ts"
103+
]
104+
},
105+
"version": "FakeTSVersion"
106+
}
107+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//// [/src/core/anotherModule.js]
2+
define(["require", "exports"], function (require, exports) {
3+
"use strict";
4+
exports.__esModule = true;
5+
exports.World = "hello";
6+
});
7+
8+
9+
//// [/src/core/index.js]
10+
define(["require", "exports"], function (require, exports) {
11+
"use strict";
12+
exports.__esModule = true;
13+
exports.someString = "HELLO WORLD";
14+
function leftPad(s, n) { return s + n; }
15+
exports.leftPad = leftPad;
16+
function multiply(a, b) { return a * b; }
17+
exports.multiply = multiply;
18+
});
19+
20+
21+
//// [/src/core/tsconfig.json]
22+
{
23+
"compilerOptions": {
24+
"incremental": true,
25+
"module": "amd"
26+
}
27+
}
28+
29+
//// [/src/core/tsconfig.tsbuildinfo]
30+
{
31+
"program": {
32+
"fileInfos": {
33+
"../../lib/lib.d.ts": {
34+
"version": "-15964756381",
35+
"signature": "-15964756381"
36+
},
37+
"./anothermodule.ts": {
38+
"version": "-2676574883",
39+
"signature": "-8396256275"
40+
},
41+
"./index.ts": {
42+
"version": "-18749805970",
43+
"signature": "1874987148"
44+
},
45+
"./some_decl.d.ts": {
46+
"version": "-9253692965",
47+
"signature": "-9253692965"
48+
}
49+
},
50+
"options": {
51+
"incremental": true,
52+
"module": 2,
53+
"configFilePath": "./tsconfig.json"
54+
},
55+
"referencedMap": {},
56+
"exportedModulesMap": {},
57+
"semanticDiagnosticsPerFile": [
58+
"../../lib/lib.d.ts",
59+
"./anothermodule.ts",
60+
"./index.ts",
61+
"./some_decl.d.ts"
62+
]
63+
},
64+
"version": "FakeTSVersion"
65+
}
66+
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//// [/src/core/anotherModule.js]
2+
"use strict";
3+
exports.__esModule = true;
4+
exports.World = "hello";
5+
6+
7+
//// [/src/core/index.js]
8+
"use strict";
9+
exports.__esModule = true;
10+
exports.someString = "HELLO WORLD";
11+
function leftPad(s, n) { return s + n; }
12+
exports.leftPad = leftPad;
13+
function multiply(a, b) { return a * b; }
14+
exports.multiply = multiply;
15+
16+
17+
//// [/src/logic/index.js]
18+
"use strict";
19+
exports.__esModule = true;
20+
var c = require("../core/index");
21+
function getSecondsInDay() {
22+
return c.multiply(10, 15);
23+
}
24+
exports.getSecondsInDay = getSecondsInDay;
25+
var mod = require("../core/anotherModule");
26+
exports.m = mod;
27+
28+
29+
//// [/src/tests/index.js]
30+
"use strict";
31+
exports.__esModule = true;
32+
var c = require("../core/index");
33+
var logic = require("../logic/index");
34+
c.leftPad("", 10);
35+
logic.getSecondsInDay();
36+
var mod = require("../core/anotherModule");
37+
exports.m = mod;
38+
39+
40+
//// [/src/tests/tsconfig.json]
41+
{
42+
"compilerOptions": {
43+
"incremental": true,
44+
"module": "commonjs",
45+
"esModuleInterop": false
46+
}
47+
}
48+
49+
//// [/src/tests/tsconfig.tsbuildinfo]
50+
{
51+
"program": {
52+
"fileInfos": {
53+
"../../lib/lib.d.ts": {
54+
"version": "-15964756381",
55+
"signature": "-15964756381"
56+
},
57+
"../core/index.ts": {
58+
"version": "-18749805970",
59+
"signature": "1874987148"
60+
},
61+
"../core/anothermodule.ts": {
62+
"version": "-2676574883",
63+
"signature": "-8396256275"
64+
},
65+
"../logic/index.ts": {
66+
"version": "-5786964698",
67+
"signature": "-6548680073"
68+
},
69+
"./index.ts": {
70+
"version": "12336236525",
71+
"signature": "-9209611"
72+
}
73+
},
74+
"options": {
75+
"incremental": true,
76+
"module": 1,
77+
"esModuleInterop": false,
78+
"configFilePath": "./tsconfig.json"
79+
},
80+
"referencedMap": {
81+
"../logic/index.ts": [
82+
"../core/anothermodule.ts",
83+
"../core/index.ts"
84+
],
85+
"./index.ts": [
86+
"../core/anothermodule.ts",
87+
"../core/index.ts",
88+
"../logic/index.ts"
89+
]
90+
},
91+
"exportedModulesMap": {
92+
"../logic/index.ts": [
93+
"../core/anothermodule.ts"
94+
],
95+
"./index.ts": [
96+
"../core/anothermodule.ts"
97+
]
98+
},
99+
"semanticDiagnosticsPerFile": [
100+
"../../lib/lib.d.ts",
101+
"../core/anothermodule.ts",
102+
"../core/index.ts",
103+
"../logic/index.ts",
104+
"./index.ts"
105+
]
106+
},
107+
"version": "FakeTSVersion"
108+
}
109+

0 commit comments

Comments
 (0)