Skip to content
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

chore(workspace): add namespace test #311

Merged
merged 1 commit into from
Apr 26, 2024
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
2 changes: 1 addition & 1 deletion packages/example-tada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "ISC",
"dependencies": {
"@graphql-typed-document-node/core": "^3.2.0",
"gql.tada": "1.5.9-canary-8711af177005f46fa3e06d990b6ba28e353e7f9b",
"gql.tada": "1.6.0",
"@urql/core": "^3.0.0",
"graphql": "^16.8.1",
"urql": "^4.0.6"
Expand Down
77 changes: 26 additions & 51 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions test/e2e/fixture-project-tada-multi-schema/fixtures/star-import.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as pokemon from './pokemon';

// prettier-ignore
const x = pokemon.graphql(`
query Pokemons($limit: Int!) {
pokemons(limit: $limit) {
id
name
fleeRate
classification
__typename
}
}
`);
2 changes: 1 addition & 1 deletion test/e2e/fixture-project-tada-multi-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"dependencies": {
"graphql": "^16.0.0",
"gql.tada": "1.5.9-canary-8711af177005f46fa3e06d990b6ba28e353e7f9b",
"gql.tada": "1.6.0",
"@graphql-typed-document-node/core": "^3.0.0",
"@0no-co/graphqlsp": "workspace:*",
"@urql/core": "^4.0.4"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/fixture-project-tada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"private": true,
"dependencies": {
"graphql": "^16.0.0",
"gql.tada": "^1.2.1",
"gql.tada": "^1.6.0",
"@graphql-typed-document-node/core": "^3.0.0",
"@0no-co/graphqlsp": "workspace:*",
"@urql/core": "^4.0.4"
Expand Down
44 changes: 44 additions & 0 deletions test/e2e/multi-schema-tada.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const projectPath = path.resolve(
describe('Multiple schemas', () => {
const outfilePokemonTest = path.join(projectPath, 'simple-pokemon.ts');
const outfileTodoTest = path.join(projectPath, 'simple-todo.ts');
const outfileStarImport = path.join(projectPath, 'star-import.ts');

let server: TSServer;
beforeAll(async () => {
Expand All @@ -29,6 +30,11 @@ describe('Multiple schemas', () => {
fileContent: '// empty',
scriptKindName: 'TS',
} satisfies ts.server.protocol.OpenRequestArgs);
server.sendCommand('open', {
file: outfileStarImport,
fileContent: '// empty',
scriptKindName: 'TS',
} satisfies ts.server.protocol.OpenRequestArgs);

server.sendCommand('updateOpen', {
openFiles: [
Expand All @@ -46,6 +52,13 @@ describe('Multiple schemas', () => {
'utf-8'
),
},
{
file: outfileStarImport,
fileContent: fs.readFileSync(
path.join(projectPath, 'fixtures/star-import.ts'),
'utf-8'
),
},
],
} satisfies ts.server.protocol.UpdateOpenRequestArgs);

Expand All @@ -57,6 +70,10 @@ describe('Multiple schemas', () => {
file: outfileTodoTest,
tmpfile: outfileTodoTest,
} satisfies ts.server.protocol.SavetoRequestArgs);
server.sendCommand('saveto', {
file: outfileStarImport,
tmpfile: outfileStarImport,
} satisfies ts.server.protocol.SavetoRequestArgs);

// Give TS some time to figure this out...
await new Promise(resolve => setTimeout(resolve, 1000));
Expand All @@ -66,6 +83,7 @@ describe('Multiple schemas', () => {
try {
fs.unlinkSync(outfilePokemonTest);
fs.unlinkSync(outfileTodoTest);
fs.unlinkSync(outfileStarImport);
} catch {}
});

Expand Down Expand Up @@ -126,6 +144,32 @@ describe('Multiple schemas', () => {
expect(res?.body.documentation).toEqual(`Pokemon.name: String!`);
}, 30000);

it('gives quick-info for the pokemon document namespace', async () => {
server.send({
seq: 20,
type: 'request',
command: 'quickinfo',
arguments: {
file: outfileStarImport,
line: 8,
offset: 9,
},
});

await server.waitForResponse(
response =>
response.type === 'response' && response.command === 'quickinfo'
);

const res = server.responses
.reverse()
.find(resp => resp.type === 'response' && resp.command === 'quickinfo');

expect(res).toBeDefined();
expect(typeof res?.body).toEqual('object');
expect(res?.body.documentation).toEqual(`Pokemon.name: String!`);
}, 30000);

it('gives quick-info for the todo document', async () => {
server.send({
seq: 10,
Expand Down