Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit a73a684

Browse files
jelisejevtrioletas
authored andcommitted
E2e tests (#233)
* add e2e tests * update readme * change query name; change tests to e2e * use exact versions * remove unused param * use isomorphic fetch * rename E2E_TEST_URI * add e2e tests to tsconfig.json * refactor export statement * update yarn.lock * move e2e test variables to a separate file * Update README.md
1 parent 8a5ea42 commit a73a684

File tree

9 files changed

+157
-4
lines changed

9 files changed

+157
-4
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ Attention Windows users: when `Docker for Windows` is not an option, install `ya
8383
- npm: `$ npm test`
8484
- yarn: `$ yarn test`
8585

86+
### Run e2e tests
87+
88+
Run the app or point E2E_TEST_URL to a remote instance you want to test against.
89+
- npm: `$ npm run test:e2e`
90+
- yarn: `$ yarn test:e2e`
91+
8692
### Generate coverage reports
8793

8894
Set environment variable `CI` to true to generate coverage reports.

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,3 @@ services:
1212
- 3001:3001
1313
environment:
1414
- SHELL=/bin/sh
15-

e2e/client.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { ApolloClient } from 'apollo-client';
2+
import { HttpLink } from 'apollo-link-http';
3+
import { InMemoryCache } from 'apollo-cache-inmemory';
4+
export { default as gql } from 'graphql-tag';
5+
6+
import 'isomorphic-fetch';
7+
8+
const httpLink = new HttpLink({
9+
uri: `${process.env.E2E_TEST_URL}/${process.env.GRAPHQL_PATH}`,
10+
});
11+
12+
const client = () => new ApolloClient({
13+
link: httpLink,
14+
cache: new InMemoryCache(),
15+
});
16+
17+
export default client;

e2e/joke.e2e.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import client, { gql } from './client';
2+
3+
test('jokes.byCategory should return a random joke', async () => {
4+
const response = await client().query({
5+
query: gql`
6+
query RandomJokeByCategory {
7+
jokes {
8+
byCategory {
9+
id
10+
text
11+
categories
12+
}
13+
}
14+
}
15+
`,
16+
});
17+
18+
const byCategory = (response.data as any).jokes.byCategory;
19+
expect(byCategory).toMatchObject({
20+
id: expect.any(String),
21+
text: expect.any(String),
22+
categories: expect.any(Array),
23+
});
24+
});

jest/__setup__/e2e-env-test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import envalid from 'envalid';
2+
3+
const { str } = envalid;
4+
5+
const env = envalid.cleanEnv(process.env, {
6+
GRAPHQL_PATH: str({ default: 'graphql' }),
7+
E2E_TEST_URL: str({ default: 'http://localhost:3001' }),
8+
});
9+
10+
export default env;

jest/__setup__/e2e-setup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import env from './e2e-env-test';
2+
process.env = env;

jest/e2e.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const path = require('path');
2+
3+
module.exports = Object.assign(
4+
{},
5+
require('./default.config.js'),
6+
{
7+
"testRegex": ".*\\.e2e\\.(ts)$",
8+
"roots": [
9+
"e2e"
10+
],
11+
"setupFiles": [
12+
path.join(__dirname, "./__setup__/e2e-setup.ts")
13+
],
14+
}
15+
);

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
"test:integration": "npm run validate:env && jest --config jest/integration.config.js",
1111
"test:unit": "npm run validate:env && jest --config jest/unit.config.js",
1212
"test:all": "npm run validate:env && jest",
13+
"test:e2e": "npm run validate:env-e2e && jest --config jest/e2e.config.js",
1314
"lint": "tslint -t stylish 'src/**/*.ts'",
1415
"lint:watch": "chokidar \"src/**/*.ts\" -c \"tslint -t stylish --force '{path}'\"",
1516
"validate:env": "tsc src/env.ts --lib esnext --esModuleInterop --outDir ./build/ && node ./build/env.js",
17+
"validate:env-e2e": "tsc jest/__setup__/e2e-env-test.ts --lib esnext --esModuleInterop --outDir ./build/e2e && node ./build/e2e/e2e-env-test.js",
1618
"clean": "rimraf build",
1719
"clean:graphql": "rimraf build/**/*.{gql,graphql,graphqls}",
1820
"copy:graphql": "cpx \"src/**/*.{gql,graphql,graphqls}\" build",
@@ -51,11 +53,16 @@
5153
"@types/koa": "2.0.45",
5254
"@types/koa-router": "7.0.28",
5355
"@types/nock": "9.1.3",
56+
"apollo-cache-inmemory": "1.1.12",
57+
"apollo-client": "2.2.8",
58+
"apollo-link-http": "1.5.4",
5459
"cash-touch": "0.2.0",
5560
"chokidar-cli": "1.2.0",
5661
"cpx": "1.5.0",
5762
"docker-share": "0.0.4",
63+
"graphql-tag": "2.8.0",
5864
"graphql-to-typescript": "0.1.2",
65+
"isomorphic-fetch": "2.2.1",
5966
"jest": "22.4.3",
6067
"jest-junit": "3.7.0",
6168
"nock": "9.2.5",

yarn.lock

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
dependencies:
5555
"@types/node" "*"
5656

57+
"@types/async@2.0.47":
58+
version "2.0.47"
59+
resolved "https://registry.yarnpkg.com/@types/async/-/async-2.0.47.tgz#f49ba1dd1f189486beb6e1d070a850f6ab4bd521"
60+
5761
"@types/bluebird@3.5.20":
5862
version "3.5.20"
5963
resolved "https://registry.yarnpkg.com/@types/bluebird/-/bluebird-3.5.20.tgz#f6363172add6f4eabb8cada53ca9af2781e8d6a1"
@@ -178,6 +182,10 @@
178182
"@types/express-serve-static-core" "*"
179183
"@types/mime" "*"
180184

185+
"@types/zen-observable@^0.5.3":
186+
version "0.5.3"
187+
resolved "https://registry.yarnpkg.com/@types/zen-observable/-/zen-observable-0.5.3.tgz#91b728599544efbb7386d8b6633693a3c2e7ade5"
188+
181189
abab@^1.0.4:
182190
version "1.0.4"
183191
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
@@ -280,7 +288,54 @@ apollo-cache-control@^0.1.0:
280288
dependencies:
281289
graphql-extensions "^0.0.x"
282290

283-
apollo-link@^1.2.1:
291+
apollo-cache-inmemory@1.1.12:
292+
version "1.1.12"
293+
resolved "https://registry.yarnpkg.com/apollo-cache-inmemory/-/apollo-cache-inmemory-1.1.12.tgz#ab489bf046b3e026556ab28bdebb6e010cac9531"
294+
dependencies:
295+
apollo-cache "^1.1.7"
296+
apollo-utilities "^1.0.11"
297+
graphql-anywhere "^4.1.8"
298+
299+
apollo-cache@^1.1.7:
300+
version "1.1.7"
301+
resolved "https://registry.yarnpkg.com/apollo-cache/-/apollo-cache-1.1.7.tgz#5817018a2fbfc05a21ba319bd17a3e7538110cc5"
302+
dependencies:
303+
apollo-utilities "^1.0.11"
304+
305+
apollo-client@2.2.8:
306+
version "2.2.8"
307+
resolved "https://registry.yarnpkg.com/apollo-client/-/apollo-client-2.2.8.tgz#b604d31ab2d2dd00db3105d8793b93ee02ce567e"
308+
dependencies:
309+
"@types/zen-observable" "^0.5.3"
310+
apollo-cache "^1.1.7"
311+
apollo-link "^1.0.0"
312+
apollo-link-dedup "^1.0.0"
313+
apollo-utilities "^1.0.11"
314+
symbol-observable "^1.0.2"
315+
zen-observable "^0.7.0"
316+
optionalDependencies:
317+
"@types/async" "2.0.47"
318+
319+
apollo-link-dedup@^1.0.0:
320+
version "1.0.9"
321+
resolved "https://registry.yarnpkg.com/apollo-link-dedup/-/apollo-link-dedup-1.0.9.tgz#3c4e4af88ef027cbddfdb857c043fd0574051dad"
322+
dependencies:
323+
apollo-link "^1.2.2"
324+
325+
apollo-link-http-common@^0.2.4:
326+
version "0.2.4"
327+
resolved "https://registry.yarnpkg.com/apollo-link-http-common/-/apollo-link-http-common-0.2.4.tgz#877603f7904dc8f70242cac61808b1f8d034b2c3"
328+
dependencies:
329+
apollo-link "^1.2.2"
330+
331+
apollo-link-http@1.5.4:
332+
version "1.5.4"
333+
resolved "https://registry.yarnpkg.com/apollo-link-http/-/apollo-link-http-1.5.4.tgz#b80b7b4b342c655b6a5614624b076a36be368f43"
334+
dependencies:
335+
apollo-link "^1.2.2"
336+
apollo-link-http-common "^0.2.4"
337+
338+
apollo-link@^1.0.0, apollo-link@^1.2.1, apollo-link@^1.2.2:
284339
version "1.2.2"
285340
resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.2.tgz#54c84199b18ac1af8d63553a68ca389c05217a03"
286341
dependencies:
@@ -317,6 +372,10 @@ apollo-utilities@^1.0.0, apollo-utilities@^1.0.1:
317372
version "1.0.8"
318373
resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.0.8.tgz#74d797d38953d2ba35e16f880326e2abcbc8b016"
319374

375+
apollo-utilities@^1.0.11:
376+
version "1.0.11"
377+
resolved "https://registry.yarnpkg.com/apollo-utilities/-/apollo-utilities-1.0.11.tgz#cd36bfa6e5c04eea2caf0c204a0f38a0ad550802"
378+
320379
append-transform@^0.4.0:
321380
version "0.4.0"
322381
resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-0.4.0.tgz#d76ebf8ca94d276e247a36bad44a4b74ab611991"
@@ -1840,6 +1899,12 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6:
18401899
version "4.1.11"
18411900
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
18421901

1902+
graphql-anywhere@^4.1.8:
1903+
version "4.1.8"
1904+
resolved "https://registry.yarnpkg.com/graphql-anywhere/-/graphql-anywhere-4.1.8.tgz#23882e6a16ec824febbe5bca40937cdd76c5acdc"
1905+
dependencies:
1906+
apollo-utilities "^1.0.11"
1907+
18431908
graphql-code-generator@^0.5.1:
18441909
version "0.5.5"
18451910
resolved "https://registry.yarnpkg.com/graphql-code-generator/-/graphql-code-generator-0.5.5.tgz#ad2a3ab2ffae56faf0290f0317dd515213f598e5"
@@ -1902,6 +1967,10 @@ graphql-subscriptions@^0.3.1:
19021967
dependencies:
19031968
es6-promise "^3.2.1"
19041969

1970+
graphql-tag@2.8.0:
1971+
version "2.8.0"
1972+
resolved "https://registry.yarnpkg.com/graphql-tag/-/graphql-tag-2.8.0.tgz#52cdea07a842154ec11a2e840c11b977f9b835ce"
1973+
19051974
graphql-to-typescript@0.1.2:
19061975
version "0.1.2"
19071976
resolved "https://registry.yarnpkg.com/graphql-to-typescript/-/graphql-to-typescript-0.1.2.tgz#a5a3ba625216c7408f13e5c62724f9973f42909b"
@@ -2454,7 +2523,7 @@ isobject@^3.0.0, isobject@^3.0.1:
24542523
version "3.0.1"
24552524
resolved "https://registry.yarnpkg.com/isobject/-/isobject-3.0.1.tgz#4e431e92b11a9731636aa1f9c8d1ccbcfdab78df"
24562525

2457-
isomorphic-fetch@^2.1.1:
2526+
isomorphic-fetch@2.1.1:
24582527
version "2.2.1"
24592528
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
24602529
dependencies:
@@ -4576,7 +4645,7 @@ svg-pan-zoom@^3.5.2:
45764645
version "3.5.3"
45774646
resolved "https://registry.yarnpkg.com/svg-pan-zoom/-/svg-pan-zoom-3.5.3.tgz#e6b52a1b349716c78e7b5f92d0ed1cc1b860f5d8"
45784647

4579-
symbol-observable@^1.0.3:
4648+
symbol-observable@^1.0.2, symbol-observable@^1.0.3:
45804649
version "1.2.0"
45814650
resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.2.0.tgz#c22688aed4eab3cdc2dfeacbb561660560a00804"
45824651

@@ -5200,6 +5269,10 @@ zen-observable-ts@^0.8.9:
52005269
dependencies:
52015270
zen-observable "^0.8.0"
52025271

5272+
zen-observable@^0.7.0:
5273+
version "0.7.1"
5274+
resolved "https://registry.yarnpkg.com/zen-observable/-/zen-observable-0.7.1.tgz#f84075c0ee085594d3566e1d6454207f126411b3"
5275+
52035276
zen-observable@^0.8.0:
52045277
version "0.8.8"
52055278
resolved "https://registry.yarnpkg.com/zen-observable/-/zen-observable-0.8.8.tgz#1ea93995bf098754a58215a1e0a7309e5749ec42"

0 commit comments

Comments
 (0)