|
1 | 1 | import { expect } from 'chai';
|
2 | 2 | import { describe, it } from 'mocha';
|
3 | 3 |
|
| 4 | +import type { IntrospectionOptions } from '../getIntrospectionQuery'; |
4 | 5 | import { getIntrospectionQuery } from '../getIntrospectionQuery';
|
5 | 6 |
|
| 7 | +function expectIntrospectionQuery(options?: IntrospectionOptions) { |
| 8 | + const query = getIntrospectionQuery(options); |
| 9 | + |
| 10 | + return { |
| 11 | + toMatch(pattern: RegExp, times: number = 1): void { |
| 12 | + expect(query).to.match(pattern); |
| 13 | + |
| 14 | + const gPattern = new RegExp(pattern, 'g'); |
| 15 | + expect(query.match(gPattern)).to.have.lengthOf(times); |
| 16 | + }, |
| 17 | + toNotMatch(pattern: RegExp): void { |
| 18 | + expect(query).to.not.match(pattern); |
| 19 | + }, |
| 20 | + }; |
| 21 | +} |
| 22 | + |
6 | 23 | describe('getIntrospectionQuery', () => {
|
7 | 24 | it('skip all "description" fields', () => {
|
8 |
| - expect(getIntrospectionQuery()).to.match(/\bdescription\b/); |
| 25 | + expectIntrospectionQuery().toMatch(/\bdescription\b/, 5); |
9 | 26 |
|
10 |
| - expect(getIntrospectionQuery({ descriptions: true })).to.match( |
| 27 | + expectIntrospectionQuery({ descriptions: true }).toMatch( |
11 | 28 | /\bdescription\b/,
|
| 29 | + 5, |
12 | 30 | );
|
13 | 31 |
|
14 |
| - expect(getIntrospectionQuery({ descriptions: false })).to.not.match( |
| 32 | + expectIntrospectionQuery({ descriptions: false }).toNotMatch( |
15 | 33 | /\bdescription\b/,
|
16 | 34 | );
|
17 | 35 | });
|
18 | 36 |
|
19 | 37 | it('include "isRepeatable" field on directives', () => {
|
20 |
| - expect(getIntrospectionQuery()).to.not.match(/\bisRepeatable\b/); |
| 38 | + expectIntrospectionQuery().toNotMatch(/\bisRepeatable\b/); |
21 | 39 |
|
22 |
| - expect(getIntrospectionQuery({ directiveIsRepeatable: true })).to.match( |
| 40 | + expectIntrospectionQuery({ directiveIsRepeatable: true }).toMatch( |
23 | 41 | /\bisRepeatable\b/,
|
24 | 42 | );
|
25 | 43 |
|
26 |
| - expect( |
27 |
| - getIntrospectionQuery({ directiveIsRepeatable: false }), |
28 |
| - ).to.not.match(/\bisRepeatable\b/); |
| 44 | + expectIntrospectionQuery({ directiveIsRepeatable: false }).toNotMatch( |
| 45 | + /\bisRepeatable\b/, |
| 46 | + ); |
29 | 47 | });
|
30 | 48 |
|
31 | 49 | it('include "description" field on schema', () => {
|
32 |
| - expect(getIntrospectionQuery().match(/\bdescription\b/g)).to.have.lengthOf( |
| 50 | + expectIntrospectionQuery().toMatch(/\bdescription\b/, 5); |
| 51 | + |
| 52 | + expectIntrospectionQuery({ schemaDescription: false }).toMatch( |
| 53 | + /\bdescription\b/, |
33 | 54 | 5,
|
34 | 55 | );
|
| 56 | + expectIntrospectionQuery({ schemaDescription: true }).toMatch( |
| 57 | + /\bdescription\b/, |
| 58 | + 6, |
| 59 | + ); |
35 | 60 |
|
36 |
| - expect( |
37 |
| - getIntrospectionQuery({ schemaDescription: false }).match( |
38 |
| - /\bdescription\b/g, |
39 |
| - ), |
40 |
| - ).to.have.lengthOf(5); |
41 |
| - |
42 |
| - expect( |
43 |
| - getIntrospectionQuery({ schemaDescription: true }).match( |
44 |
| - /\bdescription\b/g, |
45 |
| - ), |
46 |
| - ).to.have.lengthOf(6); |
47 |
| - |
48 |
| - expect( |
49 |
| - getIntrospectionQuery({ descriptions: false, schemaDescription: true }), |
50 |
| - ).to.not.match(/\bdescription\b/); |
| 61 | + expectIntrospectionQuery({ |
| 62 | + descriptions: false, |
| 63 | + schemaDescription: true, |
| 64 | + }).toNotMatch(/\bdescription\b/); |
51 | 65 | });
|
52 | 66 |
|
53 | 67 | it('include "specifiedByUrl" field', () => {
|
54 |
| - expect(getIntrospectionQuery()).to.not.match(/\bspecifiedByUrl\b/); |
| 68 | + expectIntrospectionQuery().toNotMatch(/\bspecifiedByUrl\b/); |
55 | 69 |
|
56 |
| - expect(getIntrospectionQuery({ specifiedByUrl: true })).to.match( |
| 70 | + expectIntrospectionQuery({ specifiedByUrl: true }).toMatch( |
57 | 71 | /\bspecifiedByUrl\b/,
|
58 | 72 | );
|
59 | 73 |
|
60 |
| - expect(getIntrospectionQuery({ specifiedByUrl: false })).to.not.match( |
| 74 | + expectIntrospectionQuery({ specifiedByUrl: false }).toNotMatch( |
61 | 75 | /\bspecifiedByUrl\b/,
|
62 | 76 | );
|
63 | 77 | });
|
|
0 commit comments