mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
test_runner: support expecting a test-case to fail
Co-Authored-By: Alejandro Espa <98526766+vespa7@users.noreply.github.com> PR-URL: https://github.com/nodejs/node/pull/60669 Reviewed-By: Aviv Keller <me@aviv.sh> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
1 parent
3f17acfb1c
commit
ff1fcabfc9
22 files changed
+806
-493
No files matched your search
@@ -377,7 +377,7 @@ function runInParentContext(Factory) {
|
||||
|
||||
return run(name, options, fn, overrides);
|
||||
};
|
||||
ArrayPrototypeForEach(['skip', 'todo', 'only'], (keyword) => {
|
||||
ArrayPrototypeForEach(['expectFailure', 'skip', 'todo', 'only'], (keyword) => {
|
||||
test[keyword] = (name, options, fn) => {
|
||||
const overrides = {
|
||||
__proto__: null,
|
||||
|
||||
@@ -33,12 +33,12 @@ async function * tapReporter(source) {
|
||||
for await (const { type, data } of source) {
|
||||
switch (type) {
|
||||
case 'test:fail': {
|
||||
yield reportTest(data.nesting, data.testNumber, 'not ok', data.name, data.skip, data.todo);
|
||||
yield reportTest(data.nesting, data.testNumber, 'not ok', data.name, data.skip, data.todo, data.expectFailure);
|
||||
const location = data.file ? `${data.file}:${data.line}:${data.column}` : null;
|
||||
yield reportDetails(data.nesting, data.details, location);
|
||||
break;
|
||||
} case 'test:pass':
|
||||
yield reportTest(data.nesting, data.testNumber, 'ok', data.name, data.skip, data.todo);
|
||||
yield reportTest(data.nesting, data.testNumber, 'ok', data.name, data.skip, data.todo, data.expectFailure);
|
||||
yield reportDetails(data.nesting, data.details, null);
|
||||
break;
|
||||
case 'test:plan':
|
||||
@@ -65,7 +65,7 @@ async function * tapReporter(source) {
|
||||
}
|
||||
}
|
||||
|
||||
function reportTest(nesting, testNumber, status, name, skip, todo) {
|
||||
function reportTest(nesting, testNumber, status, name, skip, todo, expectFailure) {
|
||||
let line = `${indent(nesting)}${status} ${testNumber}`;
|
||||
|
||||
if (name) {
|
||||
@@ -76,6 +76,8 @@ function reportTest(nesting, testNumber, status, name, skip, todo) {
|
||||
line += ` # SKIP${typeof skip === 'string' && skip.length ? ` ${tapEscape(skip)}` : ''}`;
|
||||
} else if (todo !== undefined) {
|
||||
line += ` # TODO${typeof todo === 'string' && todo.length ? ` ${tapEscape(todo)}` : ''}`;
|
||||
} else if (expectFailure !== undefined) {
|
||||
line += ' # EXPECTED FAILURE';
|
||||
}
|
||||
|
||||
line += '\n';
|
||||
|
||||
@@ -71,7 +71,7 @@ function formatError(error, indent) {
|
||||
function formatTestReport(type, data, prefix = '', indent = '', hasChildren = false, showErrorDetails = true) {
|
||||
let color = reporterColorMap[type] ?? colors.white;
|
||||
let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
|
||||
const { skip, todo } = data;
|
||||
const { skip, todo, expectFailure } = data;
|
||||
const duration_ms = data.details?.duration_ms ? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}` : '';
|
||||
let title = `${data.name}${duration_ms}`;
|
||||
|
||||
@@ -79,6 +79,8 @@ function formatTestReport(type, data, prefix = '', indent = '', hasChildren = fa
|
||||
title += ` # ${typeof skip === 'string' && skip.length ? skip : 'SKIP'}`;
|
||||
} else if (todo !== undefined) {
|
||||
title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`;
|
||||
} else if (expectFailure !== undefined) {
|
||||
title += ` # EXPECTED FAILURE`;
|
||||
}
|
||||
|
||||
const error = showErrorDetails ? formatError(data.details?.error, indent) : '';
|
||||
|
||||
@@ -496,7 +496,7 @@ class Test extends AsyncResource {
|
||||
super('Test');
|
||||
|
||||
let { fn, name, parent } = options;
|
||||
const { concurrency, entryFile, loc, only, timeout, todo, skip, signal, plan } = options;
|
||||
const { concurrency, entryFile, expectFailure, loc, only, timeout, todo, skip, signal, plan } = options;
|
||||
|
||||
if (typeof fn !== 'function') {
|
||||
fn = noop;
|
||||
@@ -635,6 +635,7 @@ class Test extends AsyncResource {
|
||||
this.plan = null;
|
||||
this.expectedAssertions = plan;
|
||||
this.cancelled = false;
|
||||
this.expectFailure = expectFailure !== undefined && expectFailure !== false;
|
||||
this.skipped = skip !== undefined && skip !== false;
|
||||
this.isTodo = (todo !== undefined && todo !== false) || this.parent?.isTodo;
|
||||
this.startTime = null;
|
||||
@@ -938,7 +939,12 @@ class Test extends AsyncResource {
|
||||
return;
|
||||
}
|
||||
|
||||
this.passed = false;
|
||||
if (this.expectFailure === true) {
|
||||
this.passed = true;
|
||||
} else {
|
||||
this.passed = false;
|
||||
}
|
||||
|
||||
this.error = err;
|
||||
}
|
||||
|
||||
@@ -1335,6 +1341,8 @@ class Test extends AsyncResource {
|
||||
directive = this.reporter.getSkip(this.message);
|
||||
} else if (this.isTodo) {
|
||||
directive = this.reporter.getTodo(this.message);
|
||||
} else if (this.expectFailure) {
|
||||
directive = this.reporter.getXFail(this.expectFailure); // TODO(@JakobJingleheimer): support specifying failure
|
||||
}
|
||||
|
||||
if (this.reportedType) {
|
||||
@@ -1349,6 +1357,7 @@ class Test extends AsyncResource {
|
||||
if (this.passedAttempt !== undefined) {
|
||||
details.passed_on_attempt = this.passedAttempt;
|
||||
}
|
||||
|
||||
return { __proto__: null, details, directive };
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,10 @@ class TestsStream extends Readable {
|
||||
return { __proto__: null, todo: reason ?? true };
|
||||
}
|
||||
|
||||
getXFail(expectation = undefined) {
|
||||
return { __proto__: null, expectFailure: expectation ?? true };
|
||||
}
|
||||
|
||||
enqueue(nesting, loc, name, type) {
|
||||
this[kEmitMessage]('test:enqueue', {
|
||||
__proto__: null,
|
||||
|
||||
Reference in new issue
Block a user