graphile-test

PostGraphile Testing

Usage no npm install needed!

<script type="module">
  import graphileTest from 'https://cdn.skypack.dev/graphile-test';
</script>

README

graphile-test Build Status

npm install graphile-test 

how to use

environment vars

make sure env vars are set:

PGUSER
PGPASSWORD
PGHOST
PGPORT
PGDATABASE
SCHEMA

postgres users

CREATE ROLE authenticated;

write test

Then in a test:

import { GraphQLTest, env, snapshot } from 'graphile-test';
import { MyGraphQuery } from '../utils/queries';

const { SCHEMA } = env;

const getDbString = () =>
  `postgres://${env.PGUSER}:${env.PGPASSWORD}@${env.PGHOST}:${env.PGPORT}/${env.PGDATABASE}`;

const { setup, teardown, graphQL } = GraphQLTest(
  {
    appendPlugins: [],
    schema: SCHEMA,
    graphqlRoute: '/graphql'
  },
  getDbString()
);

beforeAll(async () => {
  await setup();
});
afterAll(async () => {
  await teardown();
});

it('it works!', async () => {
  await graphQL(async query => {
    const data = await query(MyGraphQuery);
    expect(snapshot(data)).toMatchSnapshot();
  });
});

testing

createdb test_database
psql test_database < sql/test.sql