From 2ed8ea3132b08b9e2f48284ddc8b301fc1311289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=A4fer?= Date: Wed, 22 May 2019 17:41:25 +0200 Subject: [PATCH] Make #252 less painful, mark not-isolated tests With this commit you can run ``` npm run test-isolated ``` over and over again and the tests should pass. This does not fix the issue mentioned above but it makes it less painful. At least I can make my changes and run all tests exluding those that are not isolated. When I'm done with my changes I can re-import the data and run all the tests, even those that are not isolated. This is what I did to get all the tests passing on my machine: ``` sudo rm /var/lib/neo4j/data/databases/* -r sudo cp -rp ~/Downloads/temp/neo4j-graphql-js/recommendations.db/ /var/lib/neo4j/data/databases/graph.db sudo systemctl restart neo4j.service ``` Very annoying. @johnymontana @michaeldgraham do you know if there is a single command that brings the database into a state where it was *before* running the test case? Something that we could use in a `beforeEach` or `afterEach`? See: https://github.com/neo4j-graphql/neo4j-graphql-js/issues/252#issuecomment-494851354 --- .circleci/config.yml | 2 +- .gitignore | 2 +- package.json | 3 +- .../intgration.test.js} | 585 +++++++++--------- .../test-middleware.test.js} | 0 test/tck/.gitkeep | 0 6 files changed, 307 insertions(+), 285 deletions(-) rename test/{integration.js => integration/intgration.test.js} (83%) rename test/{test-middleware.js => integration/test-middleware.test.js} (100%) create mode 100644 test/tck/.gitkeep diff --git a/.circleci/config.yml b/.circleci/config.yml index 2dd7e67c..feecf855 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -101,7 +101,7 @@ references: run_tests: &run_tests run: name: Run Tests - command: ./node_modules/.bin/nyc ./node_modules/.bin/ava test/*.js test/neo4j-schema/*Test.js + command: npm run test-all env_neo4j34ee: &env_neo4j34ee NEO4J_DIST: 'enterprise' diff --git a/.gitignore b/.gitignore index d1f73494..9c6d0024 100644 --- a/.gitignore +++ b/.gitignore @@ -66,5 +66,5 @@ dist/ node-version neo4j-version -test/tck/ +test/tck/* !test/tck/.gitkeep diff --git a/package.json b/package.json index 492eaeb1..74d29eac 100755 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "parse-tck": "babel-node test/helpers/tck/parseTck.js", "test-tck": "nyc ava --fail-fast test/tck/", "report-coverage": "nyc report --reporter=text-lcov > coverage.lcov && codecov", - "test-all": "nyc ava test/*.js test/neo4j-schema/*Test.js --verbose", + "test-all": "nyc ava test/ --verbose", + "test-isolated": "nyc ava test/ --verbose --match='!*not-isolated*'", "debug": "nodemon ./example/apollo-server/movies.js --exec babel-node --inspect-brk=9229 --nolazy", "debug-typedefs": "nodemon ./example/apollo-server/movies-typedefs.js --exec babel-node --inspect-brk=9229 --nolazy", "debug-interface": "nodemon ./example/apollo-server/interfaceError.js --exec babel-node --inspect-brk=9229 --nolazy" diff --git a/test/integration.js b/test/integration/intgration.test.js similarity index 83% rename from test/integration.js rename to test/integration/intgration.test.js index 23f904a8..5f14517f 100644 --- a/test/integration.js +++ b/test/integration/intgration.test.js @@ -172,7 +172,7 @@ test('Handle @cypher directive on QueryType', async t => { }); }); -test('Mutation with @cypher directive', async t => { +test('Mutation with @cypher directive (not-isolated)', async t => { t.plan(1); let expected = { @@ -202,7 +202,7 @@ test('Mutation with @cypher directive', async t => { }); }); -test('Create node mutation', async t => { +test('Create node mutation (not-isolated)', async t => { t.plan(1); let expected = { @@ -279,7 +279,7 @@ test('Update node mutation', async t => { }); }); -test.serial('Add relationship mutation', async t => { +test.serial('Add relationship mutation (not-isolated)', async t => { t.plan(1); let expected = { @@ -348,7 +348,7 @@ test.serial('Add relationship mutation', async t => { }); }); -test.serial('Remove relationship mutation', async t => { +test.serial('Remove relationship mutation (not-isolated)', async t => { t.plan(1); await client @@ -613,54 +613,57 @@ test('query using inine fragment', async t => { */ // Temporal node property -test.serial('Temporal - Create node with temporal property', async t => { - t.plan(1); +test.serial( + 'Temporal - Create node with temporal property (not-isolated)', + async t => { + t.plan(1); - let expected = { - data: { - CreateMovie: { - __typename: 'Movie', - title: 'Bob Loblaw', - dateTime: { - __typename: '_Neo4jDateTime', - year: 2010, - month: 1, - day: 2 + let expected = { + data: { + CreateMovie: { + __typename: 'Movie', + title: 'Bob Loblaw', + dateTime: { + __typename: '_Neo4jDateTime', + year: 2010, + month: 1, + day: 2 + } } } - } - }; + }; - await client - .mutate({ - mutation: gql` - mutation { - CreateMovie( - title: "Bob Loblaw" - imdbRating: 2.0 - year: 2010 - dateTime: { year: 2010, month: 1, day: 2 } - ) { - title - dateTime { - year - month - day + await client + .mutate({ + mutation: gql` + mutation { + CreateMovie( + title: "Bob Loblaw" + imdbRating: 2.0 + year: 2010 + dateTime: { year: 2010, month: 1, day: 2 } + ) { + title + dateTime { + year + month + day + } } } - } - ` - }) - .then(data => { - t.deepEqual(data, expected); - }) - .catch(error => { - t.fail(error); - }); -}); + ` + }) + .then(data => { + t.deepEqual(data, expected); + }) + .catch(error => { + t.fail(error); + }); + } +); test.serial( - 'Temporal - Create node with multiple temporal fields and input formats', + 'Temporal - Create node with multiple temporal fields and input formats (not-isolated)', async t => { t.plan(1); @@ -727,7 +730,7 @@ test.serial( ); test.serial( - 'Temporal - Create node with multiple temporal fields and input formats - with GraphQL variables', + 'Temporal - Create node with multiple temporal fields and input formats - with GraphQL variables (not-isolated)', async t => { t.plan(1); @@ -802,282 +805,300 @@ test.serial( } ); -test.serial('Temporal - Query node with temporal field', async t => { - let expected = { - data: { - Movie: [ - { - __typename: 'Movie', - title: 'Bob Loblaw 3', - date: { - __typename: '_Neo4jDate', - formatted: '2010-01-02' - }, - localDateTime: { - __typename: '_Neo4jLocalDateTime', - day: 2, - month: 1, - year: 2010, - hour: 0, - minute: 0, - second: 0, - formatted: '2010-01-02T00:00:00' - }, - dateTime: { - __typename: '_Neo4jDateTime', - timezone: 'Z', - day: 2, - month: 1, - year: 2010, - hour: 0, - minute: 0, - second: 0, - millisecond: 0, - nanosecond: 0 - } - } - ] - } - }; - - await client - .query({ - query: gql` - { - Movie(title: "Bob Loblaw 3") { - title - date { - formatted - } - localDateTime { - day - month - year - hour - minute - second - formatted - } - dateTime { - timezone - day - month - year - hour - minute - second - millisecond - nanosecond +test.serial( + 'Temporal - Query node with temporal field (not-isolated)', + async t => { + let expected = { + data: { + Movie: [ + { + __typename: 'Movie', + title: 'Bob Loblaw 3', + date: { + __typename: '_Neo4jDate', + formatted: '2010-01-02' + }, + localDateTime: { + __typename: '_Neo4jLocalDateTime', + day: 2, + month: 1, + year: 2010, + hour: 0, + minute: 0, + second: 0, + formatted: '2010-01-02T00:00:00' + }, + dateTime: { + __typename: '_Neo4jDateTime', + timezone: 'Z', + day: 2, + month: 1, + year: 2010, + hour: 0, + minute: 0, + second: 0, + millisecond: 0, + nanosecond: 0 } } - } - ` - }) - .then(data => { - t.deepEqual(data.data, expected.data); - }) - .catch(error => { - t.fail(error); - }); -}); - -test.serial('Temporal - create node with only a temporal property', async t => { - t.plan(1); - - let expected = { - data: { - CreateOnlyDate: { - __typename: 'OnlyDate', - date: { - __typename: '_Neo4jDate', - formatted: '2020-11-10' - } + ] } - } - }; + }; - await client - .mutate({ - mutation: gql` - mutation { - CreateOnlyDate(date: { day: 10, month: 11, year: 2020 }) { - date { - formatted + await client + .query({ + query: gql` + { + Movie(title: "Bob Loblaw 3") { + title + date { + formatted + } + localDateTime { + day + month + year + hour + minute + second + formatted + } + dateTime { + timezone + day + month + year + hour + minute + second + millisecond + nanosecond + } } } - } - ` - }) - .then(data => { - t.deepEqual(data, expected); - }) - .catch(error => { - t.fail(error); - }); -}); + ` + }) + .then(data => { + t.deepEqual(data.data, expected.data); + }) + .catch(error => { + t.fail(error); + }); + } +); -test.serial('Temporal - temporal query argument, components', async t => { - t.plan(1); +test.serial( + 'Temporal - create node with only a temporal property (not-isolated)', + async t => { + t.plan(1); - let expected = { - data: { - OnlyDate: [ - { + let expected = { + data: { + CreateOnlyDate: { __typename: 'OnlyDate', date: { __typename: '_Neo4jDate', formatted: '2020-11-10' } } - ] - } - }; + } + }; - await client - .query({ - query: gql` - { - OnlyDate(date: { day: 10, month: 11, year: 2020 }) { - date { - formatted + await client + .mutate({ + mutation: gql` + mutation { + CreateOnlyDate(date: { day: 10, month: 11, year: 2020 }) { + date { + formatted + } } } - } - ` - }) - .then(data => { - t.deepEqual(data.data, expected.data); - }) - .catch(error => { - t.fail(error); - }); -}); + ` + }) + .then(data => { + t.deepEqual(data, expected); + }) + .catch(error => { + t.fail(error); + }); + } +); -test.serial('Temporal - temporal query argument, formatted', async t => { - t.plan(1); +test.serial( + 'Temporal - temporal query argument, components (not-isolated)', + async t => { + t.plan(1); - let expected = { - data: { - OnlyDate: [ - { - __typename: 'OnlyDate', - date: { - __typename: '_Neo4jDate', - formatted: '2020-11-10' + let expected = { + data: { + OnlyDate: [ + { + __typename: 'OnlyDate', + date: { + __typename: '_Neo4jDate', + formatted: '2020-11-10' + } } - } - ] - } - }; + ] + } + }; - await client - .query({ - query: gql` - { - OnlyDate(date: { formatted: "2020-11-10" }) { - date { - formatted + await client + .query({ + query: gql` + { + OnlyDate(date: { day: 10, month: 11, year: 2020 }) { + date { + formatted + } } } - } - ` - }) - .then(data => { - t.deepEqual(data.data, expected.data); - }) - .catch(error => { - t.fail(error); - }); -}); + ` + }) + .then(data => { + t.deepEqual(data.data, expected.data); + }) + .catch(error => { + t.fail(error); + }); + } +); -test.serial('Add relationship with temporal property', async t => { - t.plan(1); +test.serial( + 'Temporal - temporal query argument, formatted (not-isolated)', + async t => { + t.plan(1); - let expected = { - data: { - AddMovieRatings: { - __typename: '_AddMovieRatingsPayload', - date: { - __typename: '_Neo4jDate', - formatted: '2018-12-18' - }, - rating: 5 + let expected = { + data: { + OnlyDate: [ + { + __typename: 'OnlyDate', + date: { + __typename: '_Neo4jDate', + formatted: '2020-11-10' + } + } + ] } - } - }; + }; - await client - .mutate({ - mutation: gql` - mutation { - AddMovieRatings( - from: { userId: 18 } - to: { movieId: 6683 } - data: { rating: 5, date: { year: 2018, month: 12, day: 18 } } - ) { - date { - formatted + await client + .query({ + query: gql` + { + OnlyDate(date: { formatted: "2020-11-10" }) { + date { + formatted + } } - rating } - } - ` - }) - .then(data => { - t.deepEqual(data, expected); - }) - .catch(error => { - t.fail(error); - }); -}); + ` + }) + .then(data => { + t.deepEqual(data.data, expected.data); + }) + .catch(error => { + t.fail(error); + }); + } +); -test.serial('Query for temporal property on relationship', async t => { - t.plan(1); +test.serial( + 'Add relationship with temporal property (not-isolated)', + async t => { + t.plan(1); - let expected = { - data: { - Movie: [ - { - __typename: 'Movie', - title: 'Fire', - ratings: [ - { - __typename: '_MovieRatings', - date: { - __typename: '_Neo4jDate', - formatted: '2018-12-18' - }, - rating: 5 - } - ] + let expected = { + data: { + AddMovieRatings: { + __typename: '_AddMovieRatingsPayload', + date: { + __typename: '_Neo4jDate', + formatted: '2018-12-18' + }, + rating: 5 } - ] - } - }; + } + }; - await client - .query({ - query: gql` - { - Movie(movieId: 6683) { - title - ratings { + await client + .mutate({ + mutation: gql` + mutation { + AddMovieRatings( + from: { userId: 18 } + to: { movieId: 6683 } + data: { rating: 5, date: { year: 2018, month: 12, day: 18 } } + ) { date { formatted } rating } } - } - ` - }) - .then(data => { - t.deepEqual(data.data, expected.data); - }) - .catch(error => { - t.fail(error); - }); -}); + ` + }) + .then(data => { + t.deepEqual(data, expected); + }) + .catch(error => { + t.fail(error); + }); + } +); + +test.serial( + 'Query for temporal property on relationship (not-isolated)', + async t => { + t.plan(1); + + let expected = { + data: { + Movie: [ + { + __typename: 'Movie', + title: 'Fire', + ratings: [ + { + __typename: '_MovieRatings', + date: { + __typename: '_Neo4jDate', + formatted: '2018-12-18' + }, + rating: 5 + } + ] + } + ] + } + }; + + await client + .query({ + query: gql` + { + Movie(movieId: 6683) { + title + ratings { + date { + formatted + } + rating + } + } + } + ` + }) + .then(data => { + t.deepEqual(data.data, expected.data); + }) + .catch(error => { + t.fail(error); + }); + } +); test('Basic filter', async t => { t.plan(1); diff --git a/test/test-middleware.js b/test/integration/test-middleware.test.js similarity index 100% rename from test/test-middleware.js rename to test/integration/test-middleware.test.js diff --git a/test/tck/.gitkeep b/test/tck/.gitkeep new file mode 100644 index 00000000..e69de29b