@@ -5,8 +5,15 @@ import {mockCommand} from '@graphql-inspector/commands';
55import { mockLogger , unmockLogger } from '@graphql-inspector/logger' ;
66import yargs from 'yargs' ;
77import { buildSchema } from 'graphql' ;
8+ import { unlinkSync , existsSync } from 'fs' ;
89import createCommand from '../src' ;
910
11+ function sleepFor ( ms : number ) {
12+ return new Promise ( ( resolve ) => {
13+ setTimeout ( resolve , ms ) ;
14+ } ) ;
15+ }
16+
1017const schema = buildSchema ( /* GraphQL */ `
1118 type Post {
1219 id: ID!
@@ -33,13 +40,10 @@ const introspect = createCommand({
3340
3441describe ( 'introspect' , ( ) => {
3542 let spyReporter : jest . SpyInstance ;
36- let spyProcessExit : jest . SpyInstance ;
3743 let spyProcessCwd : jest . SpyInstance ;
3844
3945 beforeEach ( ( ) => {
4046 yargs . reset ( ) ;
41- spyProcessExit = jest . spyOn ( process , 'exit' ) ;
42- spyProcessExit . mockImplementation ( ) ;
4347
4448 spyProcessCwd = jest
4549 . spyOn ( process , 'cwd' )
@@ -52,9 +56,9 @@ describe('introspect', () => {
5256 afterEach ( ( ) => {
5357 yargs . reset ( ) ;
5458 unmockLogger ( ) ;
55- spyProcessExit . mockRestore ( ) ;
5659 spyProcessCwd . mockRestore ( ) ;
5760 spyReporter . mockRestore ( ) ;
61+ unlinkSync ( 'graphql.schema.json' ) ;
5862 } ) ;
5963
6064 test ( 'graphql api with port and ws in name using url-loader' , async ( ) => {
@@ -64,8 +68,9 @@ describe('introspect', () => {
6468 path : '/graphql' ,
6569 } ) ;
6670 await mockCommand ( introspect , 'introspect http://foo.ws:8020/graphql' ) ;
71+ await sleepFor ( 500 ) ;
6772
6873 done ( ) ;
69- expect ( spyProcessExit ) . toHaveBeenCalledWith ( 0 ) ;
74+ expect ( existsSync ( 'graphql.schema.json' ) ) . toBe ( true ) ;
7075 } ) ;
7176} ) ;
0 commit comments