【问题标题】:cucumber-js parse error when run on Jenkinscucumber-js 在 Jenkins 上运行时解析错误
【发布时间】:2018-09-04 03:39:42
【问题描述】:

我正在尝试设置一个 jenkins 管道步骤以使用 cucumber-js 运行一些测试场景,但我从构建中收到如下错误:

Error: Parse error in 'e2e/definitions/login.js': (1:1): expected:
#EOF, #Language, #TagLine, #FeatureLine, #Comment, #Empty, got 'const { Given, When, Then } = require('cucumber');'

流水线步骤中正在运行的命令如下:

cucumber-js e2e/features/**/*.feature --require e2e/**/*.js

错误引用的 login.js 文件的开头行是:

const { Given, When, Then } = require('cucumber');
const { Selector } = require('testcafe');

我想知道这是否与 nodejs 版本差异有关,因为我在我的机器上运行 8.11.2 并且没有看到这些错误,在 Jenkins 上我们运行的是 10.5.0

有谁知道问题出在哪里,请指出正确的方向?

谢谢

【问题讨论】:

    标签: node.js jenkins jenkins-pipeline cucumberjs testcafe


    【解决方案1】:

    您可能会遇到此问题,因为在 --require 模式之后指定的 glob 模式无法解析为真实文件名,但在您的 Jenkins 上却可以。尝试用双引号将 e2e/**/*.js 括起来: cucumber-js e2e/features/**/*.feature --require "e2e/**/*.js"

    【讨论】:

      【解决方案2】:

      您遇到的错误是 Gherkin 解析错误,因此我认为 cucumber 将您的步骤定义文件视为 Gherkin 文件(功能文件)。我会检查您在本地使用的 cucumber-js 版本与您在 CI 中使用的版本。如果版本不同,您的 CI 可能缺少错误修复,或者它可能使用不同版本的 CLI。

      我还强烈建议您以与 CI 相同的方式设置本地环境(相同版本的节点,为您的 npm 依赖项固定版本),它为我节省了很多痛苦。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-08
        • 2017-10-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多