首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Mocha测试重新启动并第二次失败

Mocha测试重新启动并第二次失败
EN

Stack Overflow用户
提问于 2018-06-05 23:17:23
回答 1查看 266关注 0票数 0

我有一个用于node.js应用程序接口的mocha测试工具。它在上周停止了工作,当我回到之前的工作版本时,它仍然有一个问题。mocha测试在第一次运行时一直运行,但在结束时会立即重新启动,并且所有测试都会失败。我在测试周围使用了一个异步函数:

代码语言:javascript
复制
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 ---");
});

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

代码语言:javascript
复制
--- 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。你知道为什么它现在可能会崩溃,为什么它会在结束时重新启动吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-08 03:40:46

问题是apiCall的请求url的服务器部分被重写为对象。测试将其作为字符串正确运行,然后立即以服务器作为对象重新启动测试。我仍然不确定为什么更改服务器会使测试重启,但我去掉了错误的代码行,使其成为对象,现在它可以工作了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50703570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档