@@ -77,22 +77,6 @@ describe('generate-and-save', () => {
77
77
expect ( writeSpy ) . not . toHaveBeenCalled ( ) ;
78
78
} ) ;
79
79
80
- test ( 'should not error when ignoreNoDocuments config option is present' , async ( ) => {
81
- jest . spyOn ( fs , 'writeFile' ) . mockImplementation ( ) ;
82
- const config = await createContext ( {
83
- config : './tests/test-files/graphql.config.json' ,
84
- project : undefined ,
85
- errorsOnly : true ,
86
- overwrite : true ,
87
- profile : true ,
88
- require : [ ] ,
89
- silent : false ,
90
- watch : false ,
91
- } ) ;
92
-
93
- await generate ( config , false ) ;
94
- } ) ;
95
-
96
80
test ( 'should use global overwrite option and write a file' , async ( ) => {
97
81
const filename = 'overwrite.ts' ;
98
82
const writeSpy = jest . spyOn ( fs , 'writeFile' ) . mockImplementation ( ) ;
@@ -255,11 +239,11 @@ describe('generate-and-save', () => {
255
239
expect ( writeSpy ) . toHaveBeenCalled ( ) ;
256
240
} ) ;
257
241
258
- describe ( 'Syntax errors when loading pointers' , ( ) => {
242
+ describe ( 'Errors when loading pointers' , ( ) => {
259
243
const originalConsole = { ...console } ;
260
244
const originalNodeEnv = process . env . NODE_ENV ;
261
245
262
- let consoleErrorMock ;
246
+ let consoleErrorMock : jest . Mock ;
263
247
264
248
beforeEach ( ( ) => {
265
249
// Mock common console functions to avoid noise in the terminal
@@ -279,7 +263,8 @@ describe('generate-and-save', () => {
279
263
process . env . NODE_ENV = originalNodeEnv ;
280
264
} ) ;
281
265
282
- test ( 'Schema syntax error - should print native GraphQLError for' , async ( ) => {
266
+ test ( 'Schema syntax error - should print native GraphQLError' , async ( ) => {
267
+ expect . assertions ( 4 ) ;
283
268
try {
284
269
await generate (
285
270
{
@@ -324,6 +309,7 @@ describe('generate-and-save', () => {
324
309
} ) ;
325
310
326
311
test ( 'Document syntax error - should print native GraphQLError' , async ( ) => {
312
+ expect . assertions ( 4 ) ;
327
313
try {
328
314
await generate (
329
315
{
@@ -352,5 +338,90 @@ describe('generate-and-save', () => {
352
338
` ) ;
353
339
}
354
340
} ) ;
341
+
342
+ test ( 'No documents found - should throw error by default' , async ( ) => {
343
+ expect . assertions ( 1 ) ;
344
+ try {
345
+ await generate (
346
+ {
347
+ verbose : true ,
348
+ schema : './tests/test-files/schema-dir/schema.ts' ,
349
+ documents : './tests/test-files/document-file-does-not-exist.graphql' ,
350
+ generates : {
351
+ 'src/test.ts' : {
352
+ plugins : [ 'typescript' ] ,
353
+ } ,
354
+ } ,
355
+ } ,
356
+ false
357
+ ) ;
358
+ } catch {
359
+ expect ( consoleErrorMock . mock . calls [ 0 ] [ 0 ] ) . toBeSimilarStringTo ( `
360
+ [FAILED] Unable to find any GraphQL type definitions for the following pointers:
361
+ [FAILED]
362
+ [FAILED] - ./tests/test-files/document-file-does-not-exist.graphql
363
+ ` ) ;
364
+ }
365
+ } ) ;
366
+
367
+ test ( 'No documents found - should not fail if ignoreNoDocuments=true' , async ( ) => {
368
+ await generate (
369
+ {
370
+ verbose : true ,
371
+ ignoreNoDocuments : true ,
372
+ schema : './tests/test-files/schema-dir/schema.ts' ,
373
+ documents : './tests/test-files/document-file-does-not-exist.graphql' ,
374
+ generates : {
375
+ 'src/test.ts' : {
376
+ plugins : [ 'typescript' ] ,
377
+ } ,
378
+ } ,
379
+ } ,
380
+ false
381
+ ) ;
382
+ expect ( consoleErrorMock ) . not . toHaveBeenCalled ( ) ;
383
+ } ) ;
384
+
385
+ test ( 'No documents found - GraphQL Config - should throw error by default' , async ( ) => {
386
+ expect . assertions ( 1 ) ;
387
+ try {
388
+ const config = await createContext ( {
389
+ config : './tests/test-files/graphql.config.no-doc.js' ,
390
+ project : undefined ,
391
+ errorsOnly : true ,
392
+ overwrite : true ,
393
+ profile : true ,
394
+ require : [ ] ,
395
+ silent : false ,
396
+ watch : false ,
397
+ } ) ;
398
+
399
+ await generate ( config , false ) ;
400
+ } catch {
401
+ expect ( consoleErrorMock . mock . calls [ 0 ] [ 0 ] ) . toBeSimilarStringTo ( `
402
+ [FAILED]
403
+ [FAILED] Unable to find any GraphQL type definitions for the following pointers:
404
+ [FAILED]
405
+ [FAILED] - ../test-documents/empty.graphql
406
+ ` ) ;
407
+ }
408
+ } ) ;
409
+ test ( 'No documents found - GraphQL Config - should not fail if ignoreNoDocuments=true' , async ( ) => {
410
+ jest . spyOn ( fs , 'writeFile' ) . mockImplementation ( ) ;
411
+ const config = await createContext ( {
412
+ config : './tests/test-files/graphql.config.no-doc-ignored.js' ,
413
+ project : undefined ,
414
+ errorsOnly : true ,
415
+ overwrite : true ,
416
+ profile : true ,
417
+ require : [ ] ,
418
+ silent : false ,
419
+ watch : false ,
420
+ } ) ;
421
+
422
+ await generate ( config , false ) ;
423
+
424
+ expect ( consoleErrorMock ) . not . toHaveBeenCalled ( ) ;
425
+ } ) ;
355
426
} ) ;
356
427
} ) ;
0 commit comments