由于超时,使用babel的CucumberJs测试失败

时间:2016-02-10 16:55:05

标签: node.js babeljs cucumberjs

我有一个用ES6编写的API,使用babel启动,运行没有问题。我使用cucumberJS制作两个场景来测试API的一个路径。我使用ES5开始测试,并运行经典的 ./ node-modules / .bin / cucumber-js

这是我的ES5版本,没有问题

const chai    = require('chai');
const expect  = chai.expect;
const request = require('request').defaults({json: true});
var httpResponse = {};
const API_BASE_URL = 'http://localhost:3000';

module.exports = function () {
    this.When(/^I GET (.*)$/, function(path, callback) {
        request.get(API_BASE_URL + path, function(error, response, body) {
            httpResponse = {error: error, response: response, body: body};
            callback();
        });
    });

    this.Then(/^I should receive a ([1-5][0-9][0-9]) HTTP status code$/, function(statusCode, callback) {
        expect(httpResponse).to.have.property('response');
        expect(httpResponse.response.statusCode).to.equal(parseInt(statusCode));
        callback();
    });
};

2 scenarios (2 passed)
4 steps (4 passed)
0m00.135s

我使用ES6重写了我的测试,并添加了 - 编译器js:babel-registrer 选项

module.exports = function () {
    this.When(/^I GET (.*)$/, (path, callback) => {
        request.get(`${API_BASE_URL}${path}`, (error, response, body) => {
            this.http = { error, response, body };
            callback();
        });
    });

    this.Then(/^I should receive a ([1-5][0-9][0-9]) HTTP status code$/, (statusCode, callback) => {
        expect(this).to.have.property('http');
        expect(this.http.response.statusCode).to.equal(parseInt(statusCode));
        callback();
    });
};

然而,这一次,测试在执行期间失败。当第一个scneario,告诉我有超时。

Scenario: Listing users                        # features/users.feature:5
    Given I GET /users                           # features/step_definitions/api.js:12
      Error: Step timed out after 5000 milliseconds
          at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
    Then I should receive a 200 HTTP status code # features/step_definitions/api.js:20

  Scenario: Getting user                         # features/users.feature:9
    Given I GET /users/1                         # features/step_definitions/api.js:12
    Then I should receive a 200 HTTP status code # features/step_definitions/api.js:20

Failing scenarios:
features/users.feature:5 # Scenario: Listing users

2 scenarios (1 failed, 1 passed)
4 steps (1 failed, 1 skipped, 2 passed)
0m00.310s

有什么建议吗?翻译的babel问题?

0 个答案:

没有答案