Skip to content

Commit

Permalink
test after coverage for recent features/changes 馃槵
Browse files Browse the repository at this point in the history
  • Loading branch information
acao committed Jan 27, 2024
1 parent 8188e3e commit f38f179
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 10 deletions.
5 changes: 3 additions & 2 deletions packages/graphql-language-service-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@
"source-map-js": "1.0.2",
"svelte": "^4.1.1",
"svelte2tsx": "^0.7.0",
"typescript": "^5.3.3",
"vscode-jsonrpc": "^8.0.1",
"vscode-languageserver": "^8.0.1",
"vscode-languageserver-types": "^3.17.2",
"vscode-uri": "^3.0.2",
"typescript": "^5.3.3"
"vscode-uri": "^3.0.2"
},
"devDependencies": {
"@types/glob": "^8.1.0",
"@types/mkdirp": "^1.0.1",
"@types/mock-fs": "^4.13.4",
"cross-env": "^7.0.2",
"graphql": "^16.8.1",
"mock-fs": "^5.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import mkdirp from 'mkdirp';
import { readFileSync, existsSync, writeFileSync } from 'node:fs';
import { writeFile } from 'node:fs/promises';
import { readFile, writeFile } from 'node:fs/promises';
import * as path from 'node:path';
import glob from 'fast-glob';
import { URI } from 'vscode-uri';
Expand Down Expand Up @@ -308,8 +308,10 @@ export class MessageProcessor {
return fileMatch;
}
if (uri.match('package.json')?.length) {
const graphqlConfig = await import(URI.parse(uri).fsPath);
return Boolean(graphqlConfig?.graphql);
try {
const pkgConfig = await readFile(URI.parse(uri).fsPath, 'utf-8');
return Boolean(JSON.parse(pkgConfig)?.graphql);
} catch {}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,23 @@ describe('MessageProcessor', () => {
expect(capabilities.completionProvider.resolveProvider).toEqual(true);
expect(capabilities.textDocumentSync).toEqual(1);
});
it('detects a config file', async () => {
const result = await messageProcessor._isGraphQLConfigFile(
'graphql.config.js',
);
expect(result).toEqual(true);
const falseResult = await messageProcessor._isGraphQLConfigFile(
'graphql.js',
);
expect(falseResult).toEqual(false);

mockfs({ [`${__dirname}/package.json`]: '{"graphql": {}}' });
const pkgResult = await messageProcessor._isGraphQLConfigFile(
`file://${__dirname}/package.json`,
);
mockfs.restore();
expect(pkgResult).toEqual(true);
});
it('runs completion requests properly', async () => {
const uri = `${queryPathUri}/test2.graphql`;
const query = 'test';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,4 +529,36 @@ export function Example(arg: string) {}`;
const contents = findGraphQLTags(text, '.svelte');
expect(contents.length).toEqual(1);
});
it('handles full astro example', () => {
const text = `
---
const gql = String.raw;
const response = await fetch("https://swapi-graphql.netlify.app/.netlify/functions/index",
{
method: 'POST',
headers: {'Content-Type':'application/json'},
body: JSON.stringify({
query: gql\`
query getFilm ($id:ID!) {
film(id: $id) {
title
releaseDate
}
}
\`,
variables: {
id: "ZmlsbXM6MQ==",
},
}),
});
const json = await response.json();
const { film } = json.data;
---
<h1>Fetching information about Star Wars: A New Hope</h1>
<h2>Title: {film.title}</h2>
<p>Year: {film.releaseDate}</p>`;
const contents = findGraphQLTags(text, '.astro');
expect(contents.length).toEqual(1);
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,69 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`inline.graphql grammar > should tokenize a simple astro file 1`] = `
--- |
const gql = String.raw; |
const response = await fetch( |
'https://swapi-graphql.netlify.app/.netlify/functions/index', |
{ |
method: 'POST', |
headers: { 'Content-Type': 'application/json' }, |
body: JSON.stringify({ |
query: |
|
gql | entity.name.function.tagged-template.js
\` | punctuation.definition.string.template.begin.js
| meta.embedded.block.graphql
query | meta.embedded.block.graphql keyword.operation.graphql
| meta.embedded.block.graphql
getFilm | meta.embedded.block.graphql entity.name.function.graphql
( | meta.embedded.block.graphql meta.brace.round.graphql
$id | meta.embedded.block.graphql meta.variables.graphql variable.parameter.graphql
: | meta.embedded.block.graphql meta.variables.graphql punctuation.colon.graphql
| meta.embedded.block.graphql meta.variables.graphql
ID | meta.embedded.block.graphql meta.variables.graphql support.type.builtin.graphql
! | meta.embedded.block.graphql meta.variables.graphql keyword.operator.nulltype.graphql
) | meta.embedded.block.graphql meta.brace.round.graphql
| meta.embedded.block.graphql meta.selectionset.graphql
{ | meta.embedded.block.graphql meta.selectionset.graphql punctuation.operation.graphql
| meta.embedded.block.graphql meta.selectionset.graphql
film | meta.embedded.block.graphql meta.selectionset.graphql variable.graphql
( | meta.embedded.block.graphql meta.selectionset.graphql meta.arguments.graphql meta.brace.round.directive.graphql
id | meta.embedded.block.graphql meta.selectionset.graphql meta.arguments.graphql variable.parameter.graphql
: | meta.embedded.block.graphql meta.selectionset.graphql meta.arguments.graphql punctuation.colon.graphql
| meta.embedded.block.graphql meta.selectionset.graphql meta.arguments.graphql
$id | meta.embedded.block.graphql meta.selectionset.graphql meta.arguments.graphql variable.graphql
) | meta.embedded.block.graphql meta.selectionset.graphql meta.arguments.graphql meta.brace.round.directive.graphql
| meta.embedded.block.graphql meta.selectionset.graphql meta.selectionset.graphql
{ | meta.embedded.block.graphql meta.selectionset.graphql meta.selectionset.graphql punctuation.operation.graphql
| meta.embedded.block.graphql meta.selectionset.graphql meta.selectionset.graphql
title | meta.embedded.block.graphql meta.selectionset.graphql meta.selectionset.graphql variable.graphql
| meta.embedded.block.graphql meta.selectionset.graphql meta.selectionset.graphql
releaseDate | meta.embedded.block.graphql meta.selectionset.graphql meta.selectionset.graphql variable.graphql
| meta.embedded.block.graphql meta.selectionset.graphql meta.selectionset.graphql
} | meta.embedded.block.graphql meta.selectionset.graphql meta.selectionset.graphql punctuation.operation.graphql
| meta.embedded.block.graphql meta.selectionset.graphql
} | meta.embedded.block.graphql meta.selectionset.graphql punctuation.operation.graphql
| meta.embedded.block.graphql
\` | punctuation.definition.string.template.end.js
, |
variables: { |
id: 'ZmlsbXM6MQ==', |
}, |
}), |
}, |
); |
|
const json = await response.json(); |
const { film } = json.data; |
--- |
|
<h1>Fetching information about Star Wars: A New Hope</h1> |
<h2>Title: {film.title}</h2> |
<p>Year: {film.releaseDate}</p> |
|
`;
exports[`inline.graphql grammar > should tokenize a simple ecmascript file 1`] = `
/* eslint-disable */ |
/* prettier-ignore */ |
Expand Down
4 changes: 4 additions & 0 deletions packages/vscode-graphql-syntax/tests/js-grammar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ describe('inline.graphql grammar', () => {
const result = await tokenizeFile('__fixtures__/test.svelte', scope);
expect(result).toMatchSnapshot();
});
it('should tokenize a simple astro file', async () => {
const result = await tokenizeFile('__fixtures__/test.astro', scope);
expect(result).toMatchSnapshot();
});
});
64 changes: 59 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2387,7 +2387,7 @@
"@babel/parser" "^7.12.13"
"@babel/types" "^7.12.13"

"@babel/traverse@^7.16.8", "@babel/traverse@^7.17.3", "@babel/traverse@^7.20.5", "@babel/traverse@^7.20.7", "@babel/traverse@^7.21.0", "@babel/traverse@^7.21.2", "@babel/traverse@^7.22.5", "@babel/traverse@^7.22.6", "@babel/traverse@^7.22.8", "@babel/traverse@^7.23.2", "@babel/traverse@^7.23.7", "@babel/traverse@^7.7.2":
"@babel/traverse@^7.16.8", "@babel/traverse@^7.17.3", "@babel/traverse@^7.20.5", "@babel/traverse@^7.20.7", "@babel/traverse@^7.21.0", "@babel/traverse@^7.21.2", "@babel/traverse@^7.22.5", "@babel/traverse@^7.22.6", "@babel/traverse@^7.22.8", "@babel/traverse@^7.23.7", "@babel/traverse@^7.7.2":
version "7.23.7"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.23.7.tgz#9a7bf285c928cb99b5ead19c3b1ce5b310c9c305"
integrity sha512-tY3mM8rH9jM0YHFGyfC0/xf+SB5eKUu7HPj7/k3fpi9dAlsMc5YbQvDi0Sh2QTPXqMhyaAtzAr807TIyfQrmyg==
Expand Down Expand Up @@ -5453,6 +5453,13 @@
resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-9.1.1.tgz#e7c4f1001eefa4b8afbd1eee27a237fee3bf29c4"
integrity sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==

"@types/mock-fs@^4.13.4":
version "4.13.4"
resolved "https://registry.yarnpkg.com/@types/mock-fs/-/mock-fs-4.13.4.tgz#e73edb4b4889d44d23f1ea02d6eebe50aa30b09a"
integrity sha512-mXmM0o6lULPI8z3XNnQCpL0BGxPwx1Ul1wXYEPBGl4efShyxW2Rln0JOPEWGyZaYZMM6OVXM/15zUuFMY52ljg==
dependencies:
"@types/node" "*"

"@types/ms@*":
version "0.7.31"
resolved "https://registry.yarnpkg.com/@types/ms/-/ms-0.7.31.tgz#31b7ca6407128a3d2bbc27fe2d21b345397f6197"
Expand Down Expand Up @@ -6050,6 +6057,35 @@
loupe "^2.3.6"
pretty-format "^27.5.1"

"@vscode/vsce@^2.19.0", "@vscode/vsce@^2.23.0":
version "2.23.0"
resolved "https://registry.yarnpkg.com/@vscode/vsce/-/vsce-2.23.0.tgz#280ce82356c59efda97d3ba14bcdd9e3e22ddb7f"
integrity sha512-Wf9yN8feZf4XmUW/erXyKQvCL577u72AQv4AI4Cwt5o5NyE49C5mpfw3pN78BJYYG3qnSIxwRo7JPvEurkQuNA==
dependencies:
azure-devops-node-api "^11.0.1"
chalk "^2.4.2"
cheerio "^1.0.0-rc.9"
commander "^6.2.1"
find-yarn-workspace-root "^2.0.0"
glob "^7.0.6"
hosted-git-info "^4.0.2"
jsonc-parser "^3.2.0"
leven "^3.1.0"
markdown-it "^12.3.2"
mime "^1.3.4"
minimatch "^3.0.3"
parse-semver "^1.1.1"
read "^1.0.7"
semver "^7.5.2"
tmp "^0.2.1"
typed-rest-client "^1.8.4"
url-join "^4.0.1"
xml2js "^0.5.0"
yauzl "^2.3.1"
yazl "^2.2.2"
optionalDependencies:
keytar "^7.7.0"

"@vscode/vsce@^2.22.1-2":
version "2.22.1-2"
resolved "https://registry.yarnpkg.com/@vscode/vsce/-/vsce-2.22.1-2.tgz#0f272f97b23986366ea97e29721cb28410b9af68"
Expand Down Expand Up @@ -10698,6 +10734,11 @@ follow-redirects@^1.0.0, follow-redirects@^1.14.0:
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4"
integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==

follow-redirects@^1.13.2:
version "1.15.5"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.5.tgz#54d4d6d062c0fa7d9d17feb008461550e3ba8020"
integrity sha512-vSFWUON1B+yAw1VN4xMfxgn5fTUiaOzAJCKBwIIgT/+7CuGy9+r+5gITvP62j3RmaD5Ph65UaERdOSRGUzZtgw==

follow-redirects@^1.14.6:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
Expand Down Expand Up @@ -15287,15 +15328,28 @@ outdent@^0.5.0:
resolved "https://registry.yarnpkg.com/outdent/-/outdent-0.5.0.tgz#9e10982fdc41492bb473ad13840d22f9655be2ff"
integrity sha512-/jHxFIzoMXdqPzTaCpFzAAWhpkSjZPF4Vsn6jAfNpmbH/ymsmd7Qc6VE9BGn0L6YMj6uwpQLxCECpus4ukKS9Q==

ovsx@0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/ovsx/-/ovsx-0.5.1.tgz#3a8c2707ea120d542d1d226a47f24ac47b078710"
integrity sha512-3OWq0l7DuVHi2bd2aQe5+QVQlFIqvrcw3/2vGXL404L6Tr+R4QHtzfnYYghv8CCa85xJHjU0RhcaC7pyXkAUbg==
ovsx@0.8.3:
version "0.8.3"
resolved "https://registry.yarnpkg.com/ovsx/-/ovsx-0.8.3.tgz#3c67a595e423f3f70a3d62da3735dd07dfbca69f"
integrity sha512-LG7wTzy4eYV/KolFeO4AwWPzQSARvCONzd5oHQlNvYOlji2r/zjbdK8pyObZN84uZlk6rQBWrJrAdJfh/SX0Hg==
dependencies:
"@vscode/vsce" "^2.19.0"
commander "^6.1.0"
follow-redirects "^1.14.6"
is-ci "^2.0.0"
leven "^3.1.0"
semver "^7.5.2"
tmp "^0.2.1"

ovsx@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/ovsx/-/ovsx-0.3.0.tgz#2f30c80c90fbe3c8fc406730c35371219187ca0a"
integrity sha512-UjZjzLt6Iq7LS/XFvEuBAWyn0zmsZEe8fuy5DsbcsIb0mW7PbVtB5Dhe4HeK7NJM228nyhYXC9WCeyBoMi4M3A==
dependencies:
commander "^6.1.0"
follow-redirects "^1.13.2"
is-ci "^2.0.0"
leven "^3.1.0"
tmp "^0.2.1"
vsce "^2.6.3"

Expand Down

0 comments on commit f38f179

Please sign in to comment.