Skip to content

Commit 18371cb

Browse files
coverage: remove not essential 'istanbul ignore's (#2076)
1 parent 6adb527 commit 18371cb

File tree

6 files changed

+36
-40
lines changed

6 files changed

+36
-40
lines changed

resources/inline-invariant.js

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ module.exports = function inlineInvariant(context) {
6060
const previousStatement =
6161
parentStatement.container[parentStatement.key - 1];
6262
if (
63+
previousStatement != null &&
6364
previousStatement.type === 'IfStatement' &&
6465
previousStatement.alternate == null
6566
) {

src/jsutils/__tests__/inspect-test.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { expect } from 'chai';
44
import { describe, it } from 'mocha';
55

66
import inspect from '../inspect';
7+
import invariant from '../invariant';
78
import nodejsCustomInspectSymbol from '../nodejsCustomInspectSymbol';
89

910
describe('inspect', () => {
@@ -35,10 +36,11 @@ describe('inspect', () => {
3536
});
3637

3738
it('function', () => {
38-
expect(inspect(/* istanbul ignore next */ () => 0)).to.equal('[function]');
39+
expect(inspect(() => invariant(false))).to.equal('[function]');
3940

40-
/* istanbul ignore next */
41-
function testFunc() {}
41+
function testFunc() {
42+
invariant(false);
43+
}
4244
expect(inspect(testFunc)).to.equal('[function testFunc]');
4345
});
4446

@@ -102,7 +104,7 @@ describe('inspect', () => {
102104
it('custom symbol inspect is take precedence', () => {
103105
const object = {
104106
inspect() {
105-
return '<custom inspect>';
107+
invariant(false);
106108
},
107109
[String(nodejsCustomInspectSymbol)]() {
108110
return '<custom symbol inspect>';

src/jsutils/devAssert.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// @flow strict
22

3-
/* istanbul ignore file */
43
export default function devAssert(condition: mixed, message: string): void {
54
const booleanCondition = Boolean(condition);
6-
/* istanbul ignore else */
75
if (!booleanCondition) {
86
throw new Error(message);
97
}

src/jsutils/invariant.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// @flow strict
22

3-
/* istanbul ignore file */
43
export default function invariant(condition: mixed, message?: string): void {
54
const booleanCondition = Boolean(condition);
65
if (!booleanCondition) {

src/type/__tests__/introspection-test.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import { expect } from 'chai';
44
import { describe, it } from 'mocha';
55

6+
import invariant from '../../jsutils/invariant';
7+
68
import { missingFieldArgMessage } from '../../validation/rules/ProvidedRequiredArguments';
79

810
import { graphqlSync } from '../../graphql';
@@ -1400,14 +1402,10 @@ describe('Introspection', () => {
14001402
const schema = new GraphQLSchema({ query: QueryRoot });
14011403
const source = getIntrospectionQuery();
14021404

1403-
const calledForFields = {};
1404-
/* istanbul ignore next */
1405-
function fieldResolver(value, _1, _2, info) {
1406-
calledForFields[`${info.parentType.name}::${info.fieldName}`] = true;
1407-
return value;
1405+
function fieldResolver(_1, _2, _3, info) {
1406+
invariant(false, `Called on ${info.parentType.name}::${info.fieldName}`);
14081407
}
14091408

14101409
graphqlSync({ schema, source, fieldResolver });
1411-
expect(calledForFields).to.deep.equal({});
14121410
});
14131411
});

src/utilities/__tests__/stripIgnoredCharacters-test.js

+25-27
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { expect } from 'chai';
44
import { describe, it } from 'mocha';
55

66
import dedent from '../../jsutils/dedent';
7+
import invariant from '../../jsutils/invariant';
78

89
import { parse } from '../../language/parser';
910
import { Source } from '../../language/source';
@@ -61,10 +62,7 @@ function lexValue(str) {
6162
const lexer = createLexer(new Source(str));
6263
const value = lexer.advance().value;
6364

64-
/* istanbul ignore if */
65-
if (lexer.advance().kind !== '<EOF>') {
66-
throw new Error('Expected EOF');
67-
}
65+
invariant(lexer.advance().kind === '<EOF>', 'Expected EOF');
6866
return value;
6967
}
7068

@@ -81,25 +79,25 @@ function expectStripped(docString) {
8179
toEqual(expected) {
8280
const stripped = stripIgnoredCharacters(docString);
8381

84-
/* istanbul ignore if */
85-
if (stripped !== expected) {
86-
throw new Error(dedent`
82+
invariant(
83+
stripped === expected,
84+
dedent`
8785
Expected stripIgnoredCharacters(${inspectStr(docString)})
8886
to equal ${inspectStr(expected)}
8987
but got ${inspectStr(stripped)}
90-
`);
91-
}
88+
`,
89+
);
9290

9391
const strippedTwice = stripIgnoredCharacters(stripped);
9492

95-
/* istanbul ignore if */
96-
if (stripped !== strippedTwice) {
97-
throw new Error(dedent`
93+
invariant(
94+
stripped === strippedTwice,
95+
dedent`
9896
Expected stripIgnoredCharacters(${inspectStr(stripped)})
9997
to equal ${inspectStr(stripped)}
10098
but got ${inspectStr(strippedTwice)}
101-
`);
102-
}
99+
`,
100+
);
103101
},
104102
toStayTheSame() {
105103
this.toEqual(docString);
@@ -414,14 +412,14 @@ describe('stripIgnoredCharacters', () => {
414412
const strippedStr = stripIgnoredCharacters(blockStr);
415413
const strippedValue = lexValue(strippedStr);
416414

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-
}
415+
invariant(
416+
originalValue === strippedValue,
417+
dedent`
418+
Expected lextOne(stripIgnoredCharacters(${inspectStr(blockStr)}))
419+
to equal ${inspectStr(originalValue)}
420+
but got ${inspectStr(strippedValue)}
421+
`,
422+
);
425423
return expectStripped(blockStr);
426424
}
427425

@@ -476,14 +474,14 @@ describe('stripIgnoredCharacters', () => {
476474
const strippedStr = stripIgnoredCharacters(testStr);
477475
const strippedValue = lexValue(strippedStr);
478476

479-
/* istanbul ignore if */
480-
if (testValue !== strippedValue) {
481-
throw new Error(dedent`
477+
invariant(
478+
testValue === strippedValue,
479+
dedent`
482480
Expected lextOne(stripIgnoredCharacters(${inspectStr(testStr)}))
483481
to equal ${inspectStr(testValue)}
484482
but got ${inspectStr(strippedValue)}
485-
`);
486-
}
483+
`,
484+
);
487485
}
488486
}
489487
});

0 commit comments

Comments
 (0)