【问题标题】:Jest Tests Failing on Github Actions对 Github 操作的 Jest 测试失败
【发布时间】:2020-10-26 18:30:11
【问题描述】:

我现在正在处理一个使用干净架构和 TDD 的 Repo。当我在我的机器上本地运行测试时,一切正常。但是当我尝试使用 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"

【问题讨论】:

    标签: node.js github jestjs github-actions


    【解决方案1】:

    尝试将 --maxWorkers=2 添加到您的 jest 命令中。这将防止 jest 意外产生过多的工人。

    - name: Test
      run: yarn test:ci --verbose --maxWorkers=2
    

    【讨论】:

      猜你喜欢
      • 2020-02-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-01
      • 2022-12-18
      • 2017-02-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多