Search code examples
node.jstypescriptnpmgitlab-cicucumberjs

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


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

Solution

  • 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",