Skip to content

Commit 43c6fd4

Browse files
authored
Covert some of the config testing to baselines for easy validation (#51063)
* Baseline config tests for easy validation * Refactor * Fix incorrect pick * Dont print unnecessary plugin host not implemented msg in logs
1 parent fc5e72b commit 43c6fd4

File tree

635 files changed

+42505
-42961
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

635 files changed

+42505
-42961
lines changed

src/server/project.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,7 @@ namespace ts.server {
16051605
}
16061606

16071607
protected enableGlobalPlugins(options: CompilerOptions, pluginConfigOverrides: Map<any> | undefined): void {
1608+
if (!this.projectService.globalPlugins.length) return;
16081609
const host = this.projectService.host;
16091610

16101611
if (!host.require && !host.importPlugin) {
@@ -1619,20 +1620,18 @@ namespace ts.server {
16191620
combinePaths(this.projectService.getExecutingFilePath(), "../../.."),
16201621
];
16211622

1622-
if (this.projectService.globalPlugins) {
1623-
// Enable global plugins with synthetic configuration entries
1624-
for (const globalPluginName of this.projectService.globalPlugins) {
1625-
// Skip empty names from odd commandline parses
1626-
if (!globalPluginName) continue;
1623+
// Enable global plugins with synthetic configuration entries
1624+
for (const globalPluginName of this.projectService.globalPlugins) {
1625+
// Skip empty names from odd commandline parses
1626+
if (!globalPluginName) continue;
16271627

1628-
// Skip already-locally-loaded plugins
1629-
if (options.plugins && options.plugins.some(p => p.name === globalPluginName)) continue;
1628+
// Skip already-locally-loaded plugins
1629+
if (options.plugins && options.plugins.some(p => p.name === globalPluginName)) continue;
16301630

1631-
// Provide global: true so plugins can detect why they can't find their config
1632-
this.projectService.logger.info(`Loading global plugin ${globalPluginName}`);
1631+
// Provide global: true so plugins can detect why they can't find their config
1632+
this.projectService.logger.info(`Loading global plugin ${globalPluginName}`);
16331633

1634-
this.enablePlugin({ name: globalPluginName, global: true } as PluginImport, searchPaths, pluginConfigOverrides);
1635-
}
1634+
this.enablePlugin({ name: globalPluginName, global: true } as PluginImport, searchPaths, pluginConfigOverrides);
16361635
}
16371636
}
16381637

@@ -2521,6 +2520,7 @@ namespace ts.server {
25212520

25222521
/*@internal*/
25232522
enablePluginsWithOptions(options: CompilerOptions, pluginConfigOverrides: ESMap<string, any> | undefined): void {
2523+
if (!options.plugins?.length && !this.projectService.globalPlugins.length) return;
25242524
const host = this.projectService.host;
25252525
if (!host.require && !host.importPlugin) {
25262526
this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded");

src/testRunner/unittests/config/commandLineParsing.ts

Lines changed: 147 additions & 960 deletions
Large diffs are not rendered by default.

src/testRunner/unittests/config/initializeTSConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace ts {
44
describe(name, () => {
55
const commandLine = parseCommandLine(commandLinesArgs);
66
const initResult = generateTSConfig(commandLine.options, commandLine.fileNames, "\n");
7-
const outputFileName = `tsConfig/${name.replace(/[^a-z0-9\-. ]/ig, "")}/tsconfig.json`;
7+
const outputFileName = `config/initTSConfig/${name.replace(/[^a-z0-9\-. ]/ig, "")}/tsconfig.json`;
88

99
it(`Correct output for ${outputFileName}`, () => {
1010
Harness.Baseline.runBaseline(outputFileName, initResult, { PrintDiff: true });

src/testRunner/unittests/config/showConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace ts {
22
describe("unittests:: config:: showConfig", () => {
33
function showTSConfigCorrectly(name: string, commandLinesArgs: string[], configJson?: object) {
44
describe(name, () => {
5-
const outputFileName = `showConfig/${name.replace(/[^a-z0-9\-./ ]/ig, "")}/tsconfig.json`;
5+
const outputFileName = `config/showConfig/${name.replace(/[^a-z0-9\-./ ]/ig, "")}/tsconfig.json`;
66

77
it(`Correct output for ${outputFileName}`, () => {
88
const cwd = `/${name}`;

src/testRunner/unittests/config/tsconfigParsingWatchOptions.ts

Lines changed: 108 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -42,190 +42,132 @@ namespace ts {
4242

4343
interface VerifyWatchOptions {
4444
json: object;
45-
expectedOptions: WatchOptions | undefined;
4645
additionalFiles?: vfs.FileSet;
4746
existingWatchOptions?: WatchOptions | undefined;
48-
expectedErrors?: (sourceFile?: SourceFile) => Diagnostic[];
4947
}
5048

51-
function verifyWatchOptions(scenario: () => VerifyWatchOptions[]) {
52-
it("with json api", () => {
53-
for (const { json, expectedOptions, additionalFiles, existingWatchOptions, expectedErrors } of scenario()) {
54-
const parsed = getParsedCommandJson(json, additionalFiles, existingWatchOptions);
55-
assert.deepEqual(parsed.watchOptions, expectedOptions, `With ${JSON.stringify(json)}`);
56-
if (length(parsed.errors)) {
57-
assert.deepEqual(parsed.errors, expectedErrors?.());
49+
function verifyWatchOptions(subScenario: string, scenario: () => VerifyWatchOptions[]) {
50+
describe(subScenario, () => {
51+
it("with json api", () => {
52+
const baseline: string[] = [];
53+
for (const { json, additionalFiles, existingWatchOptions } of scenario()) {
54+
addToBaseLine(baseline, json, getParsedCommandJson(json, additionalFiles, existingWatchOptions));
5855
}
59-
else {
60-
assert.equal(0, length(expectedErrors?.()), `Expected no errors`);
61-
}
62-
}
63-
});
56+
runBaseline(`${subScenario} with json api`, baseline);
57+
});
6458

65-
it("with json source file api", () => {
66-
for (const { json, expectedOptions, additionalFiles, existingWatchOptions, expectedErrors } of scenario()) {
67-
const parsed = getParsedCommandJsonNode(json, additionalFiles, existingWatchOptions);
68-
assert.deepEqual(parsed.watchOptions, expectedOptions);
69-
if (length(parsed.errors)) {
70-
assert.deepEqual(parsed.errors, expectedErrors?.(parsed.options.configFile));
71-
}
72-
else {
73-
assert.equal(0, length(expectedErrors?.(parsed.options.configFile)), `Expected no errors`);
59+
it("with json source file api", () => {
60+
const baseline: string[] = [];
61+
for (const { json, additionalFiles, existingWatchOptions, } of scenario()) {
62+
addToBaseLine(baseline, json, getParsedCommandJsonNode(json, additionalFiles, existingWatchOptions));
7463
}
75-
}
64+
runBaseline(`${subScenario} with jsonSourceFile api`, baseline);
65+
});
7666
});
67+
function addToBaseLine(baseline: string[], json: object, parsed: ParsedCommandLine) {
68+
baseline.push(`Input:: ${JSON.stringify(json, /*replacer*/ undefined, " ")}`);
69+
baseline.push(`Result: WatchOptions::`);
70+
baseline.push(JSON.stringify(parsed.watchOptions, /*replacer*/ undefined, " "));
71+
baseline.push(`Result: Errors::`);
72+
baseline.push(formatDiagnosticsWithColorAndContext(parsed.errors, {
73+
getCurrentDirectory: () => "/",
74+
getCanonicalFileName: identity,
75+
getNewLine: () => "\n"
76+
}));
77+
}
78+
function runBaseline(subScenario: string, baseline: readonly string[]) {
79+
Harness.Baseline.runBaseline(`config/tsconfigParsingWatchOptions/${subScenario}.js`, baseline.join("\n"));
80+
}
7781
}
7882

79-
describe("no watchOptions specified option", () => {
80-
verifyWatchOptions(() => [{
81-
json: {},
82-
expectedOptions: undefined
83-
}]);
84-
});
83+
verifyWatchOptions("no watchOptions specified option", () => [{
84+
json: {},
85+
}]);
8586

86-
describe("empty watchOptions specified option", () => {
87-
verifyWatchOptions(() => [{
88-
json: { watchOptions: {} },
89-
expectedOptions: undefined
90-
}]);
91-
});
87+
verifyWatchOptions("empty watchOptions specified option", () => [{
88+
json: { watchOptions: {} },
89+
}]);
9290

93-
describe("extending config file", () => {
94-
describe("when extending config file without watchOptions", () => {
95-
verifyWatchOptions(() => [
96-
{
97-
json: {
98-
extends: "./base.json",
99-
watchOptions: { watchFile: "UseFsEvents" }
100-
},
101-
expectedOptions: { watchFile: WatchFileKind.UseFsEvents },
102-
additionalFiles: { "/base.json": "{}" }
103-
},
104-
{
105-
json: { extends: "./base.json", },
106-
expectedOptions: undefined,
107-
additionalFiles: { "/base.json": "{}" }
108-
}
109-
]);
110-
});
91+
verifyWatchOptions("when extending config file without watchOptions", () => [
92+
{
93+
json: {
94+
extends: "./base.json",
95+
watchOptions: { watchFile: "UseFsEvents" }
96+
},
97+
additionalFiles: { "/base.json": "{}" }
98+
},
99+
{
100+
json: { extends: "./base.json", },
101+
additionalFiles: { "/base.json": "{}" }
102+
}
103+
]);
111104

112-
describe("when extending config file with watchOptions", () => {
113-
verifyWatchOptions(() => [
114-
{
115-
json: {
116-
extends: "./base.json",
117-
watchOptions: {
118-
watchFile: "UseFsEvents",
119-
}
120-
},
121-
expectedOptions: {
122-
watchFile: WatchFileKind.UseFsEvents,
123-
watchDirectory: WatchDirectoryKind.FixedPollingInterval
124-
},
125-
additionalFiles: {
126-
"/base.json": JSON.stringify({
127-
watchOptions: {
128-
watchFile: "UseFsEventsOnParentDirectory",
129-
watchDirectory: "FixedPollingInterval"
130-
}
131-
})
132-
}
133-
},
134-
{
135-
json: {
136-
extends: "./base.json",
137-
},
138-
expectedOptions: {
139-
watchFile: WatchFileKind.UseFsEventsOnParentDirectory,
140-
watchDirectory: WatchDirectoryKind.FixedPollingInterval
141-
},
142-
additionalFiles: {
143-
"/base.json": JSON.stringify({
144-
watchOptions: {
145-
watchFile: "UseFsEventsOnParentDirectory",
146-
watchDirectory: "FixedPollingInterval"
147-
}
148-
})
149-
}
105+
verifyWatchOptions("when extending config file with watchOptions", () => [
106+
{
107+
json: {
108+
extends: "./base.json",
109+
watchOptions: {
110+
watchFile: "UseFsEvents",
150111
}
151-
]);
152-
});
153-
});
154-
155-
describe("different options", () => {
156-
verifyWatchOptions(() => [
157-
{
158-
json: { watchOptions: { watchFile: "UseFsEvents" } },
159-
expectedOptions: { watchFile: WatchFileKind.UseFsEvents }
160-
},
161-
{
162-
json: { watchOptions: { watchDirectory: "UseFsEvents" } },
163-
expectedOptions: { watchDirectory: WatchDirectoryKind.UseFsEvents }
164-
},
165-
{
166-
json: { watchOptions: { fallbackPolling: "DynamicPriority" } },
167-
expectedOptions: { fallbackPolling: PollingWatchKind.DynamicPriority }
168-
},
169-
{
170-
json: { watchOptions: { synchronousWatchDirectory: true } },
171-
expectedOptions: { synchronousWatchDirectory: true }
172-
},
173-
{
174-
json: { watchOptions: { excludeDirectories: ["**/temp"] } },
175-
expectedOptions: { excludeDirectories: ["/**/temp"] }
176-
},
177-
{
178-
json: { watchOptions: { excludeFiles: ["**/temp/*.ts"] } },
179-
expectedOptions: { excludeFiles: ["/**/temp/*.ts"] }
180112
},
181-
{
182-
json: { watchOptions: { excludeDirectories: ["**/../*"] } },
183-
expectedOptions: { excludeDirectories: [] },
184-
expectedErrors: sourceFile => [
185-
{
186-
messageText: `File specification cannot contain a parent directory ('..') that appears after a recursive directory wildcard ('**'): '**/../*'.`,
187-
category: Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0.category,
188-
code: Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0.code,
189-
file: sourceFile,
190-
start: sourceFile && sourceFile.text.indexOf(`"**/../*"`),
191-
length: sourceFile && `"**/../*"`.length,
192-
reportsDeprecated: undefined,
193-
reportsUnnecessary: undefined
113+
additionalFiles: {
114+
"/base.json": JSON.stringify({
115+
watchOptions: {
116+
watchFile: "UseFsEventsOnParentDirectory",
117+
watchDirectory: "FixedPollingInterval"
194118
}
195-
]
119+
})
120+
}
121+
},
122+
{
123+
json: {
124+
extends: "./base.json",
196125
},
197-
{
198-
json: { watchOptions: { excludeFiles: ["**/../*"] } },
199-
expectedOptions: { excludeFiles: [] },
200-
expectedErrors: sourceFile => [
201-
{
202-
messageText: `File specification cannot contain a parent directory ('..') that appears after a recursive directory wildcard ('**'): '**/../*'.`,
203-
category: Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0.category,
204-
code: Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0.code,
205-
file: sourceFile,
206-
start: sourceFile && sourceFile.text.indexOf(`"**/../*"`),
207-
length: sourceFile && `"**/../*"`.length,
208-
reportsDeprecated: undefined,
209-
reportsUnnecessary: undefined
126+
additionalFiles: {
127+
"/base.json": JSON.stringify({
128+
watchOptions: {
129+
watchFile: "UseFsEventsOnParentDirectory",
130+
watchDirectory: "FixedPollingInterval"
210131
}
211-
]
212-
},
213-
]);
214-
});
132+
})
133+
}
134+
}
135+
]);
215136

216-
describe("watch options extending passed in watch options", () => {
217-
verifyWatchOptions(() => [
218-
{
219-
json: { watchOptions: { watchFile: "UseFsEvents" } },
220-
expectedOptions: { watchFile: WatchFileKind.UseFsEvents, watchDirectory: WatchDirectoryKind.FixedPollingInterval },
221-
existingWatchOptions: { watchDirectory: WatchDirectoryKind.FixedPollingInterval }
222-
},
223-
{
224-
json: {},
225-
expectedOptions: { watchDirectory: WatchDirectoryKind.FixedPollingInterval },
226-
existingWatchOptions: { watchDirectory: WatchDirectoryKind.FixedPollingInterval }
227-
},
228-
]);
229-
});
137+
verifyWatchOptions("different options", () => [
138+
{
139+
json: { watchOptions: { watchFile: "UseFsEvents" } },
140+
},
141+
{
142+
json: { watchOptions: { watchDirectory: "UseFsEvents" } },
143+
},
144+
{
145+
json: { watchOptions: { fallbackPolling: "DynamicPriority" } },
146+
},
147+
{
148+
json: { watchOptions: { synchronousWatchDirectory: true } },
149+
},
150+
{
151+
json: { watchOptions: { excludeDirectories: ["**/temp"] } },
152+
},
153+
{
154+
json: { watchOptions: { excludeFiles: ["**/temp/*.ts"] } },
155+
},
156+
{
157+
json: { watchOptions: { excludeDirectories: ["**/../*"] } },
158+
},
159+
{
160+
json: { watchOptions: { excludeFiles: ["**/../*"] } },
161+
},
162+
]);
163+
164+
verifyWatchOptions("watch options extending passed in watch options", () => [
165+
{
166+
json: { watchOptions: { watchFile: "UseFsEvents" } },
167+
},
168+
{
169+
json: {},
170+
},
171+
]);
230172
});
231173
}

src/testRunner/unittests/tsserver/configuredProjects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ namespace ts.projectSystem {
577577
content: "let zz = 1;"
578578
};
579579
host.writeFile(file5.path, file5.content);
580-
projectService.baselineHost("File5 written");
580+
projectService.testhost.baselineHost("File5 written");
581581
projectService.openClientFile(file5.path);
582582

583583
baselineTsserverLogs("configuredProjects", "Open ref of configured project when open file gets added to the project as part of configured file update", projectService);

0 commit comments

Comments
 (0)