Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/error/__tests__/GraphQLError-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { describe, it } from 'mocha';

import { dedent } from '../../__testUtils__/dedent';

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

import { Kind } from '../../language/kinds';
import { parse } from '../../language/parser';
import { Source } from '../../language/source';
Expand All @@ -18,9 +16,9 @@ const source = new Source(dedent`
`);
const ast = parse(source);
const operationNode = ast.definitions[0];
invariant(operationNode.kind === Kind.OPERATION_DEFINITION);
assert(operationNode.kind === Kind.OPERATION_DEFINITION);
const fieldNode = operationNode.selectionSet.selections[0];
invariant(fieldNode != null);
assert(fieldNode != null);

describe('GraphQLError', () => {
it('is a class and is a subclass of Error', () => {
Expand Down Expand Up @@ -249,7 +247,7 @@ describe('toString', () => {
),
);
const opA = docA.definitions[0];
invariant(opA.kind === Kind.OBJECT_TYPE_DEFINITION && opA.fields != null);
assert(opA.kind === Kind.OBJECT_TYPE_DEFINITION && opA.fields != null);
const fieldA = opA.fields[0];

const docB = parse(
Expand All @@ -263,7 +261,7 @@ describe('toString', () => {
),
);
const opB = docB.definitions[0];
invariant(opB.kind === Kind.OBJECT_TYPE_DEFINITION && opB.fields != null);
assert(opB.kind === Kind.OBJECT_TYPE_DEFINITION && opB.fields != null);
const fieldB = opB.fields[0];

const error = new GraphQLError('Example error with two nodes', {
Expand Down
5 changes: 2 additions & 3 deletions src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON';

import { inspect } from '../../jsutils/inspect';
import { invariant } from '../../jsutils/invariant';

import { Kind } from '../../language/kinds';
import { parse } from '../../language/parser';
Expand Down Expand Up @@ -265,7 +264,7 @@ describe('Execute: Handles basic execution tasks', () => {
);

const operation = document.definitions[0];
invariant(operation.kind === Kind.OPERATION_DEFINITION);
assert(operation.kind === Kind.OPERATION_DEFINITION);

expect(resolvedInfo).to.include({
fieldName: 'test',
Expand Down
4 changes: 2 additions & 2 deletions src/execution/__tests__/simplePubSub.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invariant } from '../../jsutils/invariant';
import { assert } from 'chai';

/**
* Create an AsyncIterator from an EventEmitter. Useful for mocking a
Expand Down Expand Up @@ -64,7 +64,7 @@ export class SimplePubSub<T> {
const value: R = transform(event);
if (pullQueue.length > 0) {
const receiver = pullQueue.shift();
invariant(receiver != null);
assert(receiver != null);
receiver({ value, done: false });
} else {
pushQueue.push(value);
Expand Down
31 changes: 15 additions & 16 deletions src/execution/__tests__/subscribe-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON';
import { resolveOnNextTick } from '../../__testUtils__/resolveOnNextTick';

import { invariant } from '../../jsutils/invariant';
import { isAsyncIterable } from '../../jsutils/isAsyncIterable';

import { parse } from '../../language/parser';
Expand Down Expand Up @@ -176,7 +175,7 @@ describe('Subscription Initialization Phase', () => {
document: parse('subscription { foo }'),
rootValue: { foo: fooGenerator },
});
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

expect(await subscription.next()).to.deep.equal({
done: false,
Expand Down Expand Up @@ -211,7 +210,7 @@ describe('Subscription Initialization Phase', () => {
schema,
document: parse('subscription { foo }'),
});
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

expect(await subscription.next()).to.deep.equal({
done: false,
Expand Down Expand Up @@ -249,7 +248,7 @@ describe('Subscription Initialization Phase', () => {
schema,
document: parse('subscription { foo }'),
});
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

expect(await subscription.next()).to.deep.equal({
done: false,
Expand Down Expand Up @@ -283,7 +282,7 @@ describe('Subscription Initialization Phase', () => {
rootValue: { customFoo: fooGenerator },
subscribeFieldResolver: (root) => root.customFoo(),
});
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

expect(await subscription.next()).to.deep.equal({
done: false,
Expand Down Expand Up @@ -331,7 +330,7 @@ describe('Subscription Initialization Phase', () => {
schema,
document: parse('subscription { foo bar }'),
});
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

expect(didResolveFoo).to.equal(true);
expect(didResolveBar).to.equal(false);
Expand Down Expand Up @@ -547,10 +546,10 @@ describe('Subscription Publish Phase', () => {
const pubsub = new SimplePubSub<Email>();

const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

const secondSubscription = await createSubscription(pubsub);
invariant(isAsyncIterable(secondSubscription));
assert(isAsyncIterable(secondSubscription));

const payload1 = subscription.next();
const payload2 = secondSubscription.next();
Expand Down Expand Up @@ -589,7 +588,7 @@ describe('Subscription Publish Phase', () => {
it('produces a payload per subscription event', async () => {
const pubsub = new SimplePubSub<Email>();
const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

// Wait for the next subscription payload.
const payload = subscription.next();
Expand Down Expand Up @@ -678,7 +677,7 @@ describe('Subscription Publish Phase', () => {
it('produces a payload when there are multiple events', async () => {
const pubsub = new SimplePubSub<Email>();
const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

let payload = subscription.next();

Expand Down Expand Up @@ -744,7 +743,7 @@ describe('Subscription Publish Phase', () => {
it('should not trigger when subscription is already done', async () => {
const pubsub = new SimplePubSub<Email>();
const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

let payload = subscription.next();

Expand Down Expand Up @@ -798,7 +797,7 @@ describe('Subscription Publish Phase', () => {
it('should not trigger when subscription is thrown', async () => {
const pubsub = new SimplePubSub<Email>();
const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

let payload = subscription.next();

Expand Down Expand Up @@ -851,7 +850,7 @@ describe('Subscription Publish Phase', () => {
it('event order is correct for multiple publishes', async () => {
const pubsub = new SimplePubSub<Email>();
const subscription = await createSubscription(pubsub);
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

let payload = subscription.next();

Expand Down Expand Up @@ -942,7 +941,7 @@ describe('Subscription Publish Phase', () => {

const document = parse('subscription { newMessage }');
const subscription = await subscribe({ schema, document });
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

expect(await subscription.next()).to.deep.equal({
done: false,
Expand Down Expand Up @@ -1003,7 +1002,7 @@ describe('Subscription Publish Phase', () => {

const document = parse('subscription { newMessage }');
const subscription = await subscribe({ schema, document });
invariant(isAsyncIterable(subscription));
assert(isAsyncIterable(subscription));

expect(await subscription.next()).to.deep.equal({
done: false,
Expand Down
7 changes: 3 additions & 4 deletions src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { describe, it } from 'mocha';

import { expectJSON } from '../../__testUtils__/expectJSON';

import { inspect } from '../../jsutils/inspect';
import { invariant } from '../../jsutils/invariant';

import { Kind } from '../../language/kinds';
import { parse } from '../../language/parser';
Expand Down Expand Up @@ -1015,9 +1014,9 @@ describe('Execute: Handles inputs', () => {
`);

const operation = doc.definitions[0];
invariant(operation.kind === Kind.OPERATION_DEFINITION);
assert(operation.kind === Kind.OPERATION_DEFINITION);
const { variableDefinitions } = operation;
invariant(variableDefinitions != null);
assert(variableDefinitions != null);

const inputValue = { input: [0, 1, 2] };

Expand Down
11 changes: 5 additions & 6 deletions src/language/__tests__/blockString-fuzz.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { assert } from 'chai';
import { describe, it } from 'mocha';

import { dedent } from '../../__testUtils__/dedent';
import { genFuzzStrings } from '../../__testUtils__/genFuzzStrings';
import { inspectStr } from '../../__testUtils__/inspectStr';

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

import { isPrintableAsBlockString, printBlockString } from '../blockString';
import { Lexer } from '../lexer';
import { Source } from '../source';
Expand All @@ -14,8 +13,8 @@ function lexValue(str: string): string {
const lexer = new Lexer(new Source(str));
const value = lexer.advance().value;

invariant(typeof value === 'string');
invariant(lexer.advance().kind === '<EOF>', 'Expected EOF');
assert(typeof value === 'string');
assert(lexer.advance().kind === '<EOF>', 'Expected EOF');
return value;
}

Expand All @@ -25,7 +24,7 @@ function testPrintableBlockString(
): void {
const blockString = printBlockString(testValue, options);
const printedValue = lexValue(blockString);
invariant(
assert(
testValue === printedValue,
dedent`
Expected lexValue(${inspectStr(blockString)})
Expand All @@ -38,7 +37,7 @@ function testPrintableBlockString(
function testNonPrintableBlockString(testValue: string): void {
const blockString = printBlockString(testValue);
const printedValue = lexValue(blockString);
invariant(
assert(
testValue !== printedValue,
dedent`
Expected lexValue(${inspectStr(blockString)})
Expand Down
14 changes: 6 additions & 8 deletions src/type/__tests__/extensions-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { describe, it } from 'mocha';

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

import {
GraphQLEnumType,
GraphQLInputObjectType,
Expand All @@ -17,7 +15,7 @@ import { GraphQLSchema } from '../schema';
const dummyType = new GraphQLScalarType({ name: 'DummyScalar' });

function expectObjMap(value: unknown) {
invariant(value != null && typeof value === 'object');
assert(value != null && typeof value === 'object');
expect(Object.getPrototypeOf(value)).to.equal(null);
return expect(value);
}
Expand Down Expand Up @@ -72,7 +70,7 @@ describe('Type System: Extensions', () => {
expect(config.extensions).to.deep.equal({});
const someFieldConfig = config.fields.someField;
expect(someFieldConfig.extensions).to.deep.equal({});
invariant(someFieldConfig.args != null);
assert(someFieldConfig.args != null);
const someArgConfig = someFieldConfig.args.someArg;
expect(someArgConfig.extensions).to.deep.equal({});
});
Expand Down Expand Up @@ -109,7 +107,7 @@ describe('Type System: Extensions', () => {
expectObjMap(config.extensions).to.deep.equal(objectExtensions);
const someFieldConfig = config.fields.someField;
expectObjMap(someFieldConfig.extensions).to.deep.equal(fieldExtensions);
invariant(someFieldConfig.args != null);
assert(someFieldConfig.args != null);
const someArgConfig = someFieldConfig.args.someArg;
expectObjMap(someArgConfig.extensions).to.deep.equal(argExtensions);
});
Expand Down Expand Up @@ -141,7 +139,7 @@ describe('Type System: Extensions', () => {
expect(config.extensions).to.deep.equal({});
const someFieldConfig = config.fields.someField;
expect(someFieldConfig.extensions).to.deep.equal({});
invariant(someFieldConfig.args != null);
assert(someFieldConfig.args != null);
const someArgConfig = someFieldConfig.args.someArg;
expect(someArgConfig.extensions).to.deep.equal({});
});
Expand Down Expand Up @@ -180,7 +178,7 @@ describe('Type System: Extensions', () => {
expectObjMap(config.extensions).to.deep.equal(interfaceExtensions);
const someFieldConfig = config.fields.someField;
expectObjMap(someFieldConfig.extensions).to.deep.equal(fieldExtensions);
invariant(someFieldConfig.args != null);
assert(someFieldConfig.args != null);
const someArgConfig = someFieldConfig.args.someArg;
expectObjMap(someArgConfig.extensions).to.deep.equal(argExtensions);
});
Expand Down
10 changes: 4 additions & 6 deletions src/utilities/__tests__/TypeInfo-test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { describe, it } from 'mocha';

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

import { parse, parseValue } from '../../language/parser';
import { print } from '../../language/printer';
import { visit } from '../../language/visitor';
Expand Down Expand Up @@ -356,7 +354,7 @@ describe('visitWithTypeInfo', () => {
`);
const ast = parseValue('{ stringListField: ["foo"] }');
const complexInputType = schema.getType('ComplexInput');
invariant(complexInputType != null);
assert(complexInputType != null);

const typeInfo = new TypeInfo(schema, complexInputType);

Expand Down Expand Up @@ -401,13 +399,13 @@ describe('visitWithTypeInfo', () => {

it('supports traversals of selection sets', () => {
const humanType = testSchema.getType('Human');
invariant(humanType != null);
assert(humanType != null);

const typeInfo = new TypeInfo(testSchema, humanType);

const ast = parse('{ name, pets { name } }');
const operationNode = ast.definitions[0];
invariant(operationNode.kind === 'OperationDefinition');
assert(operationNode.kind === 'OperationDefinition');

const visited: Array<any> = [];
visit(
Expand Down
5 changes: 2 additions & 3 deletions src/utilities/__tests__/buildASTSchema-test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { expect } from 'chai';
import { assert, expect } from 'chai';
import { describe, it } from 'mocha';

import { dedent } from '../../__testUtils__/dedent';

import { invariant } from '../../jsutils/invariant';
import type { Maybe } from '../../jsutils/Maybe';

import type { ASTNode } from '../../language/ast';
Expand Down Expand Up @@ -52,7 +51,7 @@ function cycleSDL(sdl: string): string {
}

function expectASTNode(obj: Maybe<{ readonly astNode: Maybe<ASTNode> }>) {
invariant(obj?.astNode != null);
assert(obj?.astNode != null);
return expect(print(obj.astNode));
}

Expand Down
Loading