Skip to content

Commit 1c88cd4

Browse files
fixup!: xfailexpectFailure
1 parent ea2f54c commit 1c88cd4

File tree

8 files changed

+33
-33
lines changed

8 files changed

+33
-33
lines changed

doc/api/test.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,39 +238,39 @@ In the following, `doTheThing()` returns _currently_ `false` (`false` does not e
238238
`strictEqual` to throw, so the test-case passes).
239239

240240
```js
241-
it.xfail('should do the thing', () => {
241+
it.expectFailure('should do the thing', () => {
242242
assert.strictEqual(doTheThing(), true);
243243
});
244244

245-
it('should do the thing', { xfail: true }, () => {
245+
it('should do the thing', { expectFailure: true }, () => {
246246
assert.strictEqual(doTheThing(), true);
247247
});
248248
```
249249

250-
`skip` and/or `todo` are mutually exclusive to `xfail`, and `skip` or `todo`
250+
`skip` and/or `todo` are mutually exclusive to `expectFailure`, and `skip` or `todo`
251251
will "win" when both are applied (`skip` wins against both, and `todo` wins
252-
against `xfail`).
252+
against `expectFailure`).
253253

254254
These tests will be skipped (and not run):
255255

256256
```js
257-
it.xfail('should do the thing', { skip: true }, () => {
257+
it.expectFailure('should do the thing', { skip: true }, () => {
258258
assert.strictEqual(doTheThing(), true);
259259
});
260260

261-
it.skip('should do the thing', { xfail: true }, () => {
261+
it.skip('should do the thing', { expectFailure: true }, () => {
262262
assert.strictEqual(doTheThing(), true);
263263
});
264264
```
265265

266266
These tests will be marked "todo" (silencing errors):
267267

268268
```js
269-
it.xfail('should do the thing', { todo: true }, () => {
269+
it.expectFailure('should do the thing', { todo: true }, () => {
270270
assert.strictEqual(doTheThing(), true);
271271
});
272272

273-
it.todo('should do the thing', { xfail: true }, () => {
273+
it.todo('should do the thing', { expectFailure: true }, () => {
274274
assert.strictEqual(doTheThing(), true);
275275
});
276276
```

