Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.4k
test-runner: add option to rerun only failed tests#59443
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| 'use strict'; | ||
| const { | ||
| ArrayPrototypePush, | ||
| JSONStringify, | ||
| } = primordials; | ||
| const { relative } = require('path'); | ||
| const { writeFileSync } = require('fs'); | ||
| function reportReruns(previousRuns, globalOptions) { | ||
| return async function reporter(source) { | ||
| const obj = { __proto__: null }; | ||
| const disambiguator = { __proto__: null }; | ||
| for await (const { type, data } of source) { | ||
| if (type === 'test:pass') { | ||
| let identifier = `${relative(globalOptions.cwd, data.file)}:${data.line}:${data.column}`; | ||
| if (disambiguator[identifier] !== undefined) { | ||
| identifier += `:(${disambiguator[identifier]})`; | ||
| disambiguator[identifier] += 1; | ||
| } else { | ||
| disambiguator[identifier] = 1; | ||
| } | ||
| obj[identifier] = { | ||
| __proto__: null, | ||
| name: data.name, | ||
| passed_on_attempt: data.details.passed_on_attempt ?? data.details.attempt, | ||
| }; | ||
| } | ||
| } | ||
| ArrayPrototypePush(previousRuns, obj); | ||
| writeFileSync(globalOptions.rerunFailuresFilePath, JSONStringify(previousRuns, null, 2), 'utf8'); | ||
| }; | ||
| }; | ||
| module.exports = { | ||
| __proto__: null, | ||
| reportReruns, | ||
MoLow marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -71,6 +71,7 @@ const { | ||
| } = require('timers'); | ||
| const { TIMEOUT_MAX } = require('internal/timers'); | ||
| const { fileURLToPath } = require('internal/url'); | ||
| const { relative } = require('path'); | ||
| const { availableParallelism } = require('os'); | ||
| const { innerOk } = require('internal/assert/utils'); | ||
| const { bigint: hrtime } = process.hrtime; | ||
| @@ -290,6 +291,10 @@ class TestContext { | ||
| return this.#test.passed; | ||
| } | ||
| get attempt() { | ||
| return this.#test.attempt ?? 0; | ||
| } | ||
| diagnostic(message) { | ||
| this.#test.diagnostic(message); | ||
| } | ||
| @@ -537,6 +542,7 @@ class Test extends AsyncResource { | ||
| this.childNumber = 0; | ||
| this.timeout = kDefaultTimeout; | ||
| this.entryFile = entryFile; | ||
| this.testDisambiguator = new SafeMap(); | ||
| } else { | ||
| const nesting = parent.parent === null ? parent.nesting : | ||
| parent.nesting + 1; | ||
| @@ -646,6 +652,8 @@ class Test extends AsyncResource { | ||
| this.endTime = null; | ||
| this.passed = false; | ||
| this.error = null; | ||
| this.attempt = undefined; | ||
| this.passedAttempt = undefined; | ||
| this.message = typeof skip === 'string' ? skip : | ||
| typeof todo === 'string' ? todo : null; | ||
| this.activeSubtests = 0; | ||
| @@ -690,6 +698,23 @@ class Test extends AsyncResource { | ||
| this.loc.file = fileURLToPath(this.loc.file); | ||
| } | ||
| } | ||
| if (this.loc != null && this.root.harness.previousRuns != null) { | ||
| let testIdentifier = `${relative(this.config.cwd, this.loc.file)}:${this.loc.line}:${this.loc.column}`; | ||
| const disambiguator = this.root.testDisambiguator.get(testIdentifier); | ||
| if (disambiguator !== undefined) { | ||
| testIdentifier += `:(${disambiguator})`; | ||
| this.root.testDisambiguator.set(testIdentifier, disambiguator + 1); | ||
MoLow marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| } else { | ||
| this.root.testDisambiguator.set(testIdentifier, 1); | ||
| } | ||
| this.attempt = this.root.harness.previousRuns.length; | ||
| const previousAttempt = this.root.harness.previousRuns[this.attempt - 1]?.[testIdentifier]?.passed_on_attempt; | ||
| if (previousAttempt != null) { | ||
| this.passedAttempt = previousAttempt; | ||
| this.fn = noop; | ||
| } | ||
| } | ||
| } | ||
| applyFilters() { | ||
| @@ -1329,6 +1354,12 @@ class Test extends AsyncResource { | ||
| if (!this.passed) { | ||
| details.error = this.error; | ||
| } | ||
| if (this.attempt !== undefined) { | ||
| details.attempt = this.attempt; | ||
| } | ||
| if (this.passedAttempt !== undefined) { | ||
| details.passed_on_attempt = this.passedAttempt; | ||
| } | ||
| return { __proto__: null, details, directive }; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.