Skip to content

Commit 762dc7c

Browse files
MoLowtargos
authored andcommitted
test_runner: align behavior of it and test
PR-URL: #46889 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 07036cf commit 762dc7c

File tree

6 files changed

+37
-44
lines changed

6 files changed

+37
-44
lines changed

doc/api/test.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ test('skip() method with message', (t) => {
156156
Running tests can also be done using `describe` to declare a suite
157157
and `it` to declare a test.
158158
A suite is used to organize and group related tests together.
159-
`it` is an alias for `test`, except there is no test context passed,
160-
since nesting is done using suites.
159+
`it` is a shorthand for [`test()`][].
161160

162161
```js
163162
describe('A thing', () => {
@@ -841,17 +840,19 @@ Shorthand for marking a suite as `only`, same as
841840

842841
## `it([name][, options][, fn])`
843842

844-
* `name` {string} The name of the test, which is displayed when reporting test
845-
results. **Default:** The `name` property of `fn`, or `'<anonymous>'` if `fn`
846-
does not have a name.
847-
* `options` {Object} Configuration options for the suite.
848-
supports the same options as `test([name][, options][, fn])`.
849-
* `fn` {Function|AsyncFunction} The function under test.
850-
If the test uses callbacks, the callback function is passed as an argument.
851-
**Default:** A no-op function.
852-
* Returns: `undefined`.
843+
<!-- YAML
844+
added:
845+
- v18.6.0
846+
- v16.17.0
847+
changes:
848+
- version: REPLACEME
849+
pr-url: https://github.com/nodejs/node/pull/46889
850+
description: Calling `it()` is now equivalent to calling `test()`.
851+
-->
852+
853+
Shorthand for [`test()`][].
853854

854-
The `it()` function is the value imported from the `node:test` module.
855+
The `it()` function is imported from the `node:test` module.
855856

856857
## `it.skip([name][, options][, fn])`
857858

lib/internal/test_runner/harness.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {
1616
const { exitCodes: { kGenericUserError } } = internalBinding('errors');
1717

1818
const { kEmptyObject } = require('internal/util');
19-
const { kCancelledByParent, Test, ItTest, Suite } = require('internal/test_runner/test');
19+
const { kCancelledByParent, Test, Suite } = require('internal/test_runner/test');
2020
const {
2121
kAsyncBootstrapFailure,
2222
parseCommandLine,
@@ -218,7 +218,7 @@ module.exports = {
218218
createTestTree,
219219
test,
220220
describe: runInParentContext(Suite),
221-
it: runInParentContext(ItTest),
221+
it: runInParentContext(Test),
222222
before: hook('before'),
223223
after: hook('after'),
224224
beforeEach: hook('beforeEach'),

lib/internal/test_runner/test.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -731,13 +731,6 @@ class TestHook extends Test {
731731
}
732732
}
733733

734-
class ItTest extends Test {
735-
constructor(opt) { super(opt); } // eslint-disable-line no-useless-constructor
736-
getRunArgs() {
737-
return { ctx: { signal: this.signal, name: this.name }, args: [] };
738-
}
739-
}
740-
741734
class Suite extends Test {
742735
constructor(options) {
743736
super(options);
@@ -810,7 +803,6 @@ class Suite extends Test {
810803
}
811804

812805
module.exports = {
813-
ItTest,
814806
kCancelledByParent,
815807
kSubtestsFailed,
816808
kTestCodeFailure,

test/es-module/test-esm-repl-imports.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { describe, it } = require('node:test');
99

1010

1111
describe('ESM: REPL runs', { concurrency: true }, () => {
12-
it((done) => {
12+
it((t, done) => {
1313
const child = spawn(execPath, [
1414
'--interactive',
1515
], {

test/message/test_runner_describe_it.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ it('async throw fail', async () => {
4747
throw new Error('thrown from async throw fail');
4848
});
4949

50-
it('async skip fail', async (t) => {
50+
it('async skip fail', async (t, done) => {
5151
t.skip();
5252
throw new Error('thrown from async throw fail');
5353
});
@@ -206,61 +206,61 @@ it('escaped skip message', { skip: '#skip' });
206206
// A test whose todo message needs to be escaped.
207207
it('escaped todo message', { todo: '#todo' });
208208

209-
it('callback pass', (done) => {
209+
it('callback pass', (t, done) => {
210210
setImmediate(done);
211211
});
212212

213-
it('callback fail', (done) => {
213+
it('callback fail', (t, done) => {
214214
setImmediate(() => {
215215
done(new Error('callback failure'));
216216
});
217217
});
218218

219-
it('sync t is this in test', function() {
220-
assert.deepStrictEqual(this, { signal: this.signal, name: this.name });
219+
it('sync t is this in test', function(t) {
220+
assert.strictEqual(this, t);
221221
});
222222

223-
it('async t is this in test', async function() {
224-
assert.deepStrictEqual(this, { signal: this.signal, name: this.name });
223+
it('async t is this in test', async function(t) {
224+
assert.strictEqual(this, t);
225225
});
226226

227-
it('callback t is this in test', function(done) {
228-
assert.deepStrictEqual(this, { signal: this.signal, name: this.name });
227+
it('callback t is this in test', function(t, done) {
228+
assert.strictEqual(this, t);
229229
done();
230230
});
231231

232-
it('callback also returns a Promise', async (done) => {
232+
it('callback also returns a Promise', async (t, done) => {
233233
throw new Error('thrown from callback also returns a Promise');
234234
});
235235

236-
it('callback throw', (done) => {
236+
it('callback throw', (t, done) => {
237237
throw new Error('thrown from callback throw');
238238
});
239239

240-
it('callback called twice', (done) => {
240+
it('callback called twice', (t, done) => {
241241
done();
242242
done();
243243
});
244244

245-
it('callback called twice in different ticks', (done) => {
245+
it('callback called twice in different ticks', (t, done) => {
246246
setImmediate(done);
247247
done();
248248
});
249249

250-
it('callback called twice in future tick', (done) => {
250+
it('callback called twice in future tick', (t, done) => {
251251
setImmediate(() => {
252252
done();
253253
done();
254254
});
255255
});
256256

257-
it('callback async throw', (done) => {
257+
it('callback async throw', (t, done) => {
258258
setImmediate(() => {
259259
throw new Error('thrown from callback async throw');
260260
});
261261
});
262262

263-
it('callback async throw after done', (done) => {
263+
it('callback async throw after done', (t, done) => {
264264
setImmediate(() => {
265265
throw new Error('thrown from callback async throw after done');
266266
});
@@ -316,7 +316,7 @@ describe('timeouts', () => {
316316
});
317317
});
318318

319-
it('timed out callback test', { timeout: 5 }, (done) => {
319+
it('timed out callback test', { timeout: 5 }, (t, done) => {
320320
setTimeout(done, 100);
321321
});
322322

@@ -327,7 +327,7 @@ describe('timeouts', () => {
327327
});
328328
});
329329

330-
it('large timeout callback test is ok', { timeout: 30_000_000 }, (done) => {
330+
it('large timeout callback test is ok', { timeout: 30_000_000 }, (t, done) => {
331331
setTimeout(done, 10);
332332
});
333333
});

test/message/test_runner_describe_it.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ not ok 12 - async throw fail
104104
*
105105
...
106106
# Subtest: async skip fail
107-
not ok 13 - async skip fail
107+
not ok 13 - async skip fail # SKIP
108108
---
109109
duration_ms: *
110110
failureType: 'callbackAndPromisePresent'
@@ -644,8 +644,8 @@ not ok 60 - invalid subtest fail
644644
# Warning: Test "callback async throw after done" generated asynchronous activity after the test ended. This activity created the error "Error: thrown from callback async throw after done" and would have caused the test to fail, but instead triggered an uncaughtException event.
645645
# tests 60
646646
# pass 23
647-
# fail 23
647+
# fail 22
648648
# cancelled 0
649-
# skipped 9
649+
# skipped 10
650650
# todo 5
651651
# duration_ms *

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy