Skip to content

Commit b6f067d

Browse files
committed
test(service): add more test cases.
1 parent a625b51 commit b6f067d

5 files changed

+181
-0
lines changed

src/__tests__/GQLService_autocomplete.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,46 @@ describe('Schema: autocomplete', () => {
4242
},
4343
);
4444
});
45+
46+
it('should not throw if called before initialization', () => {
47+
const gql = runGQLService(
48+
{
49+
'/test/.gqlconfig': `
50+
{
51+
schema: {
52+
files: 'schema/*.gql',
53+
}
54+
}
55+
`,
56+
'/test/schema/schema.gql': `
57+
type Query {
58+
viewer: Viewer
59+
}
60+
61+
type Viewer {
62+
name: string
63+
}
64+
`,
65+
},
66+
{
67+
cwd: '/test',
68+
},
69+
);
70+
71+
const run = () =>
72+
gql.autocomplete({
73+
sourcePath: '/test/schema/user.gql',
74+
...code(`
75+
type User {
76+
viewer: Vi
77+
#---------^
78+
}
79+
`),
80+
});
81+
82+
expect(run).not.toThrow();
83+
expect(run()).toEqual([]);
84+
});
4585
});
4686

4787
describe('Query: autocomplete', () => {

src/__tests__/GQLService_findRefs.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,43 @@ test('findRefs should return all references of token at given position', done =>
4141
},
4242
);
4343
});
44+
45+
test('should not throw if called before onInit', () => {
46+
const gql = runGQLService(
47+
{
48+
'/test/.gqlconfig': `
49+
{
50+
schema: {
51+
files: 'schema/*.gql',
52+
}
53+
}
54+
`,
55+
'/test/schema/schema.gql': `
56+
type Query {
57+
viewer: Viewer
58+
}
59+
60+
type Viewer {
61+
name: string
62+
}
63+
`,
64+
},
65+
{
66+
cwd: '/test',
67+
},
68+
);
69+
70+
const run = () =>
71+
gql.findRefs({
72+
sourcePath: '/test/schema/user.gql',
73+
...code(`
74+
type User {
75+
viewer: Viewer
76+
#---------^
77+
}
78+
`),
79+
});
80+
81+
expect(run).not.toThrow();
82+
expect(run()).toEqual([]);
83+
});

src/__tests__/GQLService_getDef.test.js

+39
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,45 @@ describe('Schema: getDef', () => {
4242
},
4343
);
4444
});
45+
46+
it('works in schema files', () => {
47+
const gql = runGQLService(
48+
{
49+
'/test/.gqlconfig': `
50+
{
51+
schema: {
52+
files: 'schema/*.gql',
53+
}
54+
}
55+
`,
56+
'/test/schema/schema.gql': `
57+
type Query {
58+
viewer: Viewer
59+
}
60+
61+
type Viewer {
62+
name: string
63+
}
64+
`,
65+
},
66+
{
67+
cwd: '/test',
68+
},
69+
);
70+
71+
const run = () =>
72+
gql.getDef({
73+
sourcePath: '/test/schema/user.gql',
74+
...code(`
75+
type User {
76+
viewer: Viewer
77+
#---------^
78+
}
79+
`),
80+
});
81+
expect(run).not.toThrow();
82+
expect(run()).toBeUndefined();
83+
});
4584
});
4685

4786
describe('Query: getDef', () => {

src/__tests__/GQLService_getInfo.test.js

+38
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,44 @@ describe('Schema: getDef', () => {
4242
},
4343
);
4444
});
45+
it('should not throw if called before onInit', () => {
46+
const gql = runGQLService(
47+
{
48+
'/test/.gqlconfig': `
49+
{
50+
schema: {
51+
files: 'schema/*.gql',
52+
}
53+
}
54+
`,
55+
'/test/schema/schema.gql': `
56+
type Query {
57+
viewer: Viewer
58+
}
59+
60+
type Viewer {
61+
name: string
62+
}
63+
`,
64+
},
65+
{
66+
cwd: '/test',
67+
},
68+
);
69+
const run = () =>
70+
gql.getInfo({
71+
sourcePath: '/test/schema/user.gql',
72+
...code(`
73+
type User {
74+
viewer: Viewer
75+
#---------^
76+
}
77+
`),
78+
});
79+
80+
expect(run).not.toThrow();
81+
expect(run()).toBeUndefined();
82+
});
4583
});
4684

4785
describe('Query: getDef', () => {

src/__tests__/GQLService_status.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ describe('Schema', () => {
6262
);
6363
});
6464

65+
it('calling status before onInit should not throw', () => {
66+
const gql = runGQLService(
67+
{
68+
'/test/.gqlconfig': `
69+
{
70+
schema: {
71+
files: 'schema/*.gql',
72+
}
73+
}
74+
`,
75+
'/test/schema/schema.gql': `
76+
type Query {
77+
viewer: xViewer # missing viewer
78+
}
79+
`,
80+
},
81+
{
82+
cwd: '/test',
83+
},
84+
);
85+
expect(() => gql.status()).not.toThrow();
86+
expect(gql.status()).toEqual([]);
87+
});
88+
6589
it('can turn off validation rules', (done) => {
6690
const gql = runGQLService(
6791
{

0 commit comments

Comments
 (0)