问题
I am trying to setup a jenkins pipeline step to runs some test scenarios using cucumber-js
but I am getting an error back from the build as follows:
Error: Parse error in 'e2e/definitions/login.js': (1:1): expected:
#EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'const { Given, When, Then } = require('cucumber');'
The command being run in the pipeline step is as follows:
cucumber-js e2e/features/**/*.feature --require e2e/**/*.js
The opening lines of the login.js file the error is referencing are:
const { Given, When, Then } = require('cucumber');
const { Selector } = require('testcafe');
I'm wondering if this has something to do with nodejs version differences, as I am running 8.11.2 on my machine and dont see these errors, on Jenkins we are running 10.5.0
Does anyone know what the problem could be and point me in the right direction please?
Thanks
回答1:
Likely you have this problem because the glob pattern specified after the --require
pattern isn't resolved to real file names, but on your Jenkins it does. Try to wrap e2e/**/*.js
in double quotes:
cucumber-js e2e/features/**/*.feature --require "e2e/**/*.js"
回答2:
The error you're getting is a Gherkin parsing error, so I think cucumber is treating your step definition file as a Gherkin file (feature file). I would check which version of cucumber-js you're using locally versus the version that your using in CI. If the versions are different, your CI might be missing a bugfix or it might be using an different version of the CLI.
I also highly recommend setting up your local environment the same way as your CI (same version of node, pinned versions for your npm dependencies), it has saved me a lot of pain.
来源:https://stackoverflow.com/questions/52150612/cucumber-js-parse-error-when-run-on-jenkins