Skip to content

Commit 707cb93

Browse files
committed
Write test case that baselines the incremental build result
Testcase for microsoft#30780
1 parent f617d16 commit 707cb93

File tree

10 files changed

+315
-1
lines changed

10 files changed

+315
-1
lines changed

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"unittests/tsbuild/amdModulesWithOut.ts",
9393
"unittests/tsbuild/emptyFiles.ts",
9494
"unittests/tsbuild/graphOrdering.ts",
95+
"unittests/tsbuild//inferredTypeFromTransitiveModule.ts",
9596
"unittests/tsbuild/missingExtendedFile.ts",
9697
"unittests/tsbuild/outFile.ts",
9798
"unittests/tsbuild/referencesWithRootDirInParent.ts",

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ Mismatch Actual(path, actual, expected): ${JSON.stringify(arrayFrom(mapDefinedIt
305305
actualReadFileMap = undefined!;
306306
host = undefined!;
307307
});
308-
if (!baselineOnly) {
308+
if (!baselineOnly || verifyDiagnostics) {
309309
it(`verify diagnostics`, () => {
310310
host.assertDiagnosticMessages(...(incrementalExpectedDiagnostics || emptyArray));
311311
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace ts {
2+
describe("unittests:: tsbuild:: inferredTypeFromTransitiveModule::", () => {
3+
let projFs: vfs.FileSystem;
4+
const { time, tick } = getTime();
5+
before(() => {
6+
projFs = loadProjectFromDisk("tests/projects/inferredTypeFromTransitiveModule", time);
7+
});
8+
after(() => {
9+
projFs = undefined!;
10+
});
11+
12+
verifyTsbuildOutput({
13+
scenario: "inferred type from transitive module",
14+
projFs: () => projFs,
15+
time,
16+
tick,
17+
proj: "inferredTypeFromTransitiveModule",
18+
rootNames: ["/src"],
19+
expectedMapFileNames: emptyArray,
20+
lastProjectOutputJs: `/src/obj/index.js`,
21+
outputFiles: [
22+
"/src/obj/bar.js", "/src/obj/bar.d.ts",
23+
"/src/obj/bundling.js", "/src/obj/bundling.d.ts",
24+
"/src/obj/lazyIndex.js", "/src/obj/lazyIndex.d.ts",
25+
"/src/obj/index.js", "/src/obj/index.d.ts",
26+
"/src/obj/tsconfig.tsbuildinfo"
27+
],
28+
initialBuild: {
29+
modifyFs: noop,
30+
expectedDiagnostics: [
31+
getExpectedDiagnosticForProjectsInBuild("src/tsconfig.json"),
32+
[Diagnostics.Project_0_is_out_of_date_because_output_file_1_does_not_exist, "src/tsconfig.json", "src/obj/bar.js"],
33+
[Diagnostics.Building_project_0, "/src/tsconfig.json"]
34+
]
35+
},
36+
incrementalDtsChangedBuild: {
37+
modifyFs: fs => replaceText(fs, "/src/bar.ts", "param: string", ""),
38+
expectedDiagnostics: [
39+
getExpectedDiagnosticForProjectsInBuild("src/tsconfig.json"),
40+
[Diagnostics.Project_0_is_out_of_date_because_oldest_output_1_is_older_than_newest_input_2, "src/tsconfig.json", "src/obj/bar.js", "src/bar.ts"],
41+
[Diagnostics.Building_project_0, "/src/tsconfig.json"],
42+
[Diagnostics.Updating_unchanged_output_timestamps_of_project_0, "/src/tsconfig.json"]
43+
]
44+
},
45+
baselineOnly: true,
46+
verifyDiagnostics: true
47+
});
48+
});
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
//// [/src/bar.ts]
2+
interface RawAction {
3+
(...args: any[]): Promise<any> | void;
4+
}
5+
interface ActionFactory {
6+
<T extends RawAction>(target: T): T;
7+
}
8+
declare function foo<U extends any[] = any[]>(): ActionFactory;
9+
export default foo()(function foobar(): void {
10+
});
11+
12+
//// [/src/obj/bar.d.ts]
13+
declare const _default: () => void;
14+
export default _default;
15+
16+
17+
//// [/src/obj/bar.js]
18+
"use strict";
19+
Object.defineProperty(exports, "__esModule", { value: true });
20+
exports.default = foo()(function foobar() {
21+
});
22+
23+
24+
//// [/src/obj/tsconfig.tsbuildinfo]
25+
{
26+
"program": {
27+
"fileInfos": {
28+
"/lib/lib.es5.d.ts": {
29+
"version": "/lib/lib.es5.d.ts",
30+
"signature": "/lib/lib.es5.d.ts"
31+
},
32+
"/lib/lib.es2015.promise.d.ts": {
33+
"version": "/lib/lib.es2015.promise.d.ts",
34+
"signature": "/lib/lib.es2015.promise.d.ts"
35+
},
36+
"/src/bar.ts": {
37+
"version": "747071916",
38+
"signature": "-9232740537"
39+
},
40+
"/src/bundling.ts": {
41+
"version": "-21659820217",
42+
"signature": "-40032907372"
43+
},
44+
"/src/lazyindex.ts": {
45+
"version": "-6956449754",
46+
"signature": "-6224542381"
47+
},
48+
"/src/index.ts": {
49+
"version": "-11602502901",
50+
"signature": "18468008756"
51+
}
52+
},
53+
"options": {
54+
"target": 1,
55+
"declaration": true,
56+
"outDir": "/src/obj",
57+
"incremental": true,
58+
"lib": [
59+
"lib.es5.d.ts",
60+
"lib.es2015.promise.d.ts"
61+
],
62+
"configFilePath": "/src/tsconfig.json"
63+
},
64+
"referencedMap": {
65+
"/src/index.ts": [
66+
"/src/bundling.ts",
67+
"/src/lazyindex.ts"
68+
],
69+
"/src/lazyindex.ts": [
70+
"/src/bar.ts"
71+
]
72+
},
73+
"exportedModulesMap": {
74+
"/src/index.ts": [
75+
"/src/bundling.ts",
76+
"/src/lazyindex.ts"
77+
],
78+
"/src/lazyindex.ts": [
79+
"/src/bar.ts"
80+
]
81+
},
82+
"semanticDiagnosticsPerFile": [
83+
"/lib/lib.es2015.promise.d.ts",
84+
"/lib/lib.es5.d.ts",
85+
"/src/bar.ts",
86+
"/src/bundling.ts",
87+
"/src/index.ts",
88+
"/src/lazyindex.ts"
89+
]
90+
},
91+
"version": "FakeTSVersion"
92+
}
93+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//// [/src/obj/bar.d.ts]
2+
declare const _default: (param: string) => void;
3+
export default _default;
4+
5+
6+
//// [/src/obj/bar.js]
7+
"use strict";
8+
Object.defineProperty(exports, "__esModule", { value: true });
9+
exports.default = foo()(function foobar(param) {
10+
});
11+
12+
13+
//// [/src/obj/bundling.d.ts]
14+
export declare class LazyModule<TModule> {
15+
private importCallback;
16+
constructor(importCallback: () => Promise<TModule>);
17+
}
18+
export declare class LazyAction<TAction extends (...args: any[]) => any, TModule> {
19+
constructor(_lazyModule: LazyModule<TModule>, _getter: (module: TModule) => TAction);
20+
}
21+
22+
23+
//// [/src/obj/bundling.js]
24+
"use strict";
25+
Object.defineProperty(exports, "__esModule", { value: true });
26+
var LazyModule = /** @class */ (function () {
27+
function LazyModule(importCallback) {
28+
this.importCallback = importCallback;
29+
}
30+
return LazyModule;
31+
}());
32+
exports.LazyModule = LazyModule;
33+
var LazyAction = /** @class */ (function () {
34+
function LazyAction(_lazyModule, _getter) {
35+
}
36+
return LazyAction;
37+
}());
38+
exports.LazyAction = LazyAction;
39+
40+
41+
//// [/src/obj/index.d.ts]
42+
import { LazyAction } from './bundling';
43+
export declare const lazyBar: LazyAction<(param: string) => void, typeof import("./lazyIndex")>;
44+
45+
46+
//// [/src/obj/index.js]
47+
"use strict";
48+
Object.defineProperty(exports, "__esModule", { value: true });
49+
var bundling_1 = require("./bundling");
50+
var lazyModule = new bundling_1.LazyModule(function () {
51+
return Promise.resolve().then(function () { return require('./lazyIndex'); });
52+
});
53+
exports.lazyBar = new bundling_1.LazyAction(lazyModule, function (m) { return m.bar; });
54+
55+
56+
//// [/src/obj/lazyIndex.d.ts]
57+
export { default as bar } from './bar';
58+
59+
60+
//// [/src/obj/lazyIndex.js]
61+
"use strict";
62+
Object.defineProperty(exports, "__esModule", { value: true });
63+
var bar_1 = require("./bar");
64+
exports.bar = bar_1.default;
65+
66+
67+
//// [/src/obj/tsconfig.tsbuildinfo]
68+
{
69+
"program": {
70+
"fileInfos": {
71+
"/lib/lib.es5.d.ts": {
72+
"version": "/lib/lib.es5.d.ts",
73+
"signature": "/lib/lib.es5.d.ts"
74+
},
75+
"/lib/lib.es2015.promise.d.ts": {
76+
"version": "/lib/lib.es2015.promise.d.ts",
77+
"signature": "/lib/lib.es2015.promise.d.ts"
78+
},
79+
"/src/bar.ts": {
80+
"version": "5936740878",
81+
"signature": "11191036521"
82+
},
83+
"/src/bundling.ts": {
84+
"version": "-21659820217",
85+
"signature": "-40032907372"
86+
},
87+
"/src/lazyindex.ts": {
88+
"version": "-6956449754",
89+
"signature": "-6224542381"
90+
},
91+
"/src/index.ts": {
92+
"version": "-11602502901",
93+
"signature": "18468008756"
94+
}
95+
},
96+
"options": {
97+
"target": 1,
98+
"declaration": true,
99+
"outDir": "/src/obj",
100+
"incremental": true,
101+
"lib": [
102+
"lib.es5.d.ts",
103+
"lib.es2015.promise.d.ts"
104+
],
105+
"configFilePath": "/src/tsconfig.json"
106+
},
107+
"referencedMap": {
108+
"/src/index.ts": [
109+
"/src/bundling.ts",
110+
"/src/lazyindex.ts"
111+
],
112+
"/src/lazyindex.ts": [
113+
"/src/bar.ts"
114+
]
115+
},
116+
"exportedModulesMap": {
117+
"/src/index.ts": [
118+
"/src/bundling.ts",
119+
"/src/lazyindex.ts"
120+
],
121+
"/src/lazyindex.ts": [
122+
"/src/bar.ts"
123+
]
124+
},
125+
"semanticDiagnosticsPerFile": [
126+
"/lib/lib.es2015.promise.d.ts",
127+
"/lib/lib.es5.d.ts",
128+
"/src/bar.ts",
129+
"/src/bundling.ts",
130+
"/src/index.ts",
131+
"/src/lazyindex.ts"
132+
]
133+
},
134+
"version": "FakeTSVersion"
135+
}
136+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface RawAction {
2+
(...args: any[]): Promise<any> | void;
3+
}
4+
interface ActionFactory {
5+
<T extends RawAction>(target: T): T;
6+
}
7+
declare function foo<U extends any[] = any[]>(): ActionFactory;
8+
export default foo()(function foobar(param: string): void {
9+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export class LazyModule<TModule> {
2+
constructor(private importCallback: () => Promise<TModule>) {}
3+
}
4+
5+
export class LazyAction<
6+
TAction extends (...args: any[]) => any,
7+
TModule
8+
> {
9+
constructor(_lazyModule: LazyModule<TModule>, _getter: (module: TModule) => TAction) {
10+
}
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { LazyAction, LazyModule } from './bundling';
2+
const lazyModule = new LazyModule(() =>
3+
import('./lazyIndex')
4+
);
5+
export const lazyBar = new LazyAction(lazyModule, m => m.bar);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as bar } from './bar';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"declaration": true,
5+
"outDir": "obj",
6+
"incremental": true,
7+
"lib": ["es5", "es2015.promise"]
8+
}
9+
}

0 commit comments

Comments
 (0)