Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: remove not essential 'istanbul ignore's #2076

Merged
merged 1 commit into from Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/inline-invariant.js
Expand Up @@ -60,6 +60,7 @@ module.exports = function inlineInvariant(context) {
const previousStatement =
parentStatement.container[parentStatement.key - 1];
if (
previousStatement != null &&
previousStatement.type === 'IfStatement' &&
previousStatement.alternate == null
) {
Expand Down
10 changes: 6 additions & 4 deletions src/jsutils/__tests__/inspect-test.js
Expand Up @@ -4,6 +4,7 @@ import { expect } from 'chai';
import { describe, it } from 'mocha';

import inspect from '../inspect';
import invariant from '../invariant';
import nodejsCustomInspectSymbol from '../nodejsCustomInspectSymbol';

describe('inspect', () => {
Expand Down Expand Up @@ -35,10 +36,11 @@ describe('inspect', () => {
});

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

/* istanbul ignore next */
function testFunc() {}
function testFunc() {
invariant(false);
}
expect(inspect(testFunc)).to.equal('[function testFunc]');
});

Expand Down Expand Up @@ -102,7 +104,7 @@ describe('inspect', () => {
it('custom symbol inspect is take precedence', () => {
const object = {
inspect() {
return '<custom inspect>';
invariant(false);
},
[String(nodejsCustomInspectSymbol)]() {
return '<custom symbol inspect>';
Expand Down
2 changes: 0 additions & 2 deletions src/jsutils/devAssert.js
@@ -1,9 +1,7 @@
// @flow strict

/* istanbul ignore file */
export default function devAssert(condition: mixed, message: string): void {
const booleanCondition = Boolean(condition);
/* istanbul ignore else */
if (!booleanCondition) {
throw new Error(message);
}
Expand Down
1 change: 0 additions & 1 deletion src/jsutils/invariant.js
@@ -1,6 +1,5 @@
// @flow strict

/* istanbul ignore file */
export default function invariant(condition: mixed, message?: string): void {
const booleanCondition = Boolean(condition);
if (!booleanCondition) {
Expand Down
10 changes: 4 additions & 6 deletions src/type/__tests__/introspection-test.js
Expand Up @@ -3,6 +3,8 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

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

import { missingFieldArgMessage } from '../../validation/rules/ProvidedRequiredArguments';

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

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

graphqlSync({ schema, source, fieldResolver });
expect(calledForFields).to.deep.equal({});
});
});
52 changes: 25 additions & 27 deletions src/utilities/__tests__/stripIgnoredCharacters-test.js
Expand Up @@ -4,6 +4,7 @@ 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,10 +62,7 @@ function lexValue(str) {
const lexer = createLexer(new Source(str));
const value = lexer.advance().value;

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

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

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

const strippedTwice = stripIgnoredCharacters(stripped);

/* istanbul ignore if */
if (stripped !== strippedTwice) {
throw new Error(dedent`
invariant(
stripped === strippedTwice,
dedent`
Expected stripIgnoredCharacters(${inspectStr(stripped)})
to equal ${inspectStr(stripped)}
but got ${inspectStr(strippedTwice)}
`);
}
`,
);
},
toStayTheSame() {
this.toEqual(docString);
Expand Down Expand Up @@ -414,14 +412,14 @@ describe('stripIgnoredCharacters', () => {
const strippedStr = stripIgnoredCharacters(blockStr);
const strippedValue = lexValue(strippedStr);

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

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

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