Skip to content

Commit

Permalink
Remove 'invariant' calls from 'stripIgnoredCharacters' tests
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed Jul 30, 2019
1 parent 91a4be2 commit ce03161
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions src/utilities/__tests__/stripIgnoredCharacters-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';

import dedent from '../../jsutils/dedent';
import invariant from '../../jsutils/invariant';

import { parse } from '../../language/parser';
import { Source } from '../../language/source';
Expand Down Expand Up @@ -61,37 +60,47 @@ const nonPunctuatorTokens = [
function lexValue(str) {
const lexer = createLexer(new Source(str));
const value = lexer.advance().value;
invariant(lexer.advance().kind === '<EOF>');

/* istanbul ignore if */
if (lexer.advance().kind !== '<EOF>') {
throw new Error('Expected EOF');
}
return value;
}

function expectStripped(docString) {
return {
toEqual(expected) {
const stripped = stripIgnoredCharacters(docString);
invariant(
stripped === expected,
`Expected stripIgnoredCharacters(${inspectStr(docString)})\n` +
`\tto equal ${inspectStr(expected)}\n` +
`\tbut got ${inspectStr(stripped)}`,
);

/* istanbul ignore if */
if (stripped !== expected) {
throw new Error(dedent`
Expected stripIgnoredCharacters(${inspectStr(docString)})
to equal ${inspectStr(expected)}
but got ${inspectStr(stripped)}
`);
}

const strippedTwice = stripIgnoredCharacters(stripped);
invariant(
stripped === strippedTwice,
`Expected stripIgnoredCharacters(${inspectStr(stripped)})\n` +
`\tto equal ${inspectStr(stripped)}\n` +
`\tbut got ${inspectStr(strippedTwice)}`,
);

/* istanbul ignore if */
if (stripped !== strippedTwice) {
throw new Error(dedent`
Expected stripIgnoredCharacters(${inspectStr(stripped)})
to equal ${inspectStr(stripped)}
but got ${inspectStr(strippedTwice)}
`);
}
},
toStayTheSame() {
this.toEqual(docString);
},
};

// Called only to make error messages for failing tests
/* istanbul ignore next */
function inspectStr(str) {
// Called only to make error messages for failing tests
/* istanbul ignore next */
return JSON.stringify(str)
.replace(/^"|"$/g, '`')
.replace(/\\"/g, '"');
Expand Down Expand Up @@ -405,7 +414,14 @@ describe('stripIgnoredCharacters', () => {
const strippedStr = stripIgnoredCharacters(blockStr);
const strippedValue = lexValue(strippedStr);

invariant(originalValue === strippedValue);
/* istanbul ignore if */
if (originalValue !== strippedValue) {
throw new Error(dedent`
Expected lextOne(stripIgnoredCharacters(${inspectStr(blockStr)}))
to equal ${inspectStr(originalValue)}
but got ${inspectStr(strippedValue)}
`);
}
return expectStripped(blockStr);
}

Expand Down Expand Up @@ -460,7 +476,14 @@ describe('stripIgnoredCharacters', () => {
const strippedStr = stripIgnoredCharacters(testStr);
const strippedValue = lexValue(strippedStr);

invariant(testValue === strippedValue);
/* istanbul ignore if */
if (testValue !== strippedValue) {
throw new Error(dedent`
Expected lextOne(stripIgnoredCharacters(${inspectStr(testStr)}))
to equal ${inspectStr(testValue)}
but got ${inspectStr(strippedValue)}
`);
}
}
}
});
Expand Down

0 comments on commit ce03161

Please sign in to comment.