![](/img/trans.png)
[英]Jest + SuperTest tests passes locally but not exiting and keep running on GitHub actions
[英]Jest Tests Failing on Github Actions
我有一个我现在正在处理的 Repo,它使用带有 TDD 的干净架构。 当我在我的机器上本地运行测试时,一切正常。 但是当我尝试使用 Github Actions 在每次提交和 PR 上运行时,我遇到了很多错误。 我也有 husky 和 lint-staged。
我的笑话配置:
// 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
}
}
我的 Github 动作
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
和我的 package.json 脚本
"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"
尝试将 --maxWorkers=2 添加到您的 jest 命令中。 这将防止 jest 意外产生过多的工人。
- name: Test
run: yarn test:ci --verbose --maxWorkers=2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.