Skip to content

Some of the test updates to ensure that it still tests what it is suppose to after we update watch path logic #53726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/testRunner/unittests/tscWatch/programUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,28 +917,28 @@ declare const eval: any`
const changeModuleFileToModuleFile1: TscWatchCompileChange = {
caption: "Rename moduleFile to moduleFile1",
edit: sys => {
sys.renameFile("/a/b/moduleFile.ts", "/a/b/moduleFile1.ts");
sys.deleteFile("/a/b/moduleFile.js");
sys.renameFile("/users/username/projects/project/moduleFile.ts", "/users/username/projects/project/moduleFile1.ts");
sys.deleteFile("/users/username/projects/project/moduleFile.js");
},
timeouts: runQueuedTimeoutCallbacksTwice
};
const changeModuleFile1ToModuleFile: TscWatchCompileChange = {
caption: "Rename moduleFile1 back to moduleFile",
edit: sys => sys.renameFile("/a/b/moduleFile1.ts", "/a/b/moduleFile.ts"),
edit: sys => sys.renameFile("/users/username/projects/project/moduleFile1.ts", "/users/username/projects/project/moduleFile.ts"),
timeouts: runQueuedTimeoutCallbacksTwice,
};

verifyTscWatch({
scenario,
subScenario: "rename a module file and rename back should restore the states for inferred projects",
commandLineArgs: ["-w", "/a/b/file1.ts"],
commandLineArgs: ["-w", "/users/username/projects/project/file1.ts"],
sys: () => {
const moduleFile = {
path: "/a/b/moduleFile.ts",
path: "/users/username/projects/project/moduleFile.ts",
content: "export function bar() { };"
};
const file1 = {
path: "/a/b/file1.ts",
path: "/users/username/projects/project/file1.ts",
content: 'import * as T from "./moduleFile"; T.bar();'
};
return createWatchedSystem([moduleFile, file1, libFile]);
Expand All @@ -952,16 +952,20 @@ declare const eval: any`
verifyTscWatch({
scenario,
subScenario: "rename a module file and rename back should restore the states for configured projects",
commandLineArgs: ["-w", "-p", configFilePath],
commandLineArgs: ["-w", "-p", "/users/username/projects/project/tsconfig.json"],
sys: () => {
const moduleFile = {
path: "/a/b/moduleFile.ts",
path: "/users/username/projects/project/moduleFile.ts",
content: "export function bar() { };"
};
const file1 = {
path: "/a/b/file1.ts",
path: "/users/username/projects/project/file1.ts",
content: 'import * as T from "./moduleFile"; T.bar();'
};
const configFile = {
path: "/users/username/projects/project/tsconfig.json",
content: `{}`
};
return createWatchedSystem([moduleFile, file1, configFile, libFile]);
},
edits: [
Expand Down Expand Up @@ -1005,18 +1009,18 @@ declare const eval: any`
verifyTscWatch({
scenario,
subScenario: "add the missing module file for inferred project-should remove the module not found error",
commandLineArgs: ["-w", "/a/b/file1.ts"],
commandLineArgs: ["-w", "/users/username/projects/project/file1.ts"],
sys: () => {
const file1 = {
path: "/a/b/file1.ts",
path: "/users/username/projects/project/file1.ts",
content: 'import * as T from "./moduleFile"; T.bar();'
};
return createWatchedSystem([file1, libFile]);
},
edits: [
{
caption: "Create module file",
edit: sys => sys.writeFile("/a/b/moduleFile.ts", "export function bar() { }"),
edit: sys => sys.writeFile("/users/username/projects/project/moduleFile.ts", "export function bar() { }"),
timeouts: runQueuedTimeoutCallbacksTwice,
}
]
Expand Down
26 changes: 13 additions & 13 deletions src/testRunner/unittests/tscWatch/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,25 +227,25 @@ describe("unittests:: tsc-watch:: resolutionCache:: tsc-watch module resolution
verifyTscWatch({
scenario,
subScenario: "works when module resolution changes to ambient module",
commandLineArgs: ["-w", "/a/b/foo.ts"],
commandLineArgs: ["-w", "/users/username/projects/project/foo.ts"],
sys: () => createWatchedSystem([{
path: "/a/b/foo.ts",
path: "/users/username/projects/project/foo.ts",
content: `import * as fs from "fs";`
}, libFile], { currentDirectory: "/a/b" }),
}, libFile], { currentDirectory: "/users/username/projects/project" }),
edits: [
{
caption: "npm install node types",
edit: sys => {
sys.ensureFileOrFolder({
path: "/a/b/node_modules/@types/node/package.json",
path: "/users/username/projects/project/node_modules/@types/node/package.json",
content: `
{
"main": ""
}
`
});
sys.ensureFileOrFolder({
path: "/a/b/node_modules/@types/node/index.d.ts",
path: "/users/username/projects/project/node_modules/@types/node/index.d.ts",
content: `
declare module "fs" {
export interface Stats {
Expand Down Expand Up @@ -580,40 +580,40 @@ declare namespace NodeJS {
scenario,
subScenario: "reusing type ref resolution",
sys: () => createWatchedSystem({
"/src/project/tsconfig.json": JSON.stringify({
"/users/username/projects/project/tsconfig.json": JSON.stringify({
compilerOptions: {
composite: true,
traceResolution: true,
outDir: "outDir",
},
}),
"/src/project/fileWithImports.ts": Utils.dedent`
"/users/username/projects/project/fileWithImports.ts": Utils.dedent`
import type { Import0 } from "pkg0";
import type { Import1 } from "pkg1";
`,
"/src/project/node_modules/pkg0/index.d.ts": `export interface Import0 {}`,
"/src/project/fileWithTypeRefs.ts": Utils.dedent`
"/users/username/projects/project/node_modules/pkg0/index.d.ts": `export interface Import0 {}`,
"/users/username/projects/project/fileWithTypeRefs.ts": Utils.dedent`
/// <reference types="pkg2"/>
/// <reference types="pkg3"/>
interface LocalInterface extends Import2, Import3 {}
export {}
`,
"/src/project/node_modules/pkg2/index.d.ts": `interface Import2 {}`,
"/users/username/projects/project/node_modules/pkg2/index.d.ts": `interface Import2 {}`,
[libFile.path]: libFile.content,
}, { currentDirectory: "/src/project" }),
}, { currentDirectory: "/users/username/projects/project" }),
commandLineArgs: ["-w", "--explainFiles", "--extendedDiagnostics"],
edits: [
{
caption: "write file not resolved by import",
edit: sys => sys.ensureFileOrFolder({ path: "/src/project/node_modules/pkg1/index.d.ts", content: `export interface Import1 {}` }),
edit: sys => sys.ensureFileOrFolder({ path: "/users/username/projects/project/node_modules/pkg1/index.d.ts", content: `export interface Import1 {}` }),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // failed lookup
sys.runQueuedTimeoutCallbacks(); // actual update
}
},
{
caption: "write file not resolved by typeRef",
edit: sys => sys.ensureFileOrFolder({ path: "/src/project/node_modules/pkg3/index.d.ts", content: `export interface Import3 {}` }),
edit: sys => sys.ensureFileOrFolder({ path: "/users/username/projects/project/node_modules/pkg3/index.d.ts", content: `export interface Import3 {}` }),
timeouts: sys => {
sys.runQueuedTimeoutCallbacks(); // failed lookup
sys.runQueuedTimeoutCallbacks(); // actual update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS

it("loads missing files from disk", () => {
const root: File = {
path: "/c/foo.ts",
path: "/users/username/projects/project/foo.ts",
content: `import {y} from "bar"`
};

const imported: File = {
path: "/c/bar.d.ts",
path: "/users/username/projects/project/bar.d.ts",
content: `export var y = 1`
};

Expand Down Expand Up @@ -318,7 +318,7 @@ describe("unittests:: tsserver:: CachingFileSystemInformation:: tsserverProjectS

describe("Subfolder invalidations correctly include parent folder failed lookup locations", () => {
function runFailedLookupTest(resolution: "Node" | "Classic") {
const projectLocation = "/proj";
const projectLocation = "/users/username/projects/proj";
const file1: File = {
path: `${projectLocation}/foo/boo/app.ts`,
content: `import * as debug from "debug"`
Expand Down
8 changes: 4 additions & 4 deletions src/testRunner/unittests/tsserver/configuredProjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1054,19 +1054,19 @@ describe("unittests:: tsserver:: ConfiguredProjects:: non-existing directories l

it("Changed module resolution reflected when specifying files list", () => {
const file1: File = {
path: "/a/b/file1.ts",
path: "/users/username/projects/project/file1.ts",
content: 'import classc from "file2"'
};
const file2a: File = {
path: "/a/file2.ts",
path: "/users/username/projects/file2.ts",
content: "export classc { method2a() { return 10; } }"
};
const file2: File = {
path: "/a/b/file2.ts",
path: "/users/username/projects/project/file2.ts",
content: "export classc { method2() { return 10; } }"
};
const configFile: File = {
path: "/a/b/tsconfig.json",
path: "/users/username/projects/project/tsconfig.json",
content: JSON.stringify({ files: [file1.path], compilerOptions: { module: "amd" } })
};
const files = [file1, file2a, configFile, libFile];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
function verifyProjectsUpdatedInBackgroundEvent(scenario: string, createSession: (host: TestServerHost) => TestSession) {
it("when adding new file", () => {
const commonFile1: File = {
path: "/a/b/file1.ts",
path: "/users/username/projects/project/file1.ts",
content: "export var x = 10;"
};
const commonFile2: File = {
path: "/a/b/file2.ts",
path: "/users/username/projects/project/file2.ts",
content: "export var y = 10;"
};
const commonFile3: File = {
path: "/a/b/file3.ts",
path: "/users/username/projects/project/file3.ts",
content: "export var z = 10;"
};
const configFile: File = {
path: "/a/b/tsconfig.json",
path: "/users/username/projects/project/tsconfig.json",
content: `{}`
};
const host = createServerHost([commonFile1, libFile, configFile]);
Expand All @@ -49,18 +49,18 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
function verifyEventWithOutSettings(subScenario: string, compilerOptions: ts.CompilerOptions = {}) {
it(subScenario, () => {
const config: File = {
path: "/a/tsconfig.json",
path: "/users/username/projects/project/tsconfig.json",
content: JSON.stringify({
compilerOptions
})
};

const f1: File = {
path: "/a/a.ts",
path: "/users/username/projects/project/a.ts",
content: "export let x = 1"
};
const f2: File = {
path: "/a/b.ts",
path: "/users/username/projects/project/b.ts",
content: "export let y = 1"
};

Expand All @@ -83,9 +83,9 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
});

describe("with modules and configured project", () => {
const file1Consumer1Path = "/a/b/file1Consumer1.ts";
const moduleFile1Path = "/a/b/moduleFile1.ts";
const configFilePath = "/a/b/tsconfig.json";
const file1Consumer1Path = "/users/username/projects/project/file1Consumer1.ts";
const moduleFile1Path = "/users/username/projects/project/moduleFile1.ts";
const configFilePath = "/users/username/projects/project/tsconfig.json";
interface InitialStateParams {
/** custom config file options */
configObj?: any;
Expand All @@ -106,17 +106,17 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
};

const file1Consumer2: File = {
path: "/a/b/file1Consumer2.ts",
path: "/users/username/projects/project/file1Consumer2.ts",
content: `import {Foo} from "./moduleFile1"; let z = 10;`,
};

const moduleFile2: File = {
path: "/a/b/moduleFile2.ts",
path: "/users/username/projects/project/moduleFile2.ts",
content: `export var Foo4 = 10;`,
};

const globalFile3: File = {
path: "/a/b/globalFile3.ts",
path: "/users/username/projects/project/globalFile3.ts",
content: `interface GlobalFoo { age: number }`
};

Expand Down Expand Up @@ -219,7 +219,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
const { host, moduleFile1, session, } = getInitialState();

host.writeFile(moduleFile1.path, `export var T: number;export function Foo() { };`);
host.writeFile("/a/b/file1Consumer3.ts", `import {Foo} from "./moduleFile1"; let y = Foo();`);
host.writeFile("/users/username/projects/project/file1Consumer3.ts", `import {Foo} from "./moduleFile1"; let y = Foo();`);
host.runQueuedTimeoutCallbacks();
baselineTsserverLogs("events/projectUpdatedInBackground", `${scenario} and should be up-to-date with newly created files`, session);
});
Expand Down Expand Up @@ -257,7 +257,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {
});

it("should always return the file itself if '--out' or '--outFile' is specified", () => {
const outFilePath = "/a/b/out.js";
const outFilePath = "/users/username/projects/project/out.js";
const { host, moduleFile1, session } = getInitialState({
configObj: { compilerOptions: { module: "system", outFile: outFilePath } }
});
Expand All @@ -269,7 +269,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {

it("should return cascaded affected file list", () => {
const file1Consumer1Consumer1: File = {
path: "/a/b/file1Consumer1Consumer1.ts",
path: "/users/username/projects/project/file1Consumer1Consumer1.ts",
content: `import {y} from "./file1Consumer1";`
};
const { host, moduleFile1, file1Consumer1, updateContentOfOpenFile, session } = getInitialState({
Expand All @@ -292,13 +292,13 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {

it("should work fine for files with circular references", () => {
const file1: File = {
path: "/a/b/file1.ts",
path: "/users/username/projects/project/file1.ts",
content: `
/// <reference path="./file2.ts" />
export var t1 = 10;`
};
const file2: File = {
path: "/a/b/file2.ts",
path: "/users/username/projects/project/file2.ts",
content: `
/// <reference path="./file1.ts" />
export var t2 = 10;`
Expand All @@ -315,7 +315,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {

it("should detect removed code file", () => {
const referenceFile1: File = {
path: "/a/b/referenceFile1.ts",
path: "/users/username/projects/project/referenceFile1.ts",
content: `
/// <reference path="./moduleFile1.ts" />
export var x = Foo();`
Expand All @@ -332,7 +332,7 @@ describe("unittests:: tsserver:: events:: ProjectsUpdatedInBackground", () => {

it("should detect non-existing code file", () => {
const referenceFile1: File = {
path: "/a/b/referenceFile1.ts",
path: "/users/username/projects/project/referenceFile1.ts",
content: `
/// <reference path="./moduleFile2.ts" />
export var x = Foo();`
Expand Down
Loading