CucumberJS脚本错误

时间:2018-03-29 12:25:42

标签: javascript react-native cucumberjs

我是cucumber的新手,所以我不知道我的问题是源于缺乏理解,还是因为脚本实际上是一个错误(我不太想到)。所以,我只会谈谈正在发生的事情。通常,当我运行cucumber时,我会获得功能/方案输出,但脚本会在执行后期抛出错误。我读到这可能是由于我的featuresteps_definition文件中的错误造成的,但我不知道该寻找什么。

我已将软件包安装为依赖项

  "dependencies": {
    "cucumber": "^4.0.0",
    "react": "^16.3.0-alpha.1",
    "react-native": "0.54.1",
    "react-native-cli": "^2.0.1"
  }

并设置在我的scripts对象

  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "jest": "jest",
    "cucumber": "cucumber-js",
    "gjest": "gherkin-jest",
    "jestc": "jest-cucumber"
  }

我的功能文件(位于/features)内写着:

Feature: Create a new member account
  As a new member
  I want to create a member account

Scenario: Create a new user
  When I create a new user with details:
    | Username | mstelly              |
    | Email    | my.email@example.com |
    | Password | mySecretPassword     |
  Then the user is created successfully

我的step_definitions文件(位于/features/step_definitions)读取:

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

    When('I create a new user with details:', function(table) {
      const data = table.rowsHash();
      JSON.stringify(data);
    });

    Then('the user is created successfully', function() {
      // Write code here that turns the phrase above into concrete actions
      return 'pending';
    });

当我执行脚本:npm run cucumber features -r step_definitions/时,我收到以下控制台输出:

> mobile_gtm@0.0.1 cucumber /Users/michaelstelly/Documents/projects/mobile_gtm
> cucumber-js "features" "step_definitions/"

.P

Warnings:

1) Scenario: Create a new user # features/accountCreate.feature:5
   ✔ When I create a new user with details: # features/step_definitions/accountCreate.steps.js:4
       | Username | mstelly              |
       | Email    | my.email@example.com |
       | Password | mySecretPassword     |
   ? Then the user is created successfully # features/step_definitions/accountCreate.steps.js:9
       Pending

1 scenario (1 pending)
2 steps (1 pending, 1 passed)
0m00.001s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! mobile_gtm@0.0.1 cucumber: `cucumber-js "features" "step_definitions/"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mobile_gtm@0.0.1 cucumber script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/michaelstelly/.npm/_logs/2018-03-29T11_57_24_218Z-debug.log

这就是我所拥有的所有信息。我收到黄瓜输出,但后来我得到npm错误。它们可能与黄瓜无关,但在这一点上,我无法确定。

帮助表示赞赏。如果您有任何疑问,请询问。

1 个答案:

答案 0 :(得分:0)

我认为这应该发生。 https://github.com/cucumber/cucumber-js/issues/843#issuecomment-305331023

如果有任何未定义/挂起/失败/模棱两可的步骤,

cucumber-js将以状态1退出。如果所有步骤都通过,它将以状态0退出。

我知道这个问题很旧,但是我遇到了这个问题,试图找到我自己的问题的答案,希望这对未来有帮助。