Skip to content

Commit

Permalink
E2E tests (#131)
Browse files Browse the repository at this point in the history
* Added e2e tests

* Moved E2E/Integration tests into src/tests subfolders

* CI attempt e2e
  • Loading branch information
AvivRubys authored Mar 12, 2020
1 parent 41d23c3 commit 9dc2e25
Show file tree
Hide file tree
Showing 29 changed files with 310 additions and 51 deletions.
21 changes: 13 additions & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: 2.1
orbs:
docker: circleci/docker@0.5.20
node: circleci/node@1.1.6
executors:
linux:
machine:
Expand All @@ -20,19 +21,23 @@ jobs:
- docker/push:
image: soluto/stitch
tag: '$CIRCLE_TAG'
build_test:
executor: linux
steps:
- checkout
- node/install:
install-yarn: false
- run:
command: |
cd services
npm ci
npm run test:full
workflows:
version: 2
pull_request:
jobs:
- docker/publish:
executor: linux
deploy: false
docker-username: DOCKERHUB_USERNAME
docker-password: DOCKERHUB_PASSWORD
image: soluto/stitch
path: ./services
dockerfile: deployment/docker/Dockerfile
- build_test:
filters:
branches:
ignore:
Expand Down
1 change: 1 addition & 0 deletions services/.dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ dist/

deployment/dev
.vscode/
src/tests/e2e
2 changes: 0 additions & 2 deletions services/deployment/dev/.env
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,3 @@ RESOURCE_UPDATE_INTERVAL=2000

AWS_ACCESS_KEY_ID=stitch_key_id
AWS_SECRET_ACCESS_KEY=stitch_secret_key
MINIO_ACCESS_KEY=stitch_key_id
MINIO_SECRET_KEY=stitch_secret_key
3 changes: 3 additions & 0 deletions services/deployment/dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ services:
- 9000:9000
command: server /var/minio
env_file: .env
environment:
MINIO_ACCESS_KEY: ${AWS_ACCESS_KEY_ID}
MINIO_SECRET_KEY: ${AWS_SECRET_ACCESS_KEY}
volumes:
- './minio_mount:/var/minio:rw'
3 changes: 2 additions & 1 deletion services/deployment/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ FROM dependencies as build-dependencies
RUN npm ci

FROM build-dependencies as test
RUN npm run test
ARG RUN_TESTS=true
RUN if [ "$RUN_TESTS" = "true" ]; then npm run test; fi

FROM build-dependencies as build
RUN npm run build
Expand Down
15 changes: 15 additions & 0 deletions services/jest.config.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
projects: [
{
displayName: 'End-to-End Tests',
roots: ['<rootDir>/src/tests/e2e'],
testTimeout: 30000,
testEnvironment: '<rootDir>/src/tests/e2e/jest-e2e-environment.js',
runner: '<rootDir>/src/tests/e2e/jest-e2e-runner.js',
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
},
],
};
3 changes: 3 additions & 0 deletions services/jest.config.full.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
projects: [...require('./jest.config').projects, ...require('./jest.config.e2e').projects],
};
12 changes: 6 additions & 6 deletions services/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ module.exports = {
{
displayName: 'Unit Tests',
roots: ['<rootDir>/src'],
testPathIgnorePatterns: ['/node_modules/', '/src/integration'],
setupFiles: ['./setupJestUnit.js'],

testPathIgnorePatterns: ['/node_modules/', '/src/tests'],
setupFiles: ['<rootDir>/setupJestUnit.js'],
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
},
},
{
displayName: 'Integration Tests',
roots: ['<rootDir>/src/integration'],
setupFiles: ['./src/integration/setupJest.js'],

roots: ['<rootDir>/src/tests/integration'],
setupFiles: ['<rootDir>/src/tests/integration/setup.js'],
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],
transform: {
'^.+\\.(ts|tsx)$': 'ts-jest',
Expand Down
77 changes: 58 additions & 19 deletions services/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
"name": "stitch",
"version": "1.0.0",
"scripts": {
"test": "jest",
"test": "jest --config jest.config.js",
"test:e2e": "jest --config jest.config.e2e.js",
"test:full": "jest --config jest.config.full.js",
"build": "tsc",
"build:dev": "tsc --watch",
"start:gateway:watch": "ts-node-dev src/gateway.ts",
Expand Down Expand Up @@ -41,8 +43,12 @@
"@types/node": "^13.7.4",
"@types/pino": "^5.15.5",
"apollo-server-testing": "^2.10.1",
"docker-compose": "^0.23.3",
"graphql-request": "^1.8.2",
"jest": "^25.1.0",
"jest-environment-node": "^25.1.0",
"jest-fetch-mock": "^3.0.1",
"jest-runner": "^25.1.0",
"nock": "^12.0.1",
"ts-jest": "^25.2.1",
"ts-node-dev": "^1.0.0-pre.44",
Expand Down
10 changes: 10 additions & 0 deletions services/src/tests/e2e/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AWS_ACCESS_KEY_ID=e2e_key_id
AWS_SECRET_ACCESS_KEY=e2e_secret_key

RESOURCE_UPDATE_INTERVAL=500
S3_RESOURCE_BUCKET_NAME=stitch-resources
S3_RESOURCE_OBJECT_KEY=resources.json
S3_ENDPOINT=http://minio:9000

USE_S3_RESOURCE_REPOSITORY=true
USE_FS_RESOURCE_REPOSITORY=false
48 changes: 48 additions & 0 deletions services/src/tests/e2e/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: '3.7'

services:
gateway:
build:
context: ../../..
dockerfile: deployment/docker/Dockerfile
args:
RUN_TESTS: 'false'
depends_on:
- minio
ports:
- '8080:80'
command: gateway
env_file: .env
environment:
PORT: 80

registry:
build:
context: ../../..
dockerfile: deployment/docker/Dockerfile
args:
RUN_TESTS: 'false'
depends_on:
- minio
ports:
- '8090:80'
command: registry
env_file: .env
environment:
PORT: 80

minio:
image: minio/minio
ports:
- 9000:9000
entrypoint: sh
environment:
MINIO_ACCESS_KEY: ${AWS_ACCESS_KEY_ID}
MINIO_SECRET_KEY: ${AWS_SECRET_ACCESS_KEY}
command: >
-c "
mkdir -p /var/minio/${S3_RESOURCE_BUCKET_NAME} &&
echo '{\"schemas\":[],\"upstreams\": [],\"upstreamClientCredentials\": []}' > /var/minio/${S3_RESOURCE_BUCKET_NAME}/${S3_RESOURCE_OBJECT_KEY} &&
minio server /var/minio
"
env_file: .env
16 changes: 16 additions & 0 deletions services/src/tests/e2e/jest-e2e-environment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const NodeEnvironment = require('jest-environment-node');
const dockerCompose = require('docker-compose');
const waitFor = require('./waitFor');

const sleep = timeout => new Promise(r => setTimeout(r, timeout));

class DockerComposeEnvironment extends NodeEnvironment {
async setup() {
await super.setup();
await dockerCompose.restartAll({cwd: __dirname, log: true});
await sleep(1000); // letting it go down before polling
await Promise.all([waitFor.gatewayStart(10000), waitFor.registryStart(10000)]);
}
}

module.exports = DockerComposeEnvironment;
32 changes: 32 additions & 0 deletions services/src/tests/e2e/jest-e2e-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const DefaultJestRunner = require('jest-runner');
const dockerCompose = require('docker-compose');
const waitFor = require('./waitFor');

class SerialJestRunner extends DefaultJestRunner {
constructor(config, context) {
super(config, context);
this.isSerial = true;
}

async setup() {
await dockerCompose.buildAll({cwd: __dirname, log: true});
await dockerCompose.upAll({cwd: __dirname, log: true});
await Promise.all([waitFor.gatewayStart(20000), waitFor.registryStart(20000)]);
}

async teardown() {
await dockerCompose.down({cwd: __dirname, log: true});
await Promise.all([waitFor.gatewayStop(10000), waitFor.registryStop(10000)]);
}

async runTests(tests, watcher, onStart, onResult, onFailure, options) {
try {
await this.setup();
await super.runTests(tests, watcher, onStart, onResult, onFailure, options);
} finally {
await this.teardown();
}
}
}

module.exports = SerialJestRunner;
Loading

0 comments on commit 9dc2e25

Please sign in to comment.