-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: update 'getIntrospectionQuery' tests to use custom matchers (#…
- Loading branch information
1 parent
139d0f6
commit ce03dab
Showing
1 changed file
with
47 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,77 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import type { IntrospectionOptions } from '../getIntrospectionQuery'; | ||
import { getIntrospectionQuery } from '../getIntrospectionQuery'; | ||
|
||
function expectIntrospectionQuery(options?: IntrospectionOptions) { | ||
const query = getIntrospectionQuery(options); | ||
|
||
return { | ||
toMatch(name: string, times: number = 1): void { | ||
const pattern = toRegExp(name); | ||
|
||
expect(query).to.match(pattern); | ||
expect(query.match(pattern)).to.have.lengthOf(times); | ||
}, | ||
toNotMatch(name: string): void { | ||
expect(query).to.not.match(toRegExp(name)); | ||
}, | ||
}; | ||
|
||
function toRegExp(name: string): RegExp { | ||
return new RegExp('\\b' + name + '\\b', 'g'); | ||
} | ||
} | ||
|
||
describe('getIntrospectionQuery', () => { | ||
it('skip all "description" fields', () => { | ||
expect(getIntrospectionQuery()).to.match(/\bdescription\b/); | ||
expectIntrospectionQuery().toMatch('description', 5); | ||
|
||
expect(getIntrospectionQuery({ descriptions: true })).to.match( | ||
/\bdescription\b/, | ||
); | ||
expectIntrospectionQuery({ descriptions: true }).toMatch('description', 5); | ||
|
||
expect(getIntrospectionQuery({ descriptions: false })).to.not.match( | ||
/\bdescription\b/, | ||
); | ||
expectIntrospectionQuery({ descriptions: false }).toNotMatch('description'); | ||
}); | ||
|
||
it('include "isRepeatable" field on directives', () => { | ||
expect(getIntrospectionQuery()).to.not.match(/\bisRepeatable\b/); | ||
expectIntrospectionQuery().toNotMatch('isRepeatable'); | ||
|
||
expect(getIntrospectionQuery({ directiveIsRepeatable: true })).to.match( | ||
/\bisRepeatable\b/, | ||
expectIntrospectionQuery({ directiveIsRepeatable: true }).toMatch( | ||
'isRepeatable', | ||
); | ||
|
||
expect( | ||
getIntrospectionQuery({ directiveIsRepeatable: false }), | ||
).to.not.match(/\bisRepeatable\b/); | ||
expectIntrospectionQuery({ directiveIsRepeatable: false }).toNotMatch( | ||
'isRepeatable', | ||
); | ||
}); | ||
|
||
it('include "description" field on schema', () => { | ||
expect(getIntrospectionQuery().match(/\bdescription\b/g)).to.have.lengthOf( | ||
expectIntrospectionQuery().toMatch('description', 5); | ||
|
||
expectIntrospectionQuery({ schemaDescription: false }).toMatch( | ||
'description', | ||
5, | ||
); | ||
expectIntrospectionQuery({ schemaDescription: true }).toMatch( | ||
'description', | ||
6, | ||
); | ||
|
||
expect( | ||
getIntrospectionQuery({ schemaDescription: false }).match( | ||
/\bdescription\b/g, | ||
), | ||
).to.have.lengthOf(5); | ||
|
||
expect( | ||
getIntrospectionQuery({ schemaDescription: true }).match( | ||
/\bdescription\b/g, | ||
), | ||
).to.have.lengthOf(6); | ||
|
||
expect( | ||
getIntrospectionQuery({ descriptions: false, schemaDescription: true }), | ||
).to.not.match(/\bdescription\b/); | ||
expectIntrospectionQuery({ | ||
descriptions: false, | ||
schemaDescription: true, | ||
}).toNotMatch('description'); | ||
}); | ||
|
||
it('include "specifiedByUrl" field', () => { | ||
expect(getIntrospectionQuery()).to.not.match(/\bspecifiedByUrl\b/); | ||
expectIntrospectionQuery().toNotMatch('specifiedByUrl'); | ||
|
||
expect(getIntrospectionQuery({ specifiedByUrl: true })).to.match( | ||
/\bspecifiedByUrl\b/, | ||
expectIntrospectionQuery({ specifiedByUrl: true }).toMatch( | ||
'specifiedByUrl', | ||
); | ||
|
||
expect(getIntrospectionQuery({ specifiedByUrl: false })).to.not.match( | ||
/\bspecifiedByUrl\b/, | ||
expectIntrospectionQuery({ specifiedByUrl: false }).toNotMatch( | ||
'specifiedByUrl', | ||
); | ||
}); | ||
}); |