Skip to content

Commit f117184

Browse files
committed
More tsserver tests refactoring
1 parent db4d9b3 commit f117184

10 files changed

+3294
-3282
lines changed

src/testRunner/tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
"unittests/tsbuild.ts",
6262
"unittests/tsbuildWatchMode.ts",
6363
"unittests/tscWatchMode.ts",
64-
"unittests/tsserverProjectSystem.ts",
6564
"unittests/config/commandLineParsing.ts",
6665
"unittests/config/configurationExtension.ts",
6766
"unittests/config/convertCompilerOptionsFromJson.ts",
@@ -98,15 +97,19 @@
9897
"unittests/tsserver/compileOnSave.ts",
9998
"unittests/tsserver/completions.ts",
10099
"unittests/tsserver/configFileSearch.ts",
100+
"unittests/tsserver/configuredProjects.ts",
101101
"unittests/tsserver/declarationFileMaps.ts",
102102
"unittests/tsserver/documentRegistry.ts",
103103
"unittests/tsserver/duplicatePackages.ts",
104104
"unittests/tsserver/events/largeFileReferenced.ts",
105+
"unittests/tsserver/events/projectLanguageServiceState.ts",
105106
"unittests/tsserver/events/projectLoading.ts",
106107
"unittests/tsserver/events/projectUpdatedInBackground.ts",
108+
"unittests/tsserver/events/surveyReady.ts",
107109
"unittests/tsserver/externalProjects.ts",
108110
"unittests/tsserver/forceConsistentCasingInFileNames.ts",
109111
"unittests/tsserver/formatSettings.ts",
112+
"unittests/tsserver/getApplicableRefactors.ts",
110113
"unittests/tsserver/getEditsForFileRename.ts",
111114
"unittests/tsserver/importHelpers.ts",
112115
"unittests/tsserver/inferredProjects.ts",
@@ -118,6 +121,7 @@
118121
"unittests/tsserver/openFile.ts",
119122
"unittests/tsserver/projectErrors.ts",
120123
"unittests/tsserver/projectReferences.ts",
124+
"unittests/tsserver/projects.ts",
121125
"unittests/tsserver/refactors.ts",
122126
"unittests/tsserver/reload.ts",
123127
"unittests/tsserver/rename.ts",

src/testRunner/unittests/tsserver/compileOnSave.ts

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,4 +695,99 @@ namespace ts.projectSystem {
695695
});
696696
});
697697

698+
describe("unittests:: tsserver:: compileOnSave:: CompileOnSaveAffectedFileListRequest with and without projectFileName in request", () => {
699+
const projectRoot = "/user/username/projects/myproject";
700+
const core: File = {
701+
path: `${projectRoot}/core/core.ts`,
702+
content: "let z = 10;"
703+
};
704+
const app1: File = {
705+
path: `${projectRoot}/app1/app.ts`,
706+
content: "let x = 10;"
707+
};
708+
const app2: File = {
709+
path: `${projectRoot}/app2/app.ts`,
710+
content: "let y = 10;"
711+
};
712+
const app1Config: File = {
713+
path: `${projectRoot}/app1/tsconfig.json`,
714+
content: JSON.stringify({
715+
files: ["app.ts", "../core/core.ts"],
716+
compilerOptions: { outFile: "build/output.js" },
717+
compileOnSave: true
718+
})
719+
};
720+
const app2Config: File = {
721+
path: `${projectRoot}/app2/tsconfig.json`,
722+
content: JSON.stringify({
723+
files: ["app.ts", "../core/core.ts"],
724+
compilerOptions: { outFile: "build/output.js" },
725+
compileOnSave: true
726+
})
727+
};
728+
const files = [libFile, core, app1, app2, app1Config, app2Config];
729+
730+
function insertString(session: TestSession, file: File) {
731+
session.executeCommandSeq<protocol.ChangeRequest>({
732+
command: protocol.CommandTypes.Change,
733+
arguments: {
734+
file: file.path,
735+
line: 1,
736+
offset: 1,
737+
endLine: 1,
738+
endOffset: 1,
739+
insertString: "let k = 1"
740+
}
741+
});
742+
}
743+
744+
function getSession() {
745+
const host = createServerHost(files);
746+
const session = createSession(host);
747+
openFilesForSession([app1, app2, core], session);
748+
const service = session.getProjectService();
749+
checkNumberOfProjects(session.getProjectService(), { configuredProjects: 2 });
750+
const project1 = service.configuredProjects.get(app1Config.path)!;
751+
const project2 = service.configuredProjects.get(app2Config.path)!;
752+
checkProjectActualFiles(project1, [libFile.path, app1.path, core.path, app1Config.path]);
753+
checkProjectActualFiles(project2, [libFile.path, app2.path, core.path, app2Config.path]);
754+
insertString(session, app1);
755+
insertString(session, app2);
756+
assert.equal(project1.dirty, true);
757+
assert.equal(project2.dirty, true);
758+
return session;
759+
}
760+
761+
it("when projectFile is specified", () => {
762+
const session = getSession();
763+
const response = session.executeCommandSeq<protocol.CompileOnSaveAffectedFileListRequest>({
764+
command: protocol.CommandTypes.CompileOnSaveAffectedFileList,
765+
arguments: {
766+
file: core.path,
767+
projectFileName: app1Config.path
768+
}
769+
}).response;
770+
assert.deepEqual(response, [
771+
{ projectFileName: app1Config.path, fileNames: [core.path, app1.path], projectUsesOutFile: true }
772+
]);
773+
assert.equal(session.getProjectService().configuredProjects.get(app1Config.path)!.dirty, false);
774+
assert.equal(session.getProjectService().configuredProjects.get(app2Config.path)!.dirty, true);
775+
});
776+
777+
it("when projectFile is not specified", () => {
778+
const session = getSession();
779+
const response = session.executeCommandSeq<protocol.CompileOnSaveAffectedFileListRequest>({
780+
command: protocol.CommandTypes.CompileOnSaveAffectedFileList,
781+
arguments: {
782+
file: core.path
783+
}
784+
}).response;
785+
assert.deepEqual(response, [
786+
{ projectFileName: app1Config.path, fileNames: [core.path, app1.path], projectUsesOutFile: true },
787+
{ projectFileName: app2Config.path, fileNames: [core.path, app2.path], projectUsesOutFile: true }
788+
]);
789+
assert.equal(session.getProjectService().configuredProjects.get(app1Config.path)!.dirty, false);
790+
assert.equal(session.getProjectService().configuredProjects.get(app2Config.path)!.dirty, false);
791+
});
792+
});
698793
}

0 commit comments

Comments
 (0)