-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Adding 'before', 'after', 'beforeEach', 'afterEach', functions to the Test Runner #43403
Comments
Yay 🔥 |
Hi @yaircohendev where does this stand? |
Hey @MoLow I wrote the initial code for this but having problems with debugging locally, any chance to setup a quick call about this? |
Sure I assume we are both in Israel so we can work on this together. Ping me |
right now i'm doing it like this "use-strict";
const assert = require("node:assert");
const test = require("node:test");
const { server, app } = require("./app.js");
test("HTTP e2e Stack Testing", async (t) => {
// beforeAll
await t.test("create connection before tests", async () => {
return new Promise((resolve, reject) => {
server.onServerStarted(() => {
resolve();
});
app.start();
});
});
// my tests here
t.test("any testing", () => {
assert.strickEqual(1, 1)
})
// afterAll
server.instance.close();
}); |
But this works in single file. If I use a common source from 2 different files beforeAll doesn't work probably because nodejs runs the files on the fly. They do not wait for each other. Therefore, a global beforeAll and afterAll methods must be provided. Unfortunately, this is a mandatory requirement for memory db connections and http server installations. |
PR-URL: nodejs/node#43730 Fixes: nodejs/node#43403 Reviewed-By: Benjamin Gruenbaum <[email protected]> (cherry picked from commit 659dc126932f986fc33c7f1c878cb2b57a1e2fac)
PR-URL: #43730 Fixes: #43403 Reviewed-By: Benjamin Gruenbaum <[email protected]>
PR-URL: #43730 Fixes: #43403 Reviewed-By: Benjamin Gruenbaum <[email protected]>
PR-URL: #43730 Fixes: #43403 Reviewed-By: Benjamin Gruenbaum <[email protected]>
PR-URL: nodejs#43730 Fixes: nodejs#43403 Reviewed-By: Benjamin Gruenbaum <[email protected]>
PR-URL: #43730 Fixes: #43403 Reviewed-By: Benjamin Gruenbaum <[email protected]>
PR-URL: #43730 Fixes: #43403 Reviewed-By: Benjamin Gruenbaum <[email protected]>
PR-URL: nodejs/node#43730 Fixes: nodejs/node#43403 Reviewed-By: Benjamin Gruenbaum <[email protected]>
PR-URL: nodejs/node#43730 Fixes: nodejs/node#43403 Reviewed-By: Benjamin Gruenbaum <[email protected]>
any update about this? |
@SynLocker this exists in node18 and above |
Is it expected that these run regardless of if the test is skipped? So if a test is being skipped the 'beforeEach' call still runs before that test is officially skipped. |
Illustrating the question from @isaacgr The code below is green with node
|
beforeEach and afterEach should not run for skipped tests. I believe it's a bug. test1 fails with assert message:
while expected
test itself: const { beforeEach, test, afterEach } = require('node:test');
const assert = require('node:assert');
const log = [];
beforeEach((sc) => {
log.push(`beforeEach for '${sc.name}'`);
});
test.skip('test0 WILL NOT/HAS NOT RUN', (sc) => {
log.push(`it ${sc.name}`); //as expected it didn't run
});
test('test1', (sc) => {
log.push(`it ${sc.name}`);
assert.equal(log.length, 2, "call log:\n >> " + log.join('\n >> '));
});
afterEach((sc) => {
log.push(`afterEach for '${sc.name}'`);
}); Node v20.10.0. Same thing happens within @benjamingr, @MoLow, any comments? It it expected behaviour? Should I open a new issue or can this one be reopened? |
@listvin This seems to be fixed now. |
What is the problem this feature will solve?
Ability to write preparation and cleanup code
What is the feature you are proposing to solve the problem?
Hey,
I'd like to work on adding
before
,after
,beforeEach
,afterEach
functions to the test runner.@benjamingr
@cjihrig
What alternatives have you considered?
No response
The text was updated successfully, but these errors were encountered: