Skip to content

Commit f87b725

Browse files
committed
feat: first commit flaky
1 parent 8cf1adf commit f87b725

6 files changed

Lines changed: 26 additions & 6 deletions

File tree

lib/internal/test_runner/harness.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ function createTestTree(rootTestOptions, globalOptions) {
6161
failed: 0,
6262
passed: 0,
6363
cancelled: 0,
64+
flaky: 0,
6465
skipped: 0,
6566
todo: 0,
6667
topLevel: 0,
@@ -377,7 +378,7 @@ function runInParentContext(Factory) {
377378

378379
return run(name, options, fn, overrides);
379380
};
380-
ArrayPrototypeForEach(['expectFailure', 'skip', 'todo', 'only'], (keyword) => {
381+
ArrayPrototypeForEach(['expectFailure', 'flaky', 'skip', 'todo', 'only'], (keyword) => {
381382
test[keyword] = (name, options, fn) => {
382383
const overrides = {
383384
__proto__: null,

lib/internal/test_runner/reporter/tap.js

Lines changed: 7 additions & 3 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.expectFailure);
36+
yield reportTest(data.nesting, data.testNumber, 'not ok', data.name, data.skip, data.todo, data.expectFailure, data.flaky);
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.expectFailure);
41+
yield reportTest(data.nesting, data.testNumber, 'ok', data.name, data.skip, data.todo, data.expectFailure, data.flaky);
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, expectFailure) {
68+
function reportTest(nesting, testNumber, status, name, skip, todo, expectFailure, flaky) {
6969
let line = `${indent(nesting)}${status} ${testNumber}`;
7070

7171
if (name) {
@@ -78,6 +78,10 @@ function reportTest(nesting, testNumber, status, name, skip, todo, expectFailure
7878
line += ` # TODO${typeof todo === 'string' && todo.length ? ` ${tapEscape(todo)}` : ''}`;
7979
} else if (expectFailure !== undefined) {
8080
line += ' # EXPECTED FAILURE';
81+
//should we use flaky >=0 here? for always printing 0 retries
82+
} else if (flaky !== undefined && flaky > 0) {
83+
const retryText = flaky === 1 ? 're-try' : 're-tries';
84+
line += ` # FLAKY ${flaky} ${retryText}`;
8185
}
8286

8387
line += '\n';

lib/internal/test_runner/reporter/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ function formatError(error, indent) {
7171
function formatTestReport(type, data, showErrorDetails = true, prefix = '', indent = '') {
7272
let color = reporterColorMap[type] ?? colors.white;
7373
let symbol = reporterUnicodeSymbolMap[type] ?? ' ';
74-
const { skip, todo, expectFailure } = data;
74+
const { skip, todo, expectFailure, flaky } = 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

@@ -87,6 +87,9 @@ function formatTestReport(type, data, showErrorDetails = true, prefix = '', inde
8787
}
8888
} else if (expectFailure !== undefined) {
8989
title += ` # EXPECTED FAILURE`;
90+
} else if (flaky !== undefined && flaky > 0) {
91+
const retryText = flaky === 1 ? 're-try' : 're-tries';
92+
title += ` # FLAKY ${flaky} ${retryText}`;
9093
}
9194

9295
const err = showErrorDetails && data.details?.error ? formatError(data.details.error, indent) : '';

lib/internal/test_runner/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const kTestTimeoutFailure = 'testTimeoutFailure';
8585
const kExpectedFailure = 'expectedFailure';
8686
const kHookFailure = 'hookFailed';
8787
const kDefaultTimeout = null;
88+
const kDefaultFlakyRetries = 20;
8889
const noop = FunctionPrototype;
8990
const kShouldAbort = Symbol('kShouldAbort');
9091
const kHookNames = ObjectSeal(['before', 'after', 'beforeEach', 'afterEach']);
@@ -497,7 +498,8 @@ class Test extends AsyncResource {
497498
super('Test');
498499

499500
let { fn, name, parent } = options;
500-
const { concurrency, entryFile, expectFailure, loc, only, timeout, todo, skip, signal, plan } = options;
501+
502+
const { concurrency, entryFile, expectFailure, flaky, loc, only, timeout, todo, skip, signal, plan } = options;
501503

502504
if (typeof fn !== 'function') {
503505
fn = noop;

lib/internal/test_runner/utils.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ function countCompletedTest(test, harness = test.root.harness) {
401401
} else {
402402
harness.counters.passed++;
403403
}
404+
405+
if (test.flakyRetries > 0) {
406+
harness.counters.flaky++;
407+
}
404408
harness.counters.tests++;
405409
}
406410

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)