摩卡测试重启和第二次失败

时间:2018-06-05 15:17:23

标签: node.js mocha

我有一个node.js api的mocha测试工具。它上周停止工作,当我回到以前的工作版本时,它仍然有问题。 mocha测试在第一次运行时一直运行,但最后它们立即重启并且所有这些都失败了。我正在使用围绕测试的异步函数:

before(function () {
// runs before all tests in this block
console.log("--- Starting Test using node: " + process.version + " --- 
");

//Log in the guest user
var request = {
    "email": guestTestor.email,
    "password": guestTestor.password,
    "deviceId": 'web'
};
var url = server + login;
apiCall(request, url, function callback(status, result) {
    if (status === 200 && result.code === 0) {
        console.log("----- Guest Login Succeeded -----");
        guestTestor.token = result.message.token.id;
    } else {
        console.log("----- Guest Login Failed -----");
        guestTestor.token = "";
    }
});
console.log("--- Setup up completed (asyncs will finish shortly) ---");
});

after(async function () {
// runs after all tests in this block
await dbcontrol.deleteDocument(guestTestor.token);

console.log("--- Clean up completed ---");
});

这是所有测试通过后的输出:

--- Clean up completed ---

  Argis Framework Automated Integration Tests
--- Starting Test using node: v8.11.2 ---
--- Setup up completed (asyncs will finish shortly) ---
    User Creation Process
Error in apiCall:Error: only absolute urls are supported
----- Guest Login Failed -----
Error in apiCall:Error: only absolute urls are supported
----- Admin Login Failed -----
Error in apiCall:Error: only absolute urls are supported
----- Argis Login Failed -----
      Create New User Tests
        4) create user should fail on a bad syntax
        5) create user should fail on user already exists
        6) create user successful awaiting verification
        7) create user successful awaiting verification (for expiration test)
        8) login should fail because the user is not validated
        9) create user should fail because esri identity or password is invalid.
        10) create user should succeed with esri identity as the user created
      Validate New User
(node:7100) UnhandledPromiseRejectionWarning: AssertionError: expected 'get user and verification from database' to equal false
    at C:\Users\Malaika\ArgisAPI\test\testing.js:353:79
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:7100) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:7100) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我尝试过使用不同版本的mocha并使用--exit。任何想法为什么它现在可能会破裂以及为什么它会在最后重新启动?

1 个答案:

答案 0 :(得分:0)

问题是apiCall的请求URL的服务器部分被覆盖为对象。测试以字符串形式正确运行,然后立即以服务器作为对象重新启动测试。我仍然不确定为什么更改服务器会使测试重新启动,但我拿出了错误的代码行,使其成为一个对象,现在可以正常工作。