Skip to content

Commit

Permalink
Add tests where resolutions are reused which is much more common scen…
Browse files Browse the repository at this point in the history
…ario
  • Loading branch information
sheetalkamat committed Mar 4, 2021
1 parent 38baba7 commit 3cc5959
Show file tree
Hide file tree
Showing 20 changed files with 3,199 additions and 1,245 deletions.
39 changes: 16 additions & 23 deletions src/testRunner/unittests/tsbuild/persistResolutions.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
namespace ts {
describe("unittests:: tsbuild:: persistResolutions::", () => {
verifyTscSerializedIncrementalEdits({
scenario: "persistResolutions",
subScenario: `saves resolution and uses it for new program`,
fs: () => loadProjectFromFiles({
function getFs(outFile?: string) {
return loadProjectFromFiles({
"/src/project/src/main.ts": Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
import { something } from "./filePresent";
import { something as something1 } from "./filePresent";
import { something2 } from "./fileNotFound";`,
"/src/project/src/anotherFileReusingResolution.ts": Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
"/src/project/src/filePresent.ts": `export function something() { return 10; }`,
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
outFile
},
include: ["src/**/*.ts"]
}),
}),
});
}
verifyTscSerializedIncrementalEdits({
scenario: "persistResolutions",
subScenario: `saves resolution and uses it for new program`,
fs: getFs,
commandLineArgs: ["--b", "src/project"],
incrementalScenarios: [
noChangeRun,
Expand Down Expand Up @@ -58,22 +66,7 @@ namespace ts {
verifyTscSerializedIncrementalEdits({
scenario: "persistResolutions",
subScenario: `saves resolution and uses it for new program with outFile`,
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
"/src/project/src/filePresent.ts": `export function something() { return 10; }`,
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
outFile: "outFile.js"
},
include: ["src/**/*.ts"]
}),
}),
fs: () => getFs("outFile.js"),
commandLineArgs: ["--b", "src/project"],
incrementalScenarios: [
noChangeRun,
Expand Down
218 changes: 46 additions & 172 deletions src/testRunner/unittests/tsbuild/watchMode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,13 +1021,18 @@ const a: string = "hello";`),
});
});

describe("unittests:: tsbuild:: watchMode:: persistentResolutions", () => {
verifyTscWatch({
scenario: "persistResolutions",
subScenario: "saves resolution and uses it for new program",
sys: () => createWatchedSystem([
describe("unittests:: tsbuild:: watchMode:: persistResolutions", () => {
function getSys(outFile?: string) {
return createWatchedSystem([
{
path: `${projectRoot}/src/main.ts`,
content: Utils.dedent`
import { something } from "./filePresent";
import { something as something1 } from "./filePresent";
import { something2 } from "./fileNotFound";`,
},
{
path: `${projectRoot}/src/anotherFileReusingResolution.ts`,
content: Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
Expand All @@ -1044,12 +1049,42 @@ const a: string = "hello";`),
composite: true,
persistResolutions: true,
traceResolution: true,
outFile
},
include: ["src/**/*.ts"]
}),
},
libFile
], { currentDirectory: projectRoot }),
], { currentDirectory: projectRoot });
}

function getSysWithSavedResolutions(outFile?: string) {
const sys = getSys(outFile);
const exit = sys.exit;
sys.exit = noop;
fakes.withTemporaryPatchingForBuildinfoReadWrite(sys, sys => executeCommandLine(sys, noop, ["--b", "."]));
sys.exit = exit;
sys.clearOutput();
return sys;
}

function getSysWithClearedResolutions(outFile?: string) {
const sys = getSys(outFile);
const exit = sys.exit;
sys.exit = noop;
fakes.withTemporaryPatchingForBuildinfoReadWrite(sys, sys => {
executeCommandLine(sys, noop, ["--b", "."]);
executeCommandLine(sys, noop, ["--b", ".", "--cleanPersistedProgram"]);
});
sys.exit = exit;
sys.clearOutput();
return sys;
}

verifyTscWatch({
scenario: "persistResolutions",
subScenario: "saves resolution and uses it for new program",
sys: getSys,
commandLineArgs: ["--b", ".", "-w", "--extendedDiagnostics"],
changes: [
{
Expand Down Expand Up @@ -1078,39 +1113,7 @@ const a: string = "hello";`),
verifyTscWatch({
scenario: "persistResolutions",
subScenario: "can build after resolutions have been saved in tsbuildinfo file",
sys: () => {
const sys = createWatchedSystem([
{
path: `${projectRoot}/src/main.ts`,
content: Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
},
{
path: `${projectRoot}/src/filePresent.ts`,
content: `export function something() { return 10; }`,
},
{
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
},
include: ["src/**/*.ts"]
}),
},
libFile
], { currentDirectory: projectRoot });
const exit = sys.exit;
sys.exit = noop;
fakes.withTemporaryPatchingForBuildinfoReadWrite(sys, sys => executeCommandLine(sys, noop, ["--b", "."]));
sys.exit = exit;
sys.clearOutput();
return sys;
},
sys: getSysWithSavedResolutions,
commandLineArgs: ["--b", ".", "-w", "--extendedDiagnostics"],
changes: [
{
Expand Down Expand Up @@ -1139,42 +1142,7 @@ const a: string = "hello";`),
verifyTscWatch({
scenario: "persistResolutions",
subScenario: "can build after resolutions are cleaned",
sys: () => {
const sys = createWatchedSystem([
{
path: `${projectRoot}/src/main.ts`,
content: Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
},
{
path: `${projectRoot}/src/filePresent.ts`,
content: `export function something() { return 10; }`,
},
{
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
},
include: ["src/**/*.ts"]
}),
},
libFile
], { currentDirectory: projectRoot });
const exit = sys.exit;
sys.exit = noop;
fakes.withTemporaryPatchingForBuildinfoReadWrite(sys, sys => {
executeCommandLine(sys, noop, ["--b", "."]);
executeCommandLine(sys, noop, ["--b", ".", "--cleanPersistedProgram"]);
});
sys.exit = exit;
sys.clearOutput();
return sys;
},
sys: getSysWithClearedResolutions,
commandLineArgs: ["--b", ".", "-w", "--extendedDiagnostics"],
changes: [
{
Expand Down Expand Up @@ -1204,32 +1172,7 @@ const a: string = "hello";`),
verifyTscWatch({
scenario: "persistResolutions",
subScenario: "saves resolution and uses it for new program with outFile",
sys: () => createWatchedSystem([
{
path: `${projectRoot}/src/main.ts`,
content: Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
},
{
path: `${projectRoot}/src/filePresent.ts`,
content: `export function something() { return 10; }`,
},
{
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
outFile: "outFile.js"
},
include: ["src/**/*.ts"]
}),
},
libFile
], { currentDirectory: projectRoot }),
sys: () => getSys("outFile.js"),
commandLineArgs: ["--b", ".", "-w", "--extendedDiagnostics"],
changes: [
{
Expand Down Expand Up @@ -1258,40 +1201,7 @@ const a: string = "hello";`),
verifyTscWatch({
scenario: "persistResolutions",
subScenario: "can build after resolutions have been saved in tsbuildinfo file with outFile",
sys: () => {
const sys = createWatchedSystem([
{
path: `${projectRoot}/src/main.ts`,
content: Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
},
{
path: `${projectRoot}/src/filePresent.ts`,
content: `export function something() { return 10; }`,
},
{
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
outFile: "outFile.js"
},
include: ["src/**/*.ts"]
}),
},
libFile
], { currentDirectory: projectRoot });
const exit = sys.exit;
sys.exit = noop;
fakes.withTemporaryPatchingForBuildinfoReadWrite(sys, sys => executeCommandLine(sys, noop, ["--b", "."]));
sys.exit = exit;
sys.clearOutput();
return sys;
},
sys: () => getSysWithSavedResolutions("outFile.js"),
commandLineArgs: ["--b", ".", "-w", "--extendedDiagnostics"],
changes: [
{
Expand Down Expand Up @@ -1320,43 +1230,7 @@ const a: string = "hello";`),
verifyTscWatch({
scenario: "persistResolutions",
subScenario: "can build after resolutions are cleaned with outFile",
sys: () => {
const sys = createWatchedSystem([
{
path: `${projectRoot}/src/main.ts`,
content: Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
},
{
path: `${projectRoot}/src/filePresent.ts`,
content: `export function something() { return 10; }`,
},
{
path: `${projectRoot}/tsconfig.json`,
content: JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
outFile: "outFile.js"
},
include: ["src/**/*.ts"]
}),
},
libFile
], { currentDirectory: projectRoot });
const exit = sys.exit;
sys.exit = noop;
fakes.withTemporaryPatchingForBuildinfoReadWrite(sys, sys => {
executeCommandLine(sys, noop, ["--b", "."]);
executeCommandLine(sys, noop, ["--b", ".", "--cleanPersistedProgram"]);
});
sys.exit = exit;
sys.clearOutput();
return sys;
},
sys: () => getSysWithClearedResolutions("outFile.js"),
commandLineArgs: ["--b", ".", "-w", "--extendedDiagnostics"],
changes: [
{
Expand Down
39 changes: 16 additions & 23 deletions src/testRunner/unittests/tsc/persistResolutions.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
namespace ts {
describe("unittests:: tsc:: persistResolutions::", () => {
verifyTscSerializedIncrementalEdits({
scenario: "persistResolutions",
subScenario: `saves resolution and uses it for new program`,
fs: () => loadProjectFromFiles({
function getFs(outFile?: string) {
return loadProjectFromFiles({
"/src/project/src/main.ts": Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
import { something } from "./filePresent";
import { something as something1 } from "./filePresent";
import { something2 } from "./fileNotFound";`,
"/src/project/src/anotherFileReusingResolution.ts": Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
"/src/project/src/filePresent.ts": `export function something() { return 10; }`,
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
outFile
},
include: ["src/**/*.ts"]
}),
}),
});
}
verifyTscSerializedIncrementalEdits({
scenario: "persistResolutions",
subScenario: `saves resolution and uses it for new program`,
fs: getFs,
commandLineArgs: ["--p", "src/project"],
incrementalScenarios: [
noChangeRun,
Expand Down Expand Up @@ -58,22 +66,7 @@ namespace ts {
verifyTscSerializedIncrementalEdits({
scenario: "persistResolutions",
subScenario: `saves resolution and uses it for new program with outFile`,
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": Utils.dedent`
import { something } from "./filePresent";
import { something2 } from "./fileNotFound";`,
"/src/project/src/filePresent.ts": `export function something() { return 10; }`,
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: {
module: "amd",
composite: true,
persistResolutions: true,
traceResolution: true,
outFile: "outFile.js"
},
include: ["src/**/*.ts"]
}),
}),
fs: () => getFs("outFile.js"),
commandLineArgs: ["--p", "src/project"],
incrementalScenarios: [
noChangeRun,
Expand Down
Loading

0 comments on commit 3cc5959

Please sign in to comment.