Skip to content

Commit 253d76f

Browse files
authored
improve LSP tests (#3510)
- mockfs strategy - move parseDocument tests to their own file - config failure/lifecycle tests
1 parent 98af530 commit 253d76f

File tree

11 files changed

+605
-365
lines changed

11 files changed

+605
-365
lines changed

.vscode/settings.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
{
22
"npm.packageManager": "yarn",
33
"editor.formatOnSave": true,
4-
"files.insertFinalNewline": true
4+
"files.insertFinalNewline": true,
5+
"editor.trimAutoWhitespace": false,
6+
"coverage-gutters.showLineCoverage": true,
7+
"coverage-gutters.coverageBaseDir": "coverage",
8+
"coverage-gutters.coverageFileNames": [
9+
"lcov.info",
10+
"cov.xml",
11+
"coverage.xml",
12+
"jacoco.xml",
13+
"coverage.cobertura.xml"
14+
]
515
}

custom-words.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ intellij
8383
jsdelivr
8484
lezer
8585
manypkg
86+
modulemap
87+
mockfs
8688
meros
8789
nullthrows
8890
onig
@@ -131,7 +133,6 @@ listvalues
131133
marko
132134
matchingbracket
133135
middlewares
134-
modulemap
135136
newhope
136137
nextjs
137138
nocheck

packages/graphql-language-service-server/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@types/glob": "^8.1.0",
6565
"@types/mkdirp": "^1.0.1",
6666
"cross-env": "^7.0.2",
67-
"graphql": "^16.8.1"
67+
"graphql": "^16.8.1",
68+
"mock-fs": "^5.2.0"
6869
}
6970
}

packages/graphql-language-service-server/src/MessageProcessor.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,18 @@ export class MessageProcessor {
212212
const settings = await this._connection.workspace.getConfiguration({
213213
section: 'graphql-config',
214214
});
215+
215216
const vscodeSettings = await this._connection.workspace.getConfiguration({
216217
section: 'vscode-graphql',
217218
});
218219
if (settings?.dotEnvPath) {
219220
require('dotenv').config({ path: settings.dotEnvPath });
220221
}
221222
this._settings = { ...settings, ...vscodeSettings };
222-
const rootDir = this._settings?.load?.rootDir || this._rootPath;
223+
const rootDir =
224+
this._settings?.load?.rootDir ??
225+
this._loadConfigOptions?.rootDir ??
226+
this._rootPath;
223227
this._rootPath = rootDir;
224228
this._loadConfigOptions = {
225229
...Object.keys(this._settings?.load ?? {}).reduce((agg, key) => {
@@ -243,9 +247,9 @@ export class MessageProcessor {
243247
this._graphQLCache,
244248
this._logger,
245249
);
246-
if (this._graphQLConfig || this._graphQLCache?.getGraphQLConfig) {
247-
const config =
248-
this._graphQLConfig ?? this._graphQLCache.getGraphQLConfig();
250+
if (this._graphQLCache?.getGraphQLConfig()) {
251+
const config = (this._graphQLConfig =
252+
this._graphQLCache.getGraphQLConfig());
249253
await this._cacheAllProjectFiles(config);
250254
}
251255
this._isInitialized = true;
@@ -254,6 +258,7 @@ export class MessageProcessor {
254258
}
255259
}
256260
_handleConfigError({ err }: { err: unknown; uri?: string }) {
261+
// console.log(err, typeof err);
257262
if (err instanceof ConfigNotFoundError || err instanceof ConfigEmptyError) {
258263
// TODO: obviously this needs to become a map by workspace from uri
259264
// for workspaces support
@@ -303,9 +308,9 @@ export class MessageProcessor {
303308
if (!this._isInitialized || !this._graphQLCache) {
304309
// don't try to initialize again if we've already tried
305310
// and the graphql config file or package.json entry isn't even there
306-
if (this._isGraphQLConfigMissing === true) {
307-
return null;
308-
}
311+
// if (this._isGraphQLConfigMissing === true) {
312+
// return null;
313+
// }
309314
// then initial call to update graphql config
310315
await this._updateGraphQLConfig();
311316
}

0 commit comments

Comments
 (0)