Reputation: 277
I have a Repo that i'm working on right now that uses clean architecture with TDD. When i run the tests locally on my machine everything is ok. but when i'm trying to use with Github Actions to run on every commit and PR i'm getting a lot of errors. I also have husky and lint-staged.
My jest configs:
// jest.config.js
module.exports = {
roots: ['<rootDir>/src'],
collectCoverageFrom: ['<rootDir>/src/**/*.ts', '!<rootDir>/src/main/**'],
coverageDirectory: 'coverage',
testEnvironment: 'node',
transform: {
'.+\\.ts$': 'ts-jest'
},
preset: '@shelf/jest-mongodb',
}
// jest-unit.config.js
const config = require('./jest.config')
config.testMatch = ['**/*.spec.ts']
module.exports = config
// jest-integration.config.js
const config = require('./jest.config')
config.testMatch = ['**/*.test.ts']
module.exports = config
// jest-mongodb.config.js
module.exports = {
mongodbMemoryServerOptions: {
instance: {
dbName: 'jest'
},
binary: {
version: '4.0.3',
skipMD5: true
},
autoStart: false
}
}
My Github Action
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Setup Node
uses: actions/setup-node@v2-beta
with:
node-version: '12'
check-latest: true
- name: Install Dependencies
run: yarn
- name: Test
run: yarn test:ci --verbose
and my package.json scripts
"start": "node dist/main/server.js",
"build": "rimraf dist && tsc",
"build:watch": "tsc -w",
"debug": "nodemon -L --watch ./dist --inspect=0.0.0.0:9222 --nolazy ./dist/main/server.js",
"dev": "docker-compose",
"up": "yarn build && yarn dev up",
"down": "yarn dev down",
"lint": "eslint 'src/**' --quiet",
"lint:fix": "eslint 'src/**' --quiet --fix",
"test": "jest --passWithNoTests --silent --noStackTrace --runInBand",
"test:verbose": "jest --passWithNoTests --runInBand --watch",
"test:unit": "yarn test --watch -c ./jest-unit.config.js",
"test:integration": "yarn test --watch -c ./jest-integration.config.js",
"test:staged": "yarn test --findRelatedTests",
"test:ci": "yarn test --coverage"
Upvotes: 1
Views: 5139
Reputation: 332
try add --maxWorkers=2 to your jest command. This will prevent jest from accidentally spawning too many workers.
- name: Test
run: yarn test:ci --verbose --maxWorkers=2
Upvotes: 4