Skip to content
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

doc, test: clarify the behavior of todo tests #52204

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,37 @@ test('skip() method with message', (t) => {
});
```

## TODO tests

Individual tests can be marked as flaky or incomplete by passing the `todo`
option to the test, or by calling the test context's `todo()` method, as shown
in the following example. These tests represent a pending implementation or bug
that needs to be fixed. TODO tests are executed, but are not treated as test
failures, and therefore do not affect the process exit code. If a test is marked
as both TODO and skipped, the TODO option is ignored.

```js
// The todo option is used, but no message is provided.
test('todo option', { todo: true }, (t) => {
// This code is executed, but not treated as a failure.
throw new Error('this does not fail the test');
});

// The todo option is used, and a message is provided.
test('todo option with message', { todo: 'this is a todo test' }, (t) => {
// This code is executed.
});

test('todo() method', (t) => {
t.todo();
});

test('todo() method with message', (t) => {
t.todo('this is a todo test and is not treated as a failure');
throw new Error('this does not fail the test');
});
```

## `describe()` and `it()` aliases

Suites and tests can also be written using the `describe()` and `it()`
Expand Down
32 changes: 32 additions & 0 deletions test/parallel/test-runner-todo-skip-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
const common = require('../common');
const { strictEqual } = require('node:assert');
const { run, suite, test } = require('node:test');

if (!process.env.NODE_TEST_CONTEXT) {
const stream = run({ files: [__filename] });

stream.on('test:fail', common.mustNotCall());
stream.on('test:pass', common.mustCall((event) => {
strictEqual(event.skip, true);
strictEqual(event.todo, undefined);
}, 4));
} else {
test('test options only', { skip: true, todo: true }, common.mustNotCall());

test('test context calls only', common.mustCall((t) => {
t.todo();
t.skip();
}));

test('todo test with context skip', { todo: true }, common.mustCall((t) => {
t.skip();
}));

// Note - there is no test for the skip option and t.todo() because the skip
// option prevents the test from running at all. This is verified by other
// tests.

// Suites don't have the context methods, so only test the options combination.
suite('suite options only', { skip: true, todo: true }, common.mustNotCall());
}