Skip to content

Commit

Permalink
fix(jest): fix problem where test suite was not running on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
brysgo committed Jul 18, 2017
1 parent 4a108d4 commit 3a1c3e1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 56 deletions.
9 changes: 0 additions & 9 deletions config/setup.js

This file was deleted.

16 changes: 7 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"homepage": "https://github.com/brysgo/graphql-bookshelf#readme",
"devDependencies": {
"babel-cli": "^6.6.5",
"babel-jest": "^20.0.0",
"babel-jest": "^20.0.3",
"babel-polyfill": "^6.7.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
Expand All @@ -38,18 +38,16 @@
"graphql-relay": "^0.5.1",
"jest-cli": "^20.0.0",
"knex": "^0.13.0",
"sqlite3": "^3.0.10"
"regenerator-runtime": "^0.10.5",
"sqlite3": "^3.1.8"
},
"jest": {
"unmockedModulePathPatterns": [
".*"
],
"testDirectoryName": "specs",
"testPathDirs": [
"roots": [
"<rootDir>/specs"
],
"setupEnvScriptFile": "<rootDir>/config/env.js",
"setupTestFrameworkScriptFile": "<rootDir>/config/setup.js"
"setupFiles": [
"<rootDir>/config/env.js"
]
},
"peerDependencies": {
"bookshelf": "^0.10.0",
Expand Down
8 changes: 4 additions & 4 deletions specs/attr-test.js → specs/attr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import graphqlWithSchema from '../schema';
describe('attr', function() {

describe('on a bookshelf table attribute', function() {
it('returns the attribute', function* () {
yield clean();
var student = yield Student.forge({name: 'Marty Finklestein'}).save();
it('returns the attribute', async function () {
await clean();
var student = await Student.forge({name: 'Marty Finklestein'}).save();

let query = `{
viewer(id: ${student.get('id')}) {
name
}
}`

var results = yield graphqlWithSchema(query);
var results = await graphqlWithSchema(query);

expect(results).toEqual({
data: {
Expand Down
14 changes: 7 additions & 7 deletions specs/belongsTo-test.js → specs/belongsTo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import graphqlWithSchema from '../schema';
describe('belongsTo', function() {

describe('on a bookshelf belongsTo', function() {
it('returns associated content', function* () {
yield clean();
var student = yield Student.forge().save();
var homework = yield student.homeworks().create();
var classroom = yield Classroom.forge().save();
yield homework.set('classroom_id', classroom.get('id')).save();
it('returns associated content', async function () {
await clean();
var student = await Student.forge().save();
var homework = await student.homeworks().create();
var classroom = await Classroom.forge().save();
await homework.set('classroom_id', classroom.get('id')).save();

let query = `{
viewer(id: ${student.get('id')}) {
Expand All @@ -22,7 +22,7 @@ describe('belongsTo', function() {
}
}`

var results = yield graphqlWithSchema(query);
var results = await graphqlWithSchema(query);

expect(results).toEqual({
data: {
Expand Down
55 changes: 28 additions & 27 deletions specs/hasMany-test.js → specs/hasMany.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import graphqlWithSchema from '../schema';
describe('hasMany', function() {

describe('with a resolve function', function() {
it('passes a KnexJS query builder through to the resolve', function* () {
yield clean();
var student = yield Student.forge({name: 'Joe Shmoe'}).save();
var classroom1 = yield student.classrooms().create();
var classroom2 = yield student.classrooms().create();
it('passes a KnexJS query builder through to the resolve', async function () {
await clean();
var student = await Student.forge({name: 'Joe Shmoe'}).save();
var classroom1 = await student.classrooms().create();
var classroom2 = await student.classrooms().create();

let query = `{
viewer(id: ${student.get('id')}) {
Expand All @@ -19,7 +19,7 @@ describe('hasMany', function() {
}
}`

const results = yield graphqlWithSchema(query);
const results = await graphqlWithSchema(query);

expect(results).toEqual({
data: {
Expand All @@ -32,12 +32,12 @@ describe('hasMany', function() {
});

describe('without a resolve function', function() {
it('returns bookshelf belongsToMany associated data', function* () {
yield clean();
var student = yield Student.forge({name: 'Joe Shmoe'}).save();
var classroom1 = yield student.classrooms().create();
var classroom2 = yield student.classrooms().create();
var student2 = yield classroom2.students().create({name: 'Marvin Martian'});
it('returns bookshelf belongsToMany associated data', async function () {
await clean();
var student = await Student.forge({name: 'Joe Shmoe'}).save();
var classroom1 = await student.classrooms().create();
var classroom2 = await student.classrooms().create();
var student2 = await classroom2.students().create({name: 'Marvin Martian'});

let query = `{
viewer(id: ${student.get('id')}) {
Expand All @@ -47,7 +47,7 @@ describe('hasMany', function() {
}
}`

const results = yield graphqlWithSchema(query);
const results = await graphqlWithSchema(query);

expect(results).toEqual({
data: {
Expand All @@ -58,19 +58,20 @@ describe('hasMany', function() {
});
let { classrooms } = results.data.viewer;

expect(classrooms).toContain({ id: classroom1.get('id') });
expect(classrooms).toContain({ id: classroom2.get('id') });
const stripped = classrooms.map(({id}) => id);
expect(stripped).toContain(classroom1.get('id'));
expect(stripped).toContain(classroom2.get('id'));
});

});

describe('with a relay connection type', function() {
it('returns a connection instead of an array', function* () {
yield clean();
var student = yield Student.forge({name: 'Joe Shmoe'}).save();
var classroom = yield student.classrooms().create();
var homework1 = yield classroom.homeworks().create({content: 'I did it...'});
var homework2 = yield classroom.homeworks().create({content: 'Look!!!'});
it('returns a connection instead of an array', async function () {
await clean();
var student = await Student.forge({name: 'Joe Shmoe'}).save();
var classroom = await student.classrooms().create();
var homework1 = await classroom.homeworks().create({content: 'I did it...'});
var homework2 = await classroom.homeworks().create({content: 'Look!!!'});

let query = `{
viewer(id: ${student.get('id')}) {
Expand All @@ -86,7 +87,7 @@ describe('hasMany', function() {
}
}`

const results = yield graphqlWithSchema(query);
const results = await graphqlWithSchema(query);

expect(results).toEqual({
data: {
Expand All @@ -100,9 +101,9 @@ describe('hasMany', function() {
}
});
let { edges } = results.data.viewer.classrooms[0].homeworks;

expect(edges).toContain({ node: { content: homework1.get('content') }});
expect(edges).toContain({ node: { content: homework2.get('content') }});
const stripped = edges.map(({node: {content}}) => content);
expect(stripped).toContain(homework1.get('content'));
expect(stripped).toContain(homework2.get('content'));
});
});
});

0 comments on commit 3a1c3e1

Please sign in to comment.