-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test runner: spurious "Promise resolution is still pending but the event loop has already resolved" when a callback tests fails #51381
Comments
You can just remove test("callback test", () => {
setTimeout(() => {
assert.ok(false, "oh no an assert failed");
});
}); AFAIK const { describe, it } = require("node:test");
const assert = require("node:assert");
const fs = require('node:fs');
describe("describe wrapper", async () => {
it("callback test", (t, done) => {
fs.readFile('package.json', (err, data) => {
if (err) done(err); // will fail with [Error: ENOENT: no such file or directory
else assert.ok(data);
});
}, 0);
}); PRs to improve the documentation are always welcomed |
That doesn't quite work as expected. In that case, the error gets thrown disconnected from any test, so it looks like all tests are passing, but then there's a mysterious Modified script"use strict";
const { describe, test } = require("node:test");
const assert = require("node:assert");
describe("describe wrapper", () => {
test("callback test", () => {
setTimeout(() => {
assert.ok(false, "oh no an assert failed");
});
});
test("promise test", async () => {
assert.ok(true, "this assert will pass");
});
});
describe("another describe block", () => {
test("sync test", () => {
assert.ok(true, "this assert will pass 2");
});
}); Output:
My expectation is that callback tests wait on the callback to be called, or an error to be thrown, in order to tie any thrown errors to the in-progress test. That's how they work in other test frameworks. |
@nodejs/test_runner @MoLow I think in any case the callback test failing shouldn't interfere with any of the other tests. Re: the second example - The "fail the test file for an uncaught error" behavior actually seems reasonable to me. |
I agree with both these statments |
If the test goes in 'uncaughtException' it's not possible to recover, so it will interfere with other test.
I agree with the second statement |
In other test frameworks, the framework is responsible for catching the exception, so it never reaches uncaughtException. |
This seems to fix the issue. The problem is that this never finishes. diff --git a/lib/internal/test_runner/harness.js b/lib/internal/test_runner/harness.js
index 469ca903c7..b62d4dded6 100644
--- a/lib/internal/test_runner/harness.js
+++ b/lib/internal/test_runner/harness.js
@@ -74,7 +74,7 @@ function createProcessEventHandler(eventName, rootTest) {
}
test.fail(new ERR_TEST_FAILURE(err, eventName));
- test.postRun();
+ test.abortController.abort();
};
} It might also be worth considering const { test } = require('node:test');
test({ timeout: 3000 }, (t, done) => {
// done() is not called but there are no ref()'ed handles so we exit.
}); It might also be worth considering setting a reasonable default test timeout instead of Infinity for the same reason. Speaking of test timeouts, the new const { test } = require('node:test');
test((t, done) => {
setTimeout(done, 3000);
}); |
This commit updates the test runner's uncaughtException handler to abort tests instead of assuming they finished running. Fixes: nodejs#51381
This commit updates the test runner's uncaughtException handler to abort tests instead of assuming they finished running. Fixes: nodejs#51381 PR-URL: nodejs#51996 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit updates the test runner's uncaughtException handler to abort tests instead of assuming they finished running. Fixes: nodejs#51381 PR-URL: nodejs#51996 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
I find a similar bug that Node.js test runner works well in Codespaces and throw errors just like this issue in GitHub actions, they are all running in latest Linux + Node.js 20: |
Hey, this issue has been resolved for several months. If you're experiencing an issue, please open a new issue or visit nodejs/help. |
Version
v21.4.0
Platform
Microsoft Windows NT 10.0.22621.0 x64
Subsystem
test
What steps will reproduce the bug?
Run the following code with
node --test test.js
:How often does it reproduce? Is there a required condition?
Always
What is the expected behavior? Why is that the expected behavior?
It should tell me that
"callback test"
alone is failingWhat do you see instead?
It shows four failure messages: one for
callback test
(correct), one fordescribe wrapper
, one forsync test
, and one foranother describe block
. The latter three have a (green??)'Promise resolution is still pending but the event loop has already resolved'
failure reason.Additional information
There isn't a lot of documentation about callback-style tests...
The text was updated successfully, but these errors were encountered: