Skip to content

Commit

Permalink
tests: replace 'printNode' with more high-level 'printASTNode' (#1918)
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanGoncharov committed May 28, 2019
1 parent dbe85d6 commit 172b141
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 44 deletions.
31 changes: 15 additions & 16 deletions src/utilities/__tests__/buildASTSchema-test.js
Expand Up @@ -47,9 +47,9 @@ function cycleSDL(sdl, options = {}) {
return printSchema(schema, { commentDescriptions });
}

function printNode(node) {
invariant(node);
return print(node);
function printASTNode(obj) {
invariant(obj != null && obj.astNode != null);
return print(obj.astNode);
}

describe('Schema Builder', () => {
Expand Down Expand Up @@ -774,26 +774,25 @@ describe('Schema Builder', () => {
expect(restoredSchemaAST).to.be.deep.equal(ast);

const testField = query.getFields().testField;
expect(printNode(testField.astNode)).to.equal(
expect(printASTNode(testField)).to.equal(
'testField(testArg: TestInput): TestUnion',
);
expect(printNode(testField.args[0].astNode)).to.equal('testArg: TestInput');
expect(printNode(testInput.getFields().testInputField.astNode)).to.equal(
expect(printASTNode(testField.args[0])).to.equal('testArg: TestInput');
expect(printASTNode(testInput.getFields().testInputField)).to.equal(
'testInputField: TestEnum',
);
const testEnumValue = testEnum.getValue('TEST_VALUE');
invariant(testEnumValue);
expect(printNode(testEnumValue.astNode)).to.equal('TEST_VALUE');

expect(
printNode(testInterface.getFields().interfaceField.astNode),
).to.equal('interfaceField: String');
expect(printNode(testType.getFields().interfaceField.astNode)).to.equal(

expect(printASTNode(testEnum.getValue('TEST_VALUE'))).to.equal(
'TEST_VALUE',
);

expect(printASTNode(testInterface.getFields().interfaceField)).to.equal(
'interfaceField: String',
);
expect(printNode(testDirective.args[0].astNode)).to.equal(
'arg: TestScalar',
expect(printASTNode(testType.getFields().interfaceField)).to.equal(
'interfaceField: String',
);
expect(printASTNode(testDirective.args[0])).to.equal('arg: TestScalar');
});

it('Root operation types with custom names', () => {
Expand Down
54 changes: 26 additions & 28 deletions src/utilities/__tests__/extendSchema-test.js
Expand Up @@ -168,9 +168,9 @@ function printTestSchemaChanges(extendedSchema) {
});
}

function printNode(node) {
invariant(node);
return print(node);
function printASTNode(obj) {
invariant(obj != null && obj.astNode != null);
return print(obj.astNode);
}

describe('extendSchema', () => {
Expand Down Expand Up @@ -528,49 +528,47 @@ describe('extendSchema', () => {
).to.be.equal(printSchema(extendedTwiceSchema));

const newField = query.getFields().newField;
expect(printNode(newField.astNode)).to.equal(
expect(printASTNode(newField)).to.equal(
'newField(testArg: TestInput): TestEnum',
);
expect(printNode(newField.args[0].astNode)).to.equal('testArg: TestInput');
expect(printNode(query.getFields().oneMoreNewField.astNode)).to.equal(
expect(printASTNode(newField.args[0])).to.equal('testArg: TestInput');
expect(printASTNode(query.getFields().oneMoreNewField)).to.equal(
'oneMoreNewField: TestUnion',
);

const newValue = someEnum.getValue('NEW_VALUE');
invariant(newValue);
expect(printNode(newValue.astNode)).to.equal('NEW_VALUE');
expect(printASTNode(someEnum.getValue('NEW_VALUE'))).to.equal('NEW_VALUE');
expect(printASTNode(someEnum.getValue('ONE_MORE_NEW_VALUE'))).to.equal(
'ONE_MORE_NEW_VALUE',
);

const oneMoreNewValue = someEnum.getValue('ONE_MORE_NEW_VALUE');
invariant(oneMoreNewValue);
expect(printNode(oneMoreNewValue.astNode)).to.equal('ONE_MORE_NEW_VALUE');
expect(printNode(someInput.getFields().newField.astNode)).to.equal(
expect(printASTNode(someInput.getFields().newField)).to.equal(
'newField: String',
);
expect(printNode(someInput.getFields().oneMoreNewField.astNode)).to.equal(
expect(printASTNode(someInput.getFields().oneMoreNewField)).to.equal(
'oneMoreNewField: String',
);
expect(printNode(someInterface.getFields().newField.astNode)).to.equal(
expect(printASTNode(someInterface.getFields().newField)).to.equal(
'newField: String',
);
expect(
printNode(someInterface.getFields().oneMoreNewField.astNode),
).to.equal('oneMoreNewField: String');
expect(printASTNode(someInterface.getFields().oneMoreNewField)).to.equal(
'oneMoreNewField: String',
);

expect(printNode(testInput.getFields().testInputField.astNode)).to.equal(
expect(printASTNode(testInput.getFields().testInputField)).to.equal(
'testInputField: TestEnum',
);

const testValue = testEnum.getValue('TEST_VALUE');
invariant(testValue);
expect(printNode(testValue.astNode)).to.equal('TEST_VALUE');
expect(printASTNode(testEnum.getValue('TEST_VALUE'))).to.equal(
'TEST_VALUE',
);

expect(
printNode(testInterface.getFields().interfaceField.astNode),
).to.equal('interfaceField: String');
expect(printNode(testType.getFields().interfaceField.astNode)).to.equal(
expect(printASTNode(testInterface.getFields().interfaceField)).to.equal(
'interfaceField: String',
);
expect(printASTNode(testType.getFields().interfaceField)).to.equal(
'interfaceField: String',
);
expect(printNode(testDirective.args[0].astNode)).to.equal('arg: Int');
expect(printASTNode(testDirective.args[0])).to.equal('arg: Int');
});

it('builds types with deprecated fields/values', () => {
Expand Down Expand Up @@ -1223,7 +1221,7 @@ describe('extendSchema', () => {

const queryType = schema.getQueryType();
expect(queryType).to.include({ name: 'Foo' });
expect(printNode(schema.astNode)).to.equal(extensionSDL);
expect(printASTNode(schema)).to.equal(extensionSDL);
});

it('adds new root types via schema extension', () => {
Expand Down

0 comments on commit 172b141

Please sign in to comment.