摩卡测试重新启动并第二次失败
Mocha Test Restarting and Failing Second Time
我有一个 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。知道为什么它现在可能会崩溃以及为什么它会在最后重新启动吗?
问题是 apiCall url 请求的服务器部分被作为对象覆盖。测试 运行 正确地将其作为字符串,然后立即以服务器作为对象重新启动测试。我仍然不确定为什么更改服务器会使测试重新启动,但我删除了错误的代码行,使其成为一个对象,现在它可以工作了。
我有一个 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。知道为什么它现在可能会崩溃以及为什么它会在最后重新启动吗?
问题是 apiCall url 请求的服务器部分被作为对象覆盖。测试 运行 正确地将其作为字符串,然后立即以服务器作为对象重新启动测试。我仍然不确定为什么更改服务器会使测试重新启动,但我删除了错误的代码行,使其成为一个对象,现在它可以工作了。