Error running ./node_modules/.bin/cucumber-js in GitLab CI

∥☆過路亽.° 提交于 2021-01-28 19:45:09

问题


I am setting up a CI build for my node project. Although my npm run test works as expected in my local environment, the gitlab ci is throwing an exception.

The test command fails in: > nyc ./node_modules/.bin/cucumber-js ./test/BDD/**/*.feature -f node_modules/cucumber-pretty -f json:./test/report/cucumber_report.json --require-module ts-node/register --require ./test/**/*.ts

Error: Parse error in 'test/BDD/step-definition.ts': (1:1): expected: #EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'import { StepDefinitionCode, Given, When, Then, StepDefinitionOptions } from "cucumber";' at /builds/cristianmercado19/basic-package/node_modules/cucumber/src/cli/helpers.js:66:13 at Array.forEach () at forEach (/builds/cristianmercado19/basic-package/node_modules/cucumber/src/cli/helpers.js:54:10) at Generator.next () at Generator.tryCatcher (/builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/util.js:16:23) at PromiseSpawn._promiseFulfilled (/builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/generators.js:97:49) at /builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/generators.js:201:15 at getTestCases (/builds/cristianmercado19/basic-package/node_modules/cucumber/lib/cli/helpers.js:102:18) at getTestCases (/builds/cristianmercado19/basic-package/node_modules/cucumber/src/cli/helpers.js:32:13) at Generator.next () at Generator.tryCatcher (/builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/util.js:16:23) at PromiseSpawn._promiseFulfilled (/builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/generators.js:97:49) at Promise._settlePromise (/builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/promise.js:579:26) at Promise._settlePromise0 (/builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/promise.js:619:10) at Promise._settlePromises (/builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/promise.js:699:18) at _drainQueueStep (/builds/cristianmercado19/basic-package/node_modules/bluebird/js/release/async.js:138:12)

Screenshot:

My .gitlab-ci.yml configuration:

image: node:latest

stages:
  - build
  - test

cache:
  paths:
    - node_modules/

install_dependencies:
  stage: build
  script:
    - npm install
    - npm build
  artifacts:
    paths:
      - node_modules/

testing_testing:
  stage: test
  script: npm test

My cucumber folder structure:

I have tried...

  • to get the artifacts and compare the cucumber folder with my local. Both are the same.
  • removing nyc
  • updating packages versions
  • this minimum script also fails "test": "./node_modules/.bin/cucumber-js test/BDD/**/*.feature --require-module ts-node/register --require ./test/**/*.ts",

回答1:


I do not know for what reason this script does not work in the GitLab CI (works in my local)

"test": "nyc cucumber-js -f node_modules/cucumber-pretty -f json:./test/report/cucumber_report.json --require test/**/*.ts ./test/BDD/**/*.feature",

Instead, I have extracted that configuration in a cucumber.js file

let common = [
  'test/**/*.feature',
  '--require-module ts-node/register',
  '--require test/**/*.ts',
  '--format node_modules/cucumber-pretty',
  '--format json:./test/report/cucumber_report.json'
].join(' ');

module.exports = {
  default: common,
};

And replaced test script by:

"test": "nyc ./node_modules/.bin/cucumber-js -p default",



来源:https://stackoverflow.com/questions/57422245/error-running-node-modules-bin-cucumber-js-in-gitlab-ci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!