Skip to content

Commit b39e34f

Browse files
committed
Move module specifiers to verifyTsBuildOutput
1 parent f3f2280 commit b39e34f

File tree

5 files changed

+242
-365
lines changed

5 files changed

+242
-365
lines changed

src/harness/fakes.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,15 @@ Actual: ${JSON.stringify(actual, /*replacer*/ undefined, " ")}
571571
Expected: ${JSON.stringify(expected, /*replacer*/ undefined, " ")}`);
572572
}
573573

574+
assertErrors(...expectedDiagnostics: ExpectedErrorDiagnostic[]) {
575+
const actual = this.diagnostics.filter(d => d.kind === DiagnosticKind.Error).map(diagnosticToText);
576+
const expected = expectedDiagnostics.map(expectedDiagnosticToText);
577+
assert.deepEqual(actual, expected, `Diagnostics arrays did not match:
578+
Actual: ${JSON.stringify(actual, /*replacer*/ undefined, " ")}
579+
Expected: ${JSON.stringify(expected, /*replacer*/ undefined, " ")}
580+
Actual All:: ${JSON.stringify(this.diagnostics.slice().map(diagnosticToText), /*replacer*/ undefined, " ")}`);
581+
}
582+
574583
printDiagnostics(header = "== Diagnostics ==") {
575584
const out = ts.createDiagnosticReporter(ts.sys);
576585
ts.sys.write(header + "\r\n");

src/testRunner/unittests/tsbuild/helpers.ts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,22 @@ namespace ts {
102102
interface ReadonlyArray<T> {}
103103
declare const console: { log(msg: any): void; };`;
104104

105-
export function loadProjectFromDisk(root: string, time?: vfs.FileSystemOptions["time"]): vfs.FileSystem {
105+
export const symbolLibContent = `
106+
interface SymbolConstructor {
107+
readonly species: symbol;
108+
readonly toStringTag: symbol;
109+
}
110+
declare var Symbol: SymbolConstructor;
111+
interface Symbol {
112+
readonly [Symbol.toStringTag]: string;
113+
}
114+
`;
115+
116+
export function loadProjectFromDisk(
117+
root: string,
118+
time?: vfs.FileSystemOptions["time"],
119+
libContentToAppend?: string
120+
): vfs.FileSystem {
106121
const resolver = vfs.createResolver(Harness.IO);
107122
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
108123
files: {
@@ -112,10 +127,29 @@ declare const console: { log(msg: any): void; };`;
112127
meta: { defaultLibLocation: "/lib" },
113128
time
114129
});
130+
addLibAndMakeReadonly(fs, libContentToAppend);
131+
return fs;
132+
}
133+
134+
export function loadProjectFromFiles(
135+
files: vfs.FileSet,
136+
time?: vfs.FileSystemOptions["time"],
137+
libContentToAppend?: string
138+
): vfs.FileSystem {
139+
const fs = new vfs.FileSystem(/*ignoreCase*/ true, {
140+
files,
141+
cwd: "/",
142+
meta: { defaultLibLocation: "/lib" },
143+
time
144+
});
145+
addLibAndMakeReadonly(fs, libContentToAppend);
146+
return fs;
147+
}
148+
149+
function addLibAndMakeReadonly(fs: vfs.FileSystem, libContentToAppend?: string) {
115150
fs.mkdirSync("/lib");
116-
fs.writeFileSync("/lib/lib.d.ts", libContent);
151+
fs.writeFileSync("/lib/lib.d.ts", libContentToAppend ? `${libContent}${libContentToAppend}` : libContent);
117152
fs.makeReadonly();
118-
return fs;
119153
}
120154

121155
export function verifyOutputsPresent(fs: vfs.FileSystem, outputs: readonly string[]) {
@@ -360,6 +394,12 @@ Mismatch Actual(path, actual, expected): ${JSON.stringify(arrayFrom(mapDefinedIt
360394
host.assertDiagnosticMessages(...(incrementalExpectedDiagnostics || emptyArray));
361395
});
362396
}
397+
else {
398+
// Build should pass without errors if not verifying diagnostics
399+
it(`verify no errors`, () => {
400+
host.assertErrors(/*empty*/);
401+
});
402+
}
363403
it(`Generates files matching the baseline`, () => {
364404
generateBaseline(newFs, proj, scenario, subScenario, fs);
365405
});

src/testRunner/unittests/tsbuild/moduleSpecifiers.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
namespace ts {
22
// https://github.com/microsoft/TypeScript/issues/31696
3-
it("unittests:: tsbuild:: moduleSpecifiers:: synthesized module specifiers to referenced projects resolve correctly", () => {
4-
const baseFs = vfs.createFromFileSystem(Harness.IO, /*ignoreCase*/ false, {
5-
files: {
3+
describe("unittests:: tsbuild:: moduleSpecifiers:: synthesized module specifiers to referenced projects resolve correctly", () => {
4+
let projFs: vfs.FileSystem;
5+
const { time, tick } = getTime();
6+
before(() => {
7+
projFs = loadProjectFromFiles({
68
"/src/common/nominal.ts": utils.dedent`
79
export declare type Nominal<T, Name extends string> = T & {
810
[Symbol.species]: Name;
@@ -71,7 +73,6 @@ namespace ts {
7173
"skipLibCheck": true,
7274
"rootDir": "./",
7375
"outDir": "lib",
74-
"lib": ["dom", "es2015", "es2015.symbol.wellknown"]
7576
}
7677
}`,
7778
"/tsconfig.json": utils.dedent`{
@@ -83,16 +84,23 @@ namespace ts {
8384
],
8485
"include": []
8586
}`
87+
}, time, symbolLibContent);
88+
});
89+
after(() => {
90+
projFs = undefined!;
91+
});
92+
verifyTsbuildOutput({
93+
scenario: `synthesized module specifiers resolve correctly`,
94+
projFs: () => projFs,
95+
time,
96+
tick,
97+
proj: "moduleSpecifiers",
98+
rootNames: ["/"],
99+
lastProjectOutput: `/src/lib/index.d.ts`,
100+
initialBuild: {
101+
modifyFs: noop,
86102
},
87-
cwd: "/"
103+
baselineOnly: true
88104
});
89-
const fs = baseFs.makeReadonly().shadow();
90-
const sys = new fakes.System(fs, { executingFilePath: "/", newLine: "\n" });
91-
const host = new fakes.SolutionBuilderHost(sys);
92-
const builder = createSolutionBuilder(host, ["/tsconfig.json"], { dry: false, force: false, verbose: false });
93-
builder.build();
94-
95-
// Prior to fixing GH31696 the import in `/lib/src/sub-project-2/index.d.ts` was `import("../../lib/src/common/nonterminal")`, which was invalid.
96-
Harness.Baseline.runBaseline("tsbuild/moduleSpecifiers/initial-build/resolves-correctly.js", vfs.formatPatch(fs.diff(baseFs)));
97105
});
98-
}
106+
}

0 commit comments

Comments
 (0)