CucumberJS 未在 Gitlab 的打字稿中编译 CI

CucumberJS not compiling in typescript in Gitlab CI

NPM 脚本: "cucumber": "cucumber-js --require features/tests.setup.js --require features/**/*.ts".

tests.setup.js:

require('ts-node').register({
  transpileOnly: true,
  compilerOptions: {
    "module": "commonjs",
  },
});

GitlabCI错误:

> cucumber-js --require features/tests.setup.js --require features/**/*.ts
Error: Parse error in 'features/step-definitions/steps.calculus-triangle.ts': (1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'import {Then} from 'cucumber''
    at events.forEach.event (/builds/Ambroise-Rabier/mandala-vibratoire/node_modules/cucumber/lib/cli/helpers.js:110:13)
    at Array.forEach (<anonymous>)
    at getTestCases (/builds/Ambroise-Rabier/mandala-vibratoire/node_modules/cucumber/lib/cli/helpers.js:81:10)
    at _bluebird.default.each (/builds/Ambroise-Rabier/mandala-vibratoire/node_modules/cucumber/lib/cli/helpers.js:58:35)

它在本地(win 10)工作,但在 Gitlab 上 CI 它似乎忽略了 typescript 编译。

我在 的帮助下找到了一些有用的东西,但是我没有使用 nyc,所以这里的解决方案只使用 cucumberjs.

NPM 脚本: "cucumber": "cucumber-js --profile default".

在项目的根目录创建 cucumber.js 文件,内容为:

let common = [
  '--require features/tests.setup.js',
  '--require features/**/*.ts',
].join(' ');

module.exports = {
  default: common,
};

相关文档https://github.com/cucumber/cucumber-js/blob/master/docs/cli.md#profiles