Skip to content

Commit

Permalink
Get e2e tests working on GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
humphd committed Feb 24, 2021
1 parent 750f8c0 commit 0b38146
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 56 deletions.
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ module.exports = {
],
plugins: ['prettier', 'promise', 'react', 'react-hooks'],
settings: {
'importer/resolver': {
node: {},
},
react: {
version: 'detect',
},
Expand Down Expand Up @@ -138,5 +141,11 @@ module.exports = {
'react/no-danger': 'off',

'jsx-a11y/control-has-associated-label': 'warn',

/**
* Due to having our dev dependencies in a monorepo layout, this is
* difficult to configure properly. Disabling for now.
*/
'import/no-extraneous-dependencies': ['off'],
},
};
71 changes: 50 additions & 21 deletions .github/workflows/node-js-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,39 @@ on:
- master

jobs:
build:
runs-on: ${{matrix.os}}
# Confirm that prettier was run on the changes
prettier:
name: Prettier Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: |
npm install
npm run prettier-check
# Make sure eslint passes
eslint:
name: ESLint Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: |
npm install
npm run eslint
# Run unit tests on all platforms/versions of node
unit:
name: Unit Tests
runs-on: ${{matrix.os}}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node-version: [12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Cache node modules
uses: actions/cache@v2
- uses: actions/cache@v2
env:
cache-name: cache-node-modules
with:
Expand All @@ -31,25 +52,33 @@ jobs:
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Test
uses: actions/setup-node@v1
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: cp env.example .env
# Start the microservices needed for tests
- run: npm run services:start auth
- run: npm run test
Prettier-Check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: npm install && npm run prettier-check
Lint:
- run: |
npm install
cp env.example .env
npm run jest
# Run end-to-end tests along with the microservices in docker-compose on Linux
e2e:
name: End-To-End Tests
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x]
steps:
- uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: npm install && npm run eslint
with:
node-version: ${{ matrix.node-version }}
- run: |
npm install
npm run services:start
npm run jest:e2e
15 changes: 15 additions & 0 deletions jest-playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// NOTE: this should really live in src/api/auth but jest-playwright doesn't
// seen to know how to find it if I put it there. It has to be at the root.
module.exports = {
launchOptions: {
headless: true,
},
browsers: ['chromium', 'firefox', 'webkit'],
serverOptions: {
command: 'npx http-server src/api/auth/test/e2e -p 8888',
port: 8888,
launchTime: 10000,
usedPortAction: 'kill',
debug: true,
},
};
6 changes: 6 additions & 0 deletions jest.config.e2e.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const baseConfig = require('./jest.config.base');

module.exports = {
...baseConfig,
projects: ['<rootDir>/src/api/**/jest.config.e2e.js'],
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"pretest": "npm run lint",
"test": "npm run jest",
"jest": "cross-env NODE_ENV=test LOG_LEVEL=error MOCK_REDIS=1 FEED_URL_INTERVAL_MS=200 jest -c jest.config.js --",
"jest:e2e": "jest -c jest.config.e2e.js --",
"coverage": "cross-env NODE_ENV=test LOG_LEVEL=silent MOCK_REDIS=1 FEED_URL_INTERVAL_MS=200 jest --collectCoverage --",
"jest-watch": "cross-env MOCK_REDIS=1 jest --watch --",
"start": "node src/backend",
Expand Down Expand Up @@ -115,8 +116,10 @@
"husky": "5.0.9",
"jest": "26.6.3",
"jest-fetch-mock": "3.0.3",
"jest-playwright-preset": "1.4.7",
"nock": "13.0.7",
"npm-run-all": "4.1.5",
"playwright": "1.9.0",
"prettier": "2.2.1",
"pretty-quick": "3.1.0",
"react-test-renderer": "17.0.1",
Expand Down
28 changes: 2 additions & 26 deletions src/api/auth/jest-playwright.config.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,2 @@
// NOTE: you need to copy ../env.development to ../.env and run services
const result = require('dotenv').config({ path: '../.env' });

if (result.error) {
throw result.error;
}

const showServerLogs = false;

module.exports = {
launchOptions: {
headless: true,
},
browsers: ['chromium', 'firefox', 'webkit'],
// Quit when any test fails to save time
bail: 1,
serverOptions: [
{
command: 'npx http-server test/e2e -p 8888',
port: 8888,
launchTime: 5000,
usedPortAction: 'kill',
debug: showServerLogs,
},
],
};
// Due to https://github.com/playwright-community/jest-playwright/issues/446
// we put our jest-playwright config in the Telescope root, see ./jest-playwright.confing.js
11 changes: 9 additions & 2 deletions src/api/auth/jest.config.e2e.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
const baseConfig = require('../../../jest.config.base');

module.exports = {
...baseConfig,
rootDir: '../../..',
setupFiles: ['<rootDir>/jest.setup.js', '<rootDir>/src/api/auth/jest.setup.js'],
testMatch: ['<rootDir>/src/api/auth/test/e2e/**/*.test.js'],
collectCoverageFrom: ['<rootDir>/src/api/auth/server.js', '<rootDir>/src/api/auth/src/**/*.js'],
// We use jest-playwright to do browser tests, https://github.com/playwright-community/jest-playwright
// See the jest-playwright config in the Telescope root ./jest-playwright.config.js
preset: 'jest-playwright-preset',
testPathIgnorePatterns: ['/node_modules/'],
testMatch: ['<rootDir>/test/e2e/**/*.test.js'],
};
8 changes: 1 addition & 7 deletions src/api/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"version": "1.0.0",
"description": "An Authorization Service",
"scripts": {
"test:e2e": "jest -c jest.config.e2e.js",
"test:manual": "http-server test/manual -p 8888",
"test:unit": "jest -c jest.config.js",
"dev": "nodemon server.js | pino-pretty -c -t",
"start": "node server.js"
},
Expand Down Expand Up @@ -34,11 +32,7 @@
},
"devDependencies": {
"http-server": "^0.12.3",
"jest": "^26.6.3",
"jest-playwright-preset": "^1.4.6",
"nodemon": "^2.0.7",
"pino-pretty": "^4.5.0",
"playwright": "^1.8.1",
"supertest": "^6.1.3"
"pino-pretty": "^4.5.0"
}
}
File renamed without changes.
File renamed without changes.

0 comments on commit 0b38146

Please sign in to comment.