@@ -4,7 +4,6 @@ import { expect } from 'chai';
4
4
import { describe , it } from 'mocha' ;
5
5
6
6
import dedent from '../../jsutils/dedent' ;
7
- import invariant from '../../jsutils/invariant' ;
8
7
9
8
import { parse } from '../../language/parser' ;
10
9
import { Source } from '../../language/source' ;
@@ -61,37 +60,47 @@ const nonPunctuatorTokens = [
61
60
function lexValue ( str ) {
62
61
const lexer = createLexer ( new Source ( str ) ) ;
63
62
const value = lexer . advance ( ) . value ;
64
- invariant ( lexer . advance ( ) . kind === '<EOF>' ) ;
63
+
64
+ /* istanbul ignore if */
65
+ if ( lexer . advance ( ) . kind !== '<EOF>' ) {
66
+ throw new Error ( 'Expected EOF' ) ;
67
+ }
65
68
return value ;
66
69
}
67
70
68
71
function expectStripped ( docString ) {
69
72
return {
70
73
toEqual ( expected ) {
71
74
const stripped = stripIgnoredCharacters ( docString ) ;
72
- invariant (
73
- stripped === expected ,
74
- `Expected stripIgnoredCharacters(${ inspectStr ( docString ) } )\n` +
75
- `\tto equal ${ inspectStr ( expected ) } \n` +
76
- `\tbut got ${ inspectStr ( stripped ) } ` ,
77
- ) ;
75
+
76
+ /* istanbul ignore if */
77
+ if ( stripped !== expected ) {
78
+ throw new Error ( dedent `
79
+ Expected stripIgnoredCharacters(${ inspectStr ( docString ) } )
80
+ to equal ${ inspectStr ( expected ) }
81
+ but got ${ inspectStr ( stripped ) }
82
+ ` ) ;
83
+ }
78
84
79
85
const strippedTwice = stripIgnoredCharacters ( stripped ) ;
80
- invariant (
81
- stripped === strippedTwice ,
82
- `Expected stripIgnoredCharacters(${ inspectStr ( stripped ) } )\n` +
83
- `\tto equal ${ inspectStr ( stripped ) } \n` +
84
- `\tbut got ${ inspectStr ( strippedTwice ) } ` ,
85
- ) ;
86
+
87
+ /* istanbul ignore if */
88
+ if ( stripped !== strippedTwice ) {
89
+ throw new Error ( dedent `
90
+ Expected stripIgnoredCharacters(${ inspectStr ( stripped ) } )
91
+ to equal ${ inspectStr ( stripped ) }
92
+ but got ${ inspectStr ( strippedTwice ) }
93
+ ` ) ;
94
+ }
86
95
} ,
87
96
toStayTheSame ( ) {
88
97
this . toEqual ( docString ) ;
89
98
} ,
90
99
} ;
91
100
101
+ // Called only to make error messages for failing tests
102
+ /* istanbul ignore next */
92
103
function inspectStr ( str ) {
93
- // Called only to make error messages for failing tests
94
- /* istanbul ignore next */
95
104
return JSON . stringify ( str )
96
105
. replace ( / ^ " | " $ / g, '`' )
97
106
. replace ( / \\ " / g, '"' ) ;
@@ -405,7 +414,14 @@ describe('stripIgnoredCharacters', () => {
405
414
const strippedStr = stripIgnoredCharacters ( blockStr ) ;
406
415
const strippedValue = lexValue ( strippedStr ) ;
407
416
408
- invariant ( originalValue === strippedValue ) ;
417
+ /* istanbul ignore if */
418
+ if ( originalValue !== strippedValue ) {
419
+ throw new Error ( dedent `
420
+ Expected lextOne(stripIgnoredCharacters(${ inspectStr ( blockStr ) } ))
421
+ to equal ${ inspectStr ( originalValue ) }
422
+ but got ${ inspectStr ( strippedValue ) }
423
+ ` ) ;
424
+ }
409
425
return expectStripped ( blockStr ) ;
410
426
}
411
427
@@ -460,7 +476,14 @@ describe('stripIgnoredCharacters', () => {
460
476
const strippedStr = stripIgnoredCharacters ( testStr ) ;
461
477
const strippedValue = lexValue ( strippedStr ) ;
462
478
463
- invariant ( testValue === strippedValue ) ;
479
+ /* istanbul ignore if */
480
+ if ( testValue !== strippedValue ) {
481
+ throw new Error ( dedent `
482
+ Expected lextOne(stripIgnoredCharacters(${ inspectStr ( testStr ) } ))
483
+ to equal ${ inspectStr ( testValue ) }
484
+ but got ${ inspectStr ( strippedValue ) }
485
+ ` ) ;
486
+ }
464
487
}
465
488
}
466
489
} ) ;
0 commit comments