使用hapi / jest运行单元测试时Gitlab CI失败

时间:2019-12-27 11:06:34

标签: typescript jestjs gitlab-ci gitlab-ci-runner hapi

我们当前面临的问题是,当我们在GitLab CI上运行Jest时,测试失败,并出现以下错误:

Test suite failed to run
     Cannot find module '@Hapi/joi' from 'user.schema.ts'
     However, Jest was able to find:
        'plugins/index.ts'
     You might want to include a file extension in your import, or update your 'moduleFileExtensions', 
     which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node', 'ts', 'tsx'].
     See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string
     However, Jest was able to find:
        '../../app.ts'

,但是它在本地Windows计算机上运行良好。似乎我们的Jest配置文件在我们的网站上存在配置错误,但我看不到任何错误。看起来像这样:

const { defaults } = require( 'jest-config' );

module.exports = {
  roots: [
    '<rootDir>/src'
  ],
  moduleDirectories: [
    '<rootDir>/src',
    'node_modules'
  ],
  globals: {
    'ts-jest': {
      tsConfig: 'tsconfig.json',
      diagnostics: false
    }
  },
  transform: {
    '^.+\\.(ts|tsx)$': 'ts-jest'
  },
  moduleFileExtensions: [ ...defaults.moduleFileExtensions, 'ts', 'tsx' ],
};

所以我的猜测是Jest在解析正确的路径时出错,但我无法正常工作。有谁有同样的问题,可以给我提示如何解决此问题吗?

0 个答案:

没有答案