玩笑测试在Github动作上失败

时间:2020-07-06 15:28:18

标签: node.js github jestjs github-actions

我有一个正在使用的Repo,它使用带有TDD的干净架构。当我在计算机上本地运行测试时,一切正常。但是当我尝试与Github Actions一起使用以在每次提交和PR上运行时,我遇到了很多错误。我也有沙哑的和上绒的。

enter image description here enter image description here

我的玩笑配置:

// 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"

1 个答案:

答案 0 :(得分:0)

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

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