Skip to content

Commit

Permalink
test_runner: align behavior of it and test
Browse files Browse the repository at this point in the history
  • Loading branch information
MoLow committed Feb 28, 2023
1 parent a76cb23 commit 220c61d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
4 changes: 2 additions & 2 deletions lib/internal/test_runner/harness.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const {
const { exitCodes: { kGenericUserError } } = internalBinding('errors');

const { kEmptyObject } = require('internal/util');
const { kCancelledByParent, Test, ItTest, Suite } = require('internal/test_runner/test');
const { kCancelledByParent, Test, Suite } = require('internal/test_runner/test');
const {
kAsyncBootstrapFailure,
parseCommandLine,
Expand Down Expand Up @@ -224,7 +224,7 @@ module.exports = {
createTestTree,
test,
describe: runInParentContext(Suite),
it: runInParentContext(ItTest),
it: runInParentContext(Test),
before: hook('before'),
after: hook('after'),
beforeEach: hook('beforeEach'),
Expand Down
8 changes: 0 additions & 8 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,6 @@ class TestHook extends Test {
}
}

class ItTest extends Test {
constructor(opt) { super(opt); } // eslint-disable-line no-useless-constructor
getRunArgs() {
return { ctx: { signal: this.signal, name: this.name }, args: [] };
}
}

class Suite extends Test {
constructor(options) {
super(options);
Expand Down Expand Up @@ -824,7 +817,6 @@ class Suite extends Test {
}

module.exports = {
ItTest,
kCancelledByParent,
kSubtestsFailed,
kTestCodeFailure,
Expand Down
36 changes: 18 additions & 18 deletions test/message/test_runner_describe_it.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ it('async throw fail', async () => {
throw new Error('thrown from async throw fail');
});

it('async skip fail', async (t) => {
it('async skip fail', async (t, done) => {
t.skip();
throw new Error('thrown from async throw fail');
});
Expand Down Expand Up @@ -206,61 +206,61 @@ it('escaped skip message', { skip: '#skip' });
// A test whose todo message needs to be escaped.
it('escaped todo message', { todo: '#todo' });

it('callback pass', (done) => {
it('callback pass', (t, done) => {
setImmediate(done);
});

it('callback fail', (done) => {
it('callback fail', (t, done) => {
setImmediate(() => {
done(new Error('callback failure'));
});
});

it('sync t is this in test', function() {
assert.deepStrictEqual(this, { signal: this.signal, name: this.name });
it('sync t is this in test', function(t) {
assert.strictEqual(this, t);
});

it('async t is this in test', async function() {
assert.deepStrictEqual(this, { signal: this.signal, name: this.name });
it('async t is this in test', async function(t) {
assert.strictEqual(this, t);
});

it('callback t is this in test', function(done) {
assert.deepStrictEqual(this, { signal: this.signal, name: this.name });
it('callback t is this in test', function(t, done) {
assert.strictEqual(this, t);
done();
});

it('callback also returns a Promise', async (done) => {
it('callback also returns a Promise', async (t, done) => {
throw new Error('thrown from callback also returns a Promise');
});

it('callback throw', (done) => {
it('callback throw', (t, done) => {
throw new Error('thrown from callback throw');
});

it('callback called twice', (done) => {
it('callback called twice', (t, done) => {
done();
done();
});

it('callback called twice in different ticks', (done) => {
it('callback called twice in different ticks', (t, done) => {
setImmediate(done);
done();
});

it('callback called twice in future tick', (done) => {
it('callback called twice in future tick', (t, done) => {
setImmediate(() => {
done();
done();
});
});

it('callback async throw', (done) => {
it('callback async throw', (t, done) => {
setImmediate(() => {
throw new Error('thrown from callback async throw');
});
});

it('callback async throw after done', (done) => {
it('callback async throw after done', (t, done) => {
setImmediate(() => {
throw new Error('thrown from callback async throw after done');
});
Expand Down Expand Up @@ -316,7 +316,7 @@ describe('timeouts', () => {
});
});

it('timed out callback test', { timeout: 5 }, (done) => {
it('timed out callback test', { timeout: 5 }, (t, done) => {
setTimeout(done, 100);
});

Expand All @@ -327,7 +327,7 @@ describe('timeouts', () => {
});
});

it('large timeout callback test is ok', { timeout: 30_000_000 }, (done) => {
it('large timeout callback test is ok', { timeout: 30_000_000 }, (t, done) => {
setTimeout(done, 10);
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/message/test_runner_describe_it.out
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ not ok 12 - async throw fail
*
...
# Subtest: async skip fail
not ok 13 - async skip fail
not ok 13 - async skip fail # SKIP
---
duration_ms: *
failureType: 'callbackAndPromisePresent'
Expand Down Expand Up @@ -644,8 +644,8 @@ not ok 60 - invalid subtest fail
# 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.
# tests 60
# pass 23
# fail 23
# fail 22
# cancelled 0
# skipped 9
# skipped 10
# todo 5
# duration_ms *

0 comments on commit 220c61d

Please sign in to comment.