@@ -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,41 +60,51 @@ 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
71
+ // Called only to make error messages for failing tests
72
+ /* istanbul ignore next */
73
+ function inspectStr ( str ) {
74
+ return ( JSON . stringify ( str ) || '' )
75
+ . replace ( / ^ " | " $ / g, '`' )
76
+ . replace ( / \\ " / g, '"' ) ;
77
+ }
78
+
68
79
function expectStripped ( docString ) {
69
80
return {
70
81
toEqual ( expected ) {
71
82
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
- ) ;
83
+
84
+ /* istanbul ignore if */
85
+ if ( stripped !== expected ) {
86
+ throw new Error ( dedent `
87
+ Expected stripIgnoredCharacters(${ inspectStr ( docString ) } )
88
+ to equal ${ inspectStr ( expected ) }
89
+ but got ${ inspectStr ( stripped ) }
90
+ ` ) ;
91
+ }
78
92
79
93
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
- ) ;
94
+
95
+ /* istanbul ignore if */
96
+ if ( stripped !== strippedTwice ) {
97
+ throw new Error ( dedent `
98
+ Expected stripIgnoredCharacters(${ inspectStr ( stripped ) } )
99
+ to equal ${ inspectStr ( stripped ) }
100
+ but got ${ inspectStr ( strippedTwice ) }
101
+ ` ) ;
102
+ }
86
103
} ,
87
104
toStayTheSame ( ) {
88
105
this . toEqual ( docString ) ;
89
106
} ,
90
107
} ;
91
-
92
- function inspectStr ( str ) {
93
- // Called only to make error messages for failing tests
94
- /* istanbul ignore next */
95
- return JSON . stringify ( str )
96
- . replace ( / ^ " | " $ / g, '`' )
97
- . replace ( / \\ " / g, '"' ) ;
98
- }
99
108
}
100
109
101
110
describe ( 'stripIgnoredCharacters' , ( ) => {
@@ -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