lib/internal/test_runner/harness.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ function runInParentContext(Factory) {
377377

378378
return run(name, options, fn, overrides);
379379
};
380-
ArrayPrototypeForEach(['xfail', 'skip', 'todo', 'only'], (keyword) => {
380+
ArrayPrototypeForEach(['expectFailure', 'skip', 'todo', 'only'], (keyword) => {
381381
test[keyword] = (name, options, fn) => {
382382
const overrides = {
383383
__proto__: null,

lib/internal/test_runner/reporter/tap.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ async function * tapReporter(source) {
3333
for await (const { type, data } of source) {
3434
switch (type) {
3535
case 'test:fail': {
36-
yield reportTest(data.nesting, data.testNumber, 'not ok', data.name, data.skip, data.todo, data.xfail);
36+
yield reportTest(data.nesting, data.testNumber, 'not ok', data.name, data.skip, data.todo, data.expectFailure);
3737
const location = data.file ? `${data.file}:${data.line}:${data.column}` : null;
3838
yield reportDetails(data.nesting, data.details, location);
3939
break;
4040
} case 'test:pass':
41-
yield reportTest(data.nesting, data.testNumber, 'ok', data.name, data.skip, data.todo, data.xfail);
41+
yield reportTest(data.nesting, data.testNumber, 'ok', data.name, data.skip, data.todo, data.expectFailure);
4242
yield reportDetails(data.nesting, data.details, null);
4343
break;
4444
case 'test:plan':
@@ -65,7 +65,7 @@ async function * tapReporter(source) {
6565
}
6666
}
6767

68-
function reportTest(nesting, testNumber, status, name, skip, todo, xfail) {
68+
function reportTest(nesting, testNumber, status, name, skip, todo, expectFailure) {
6969
let line = `${indent(nesting)}${status} ${testNumber}`;
7070

7171
if (name) {
@@ -76,7 +76,7 @@ function reportTest(nesting, testNumber, status, name, skip, todo, xfail) {
7676
line += ` # SKIP${typeof skip === 'string' && skip.length ? ` ${tapEscape(skip)}` : ''}`;
7777
} else if (todo !== undefined) {
7878
line += ` # TODO${typeof todo === 'string' && todo.length ? ` ${tapEscape(todo)}` : ''}`;
79-
} else if (xfail !== undefined) {
79+
} else if (expectFailure !== undefined) {
8080
line += ' # EXPECTED FAILURE';
8181
}
8282

lib/internal/test_runner/reporter/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ function formatError(error, indent) {
7171
function formatTestReport(type, data, prefix = '', indent = '', hasChildren = false, showErrorDetails = true) {
7272
let color = reporterColorMap[type] ?? colors.white;
7373
let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
74-
const { skip, todo, xfail } = data;
74+
const { skip, todo, expectFailure } = data;
7575
const duration_ms = data.details?.duration_ms ? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}` : '';
7676
let title = `${data.name}${duration_ms}`;
7777

7878
if (skip !== undefined) {
7979
title += ` # ${typeof skip === 'string' && skip.length ? skip : 'SKIP'}`;
8080
} else if (todo !== undefined) {
8181
title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
82-
} else if (xfail !== undefined) {
82+
} else if (expectFailure !== undefined) {
8383
title += ` # EXPECTED FAILURE`;
8484
}
8585

lib/internal/test_runner/test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ class Test extends AsyncResource {
496496
super('Test');
497497

498498
let { fn, name, parent } = options;
499-
const { concurrency, entryFile, xfail, loc, only, timeout, todo, skip, signal, plan } = options;
499+
const { concurrency, entryFile, expectFailure, loc, only, timeout, todo, skip, signal, plan } = options;
500500

501501
if (typeof fn !== 'function') {
502502
fn = noop;
@@ -635,7 +635,7 @@ class Test extends AsyncResource {
635635
this.plan = null;
636636
this.expectedAssertions = plan;
637637
this.cancelled = false;
638-
this.xfail = xfail !== undefined && xfail !== false;
638+
this.expectFailure = expectFailure !== undefined && expectFailure !== false;
639639
this.skipped = skip !== undefined && skip !== false;
640640
this.isTodo = (todo !== undefined && todo !== false) || this.parent?.isTodo;
641641
this.startTime = null;
@@ -939,7 +939,7 @@ class Test extends AsyncResource {
939939
return;
940940
}
941941

942-
if (this.xfail === true) {
942+
if (this.expectFailure === true) {
943943
this.passed = true;
944944
} else {
945945
this.passed = false;
@@ -1341,8 +1341,8 @@ class Test extends AsyncResource {
13411341
directive = this.reporter.getSkip(this.message);
13421342
} else if (this.isTodo) {
13431343
directive = this.reporter.getTodo(this.message);
1344-
} else if (this.xfail) {
1345-
directive = this.reporter.getXFail(this.xfail); // TODO(@JakobJingleheimer): support specifying failure
1344+
} else if (this.expectFailure) {
1345+
directive = this.reporter.getXFail(this.expectFailure); // TODO(@JakobJingleheimer): support specifying failure
13461346
}
13471347

13481348
if (this.reportedType) {

lib/internal/test_runner/tests_stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class TestsStream extends Readable {
8888
}
8989

9090
getXFail(expectation = undefined) {
91-
return { __proto__: null, xfail: expectation ?? true };
91+
return { __proto__: null, expectFailure: expectation ?? true };
9292
}
9393

9494
enqueue(nesting, loc, name, type) {

test/fixtures/test-runner/output/describe_it.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ const { describe, it, test } = require('node:test');
55
const util = require('util');
66

77

8-
it.xfail('sync expect fail (method)', () => {
8+
it.expectFailure('sync expect fail (method)', () => {
99
throw new Error('should pass');
1010
});
1111

12-
it('sync expect fail (options)', { xfail: true }, () => {
12+
it('sync expect fail (options)', { expectFailure: true }, () => {
1313
throw new Error('should pass');
1414
});
1515

16-
it.xfail('async expect fail (method)', async () => {
16+
it.expectFailure('async expect fail (method)', async () => {
1717
throw new Error('should pass');
1818
});
1919

20-
it('async expect fail (options)', { xfail: true }, async () => {
20+
it('async expect fail (options)', { expectFailure: true }, async () => {
2121
throw new Error('should pass');
2222
});
2323

@@ -31,7 +31,7 @@ it.todo('sync todo', () => {
3131
throw new Error('should not count as a failure');
3232
});
3333

34-
it.todo('sync todo with expect fail', { xfail: true }, () => {
34+
it.todo('sync todo with expect fail', { expectFailure: true }, () => {
3535
throw new Error('should not count as an expected failure');
3636
});
3737

@@ -42,7 +42,7 @@ it('sync todo with message', { todo: 'this is a failing todo' }, () => {
4242
it.skip('sync skip pass', () => {
4343
});
4444

45-
it.skip('sync skip expect fail', { xfail: true }, () => {
45+
it.skip('sync skip expect fail', { expectFailure: true }, () => {
4646
throw new Error('should not fail');
4747
});
4848

test/fixtures/test-runner/output/output.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,27 @@ const assert = require('node:assert');
55
const test = require('node:test');
66
const util = require('util');
77

8-
test.xfail('sync expect fail (method)', () => {
8+
test.expectFailure('sync expect fail (method)', () => {
99
throw new Error('should pass');
1010
});
1111

12-
test('sync expect fail (options)', { xfail: true }, () => {
12+
test('sync expect fail (options)', { expectFailure: true }, () => {
1313
throw new Error('should pass');
1414
});
1515

16-
test.xfail('async expect fail (method)', async () => {
16+
test.expectFailure('async expect fail (method)', async () => {
1717
throw new Error('should pass');
1818
});
1919

20-
test('async expect fail (options)', { xfail: true }, async () => {
20+
test('async expect fail (options)', { expectFailure: true }, async () => {
2121
throw new Error('should pass');
2222
});
2323

24-
test.todo('sync todo with expect fail', { xfail: true }, () => {
24+
test.todo('sync todo with expect fail', { expectFailure: true }, () => {
2525
throw new Error('should not count as an expected failure');
2626
});
2727

28-
test.skip('sync skip expect fail', { xfail: true }, () => {
28+
test.skip('sync skip expect fail', { expectFailure: true }, () => {
2929
throw new Error('should not fail');
3030
});
3131

0 commit comments

Comments
 (0)