-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into ryanm/fix/better-sqlite3
- Loading branch information
Showing
15 changed files
with
1,814 additions
and
1,510 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
interface ReporterTestAttempt { | ||
state: 'skipped' | 'failed' | 'passed' | ||
error: any | ||
timings: any | ||
failedFromHookId: any | ||
wallClockStartedAt: Date | ||
wallClockDuration: number | ||
videoTimestamp: any | ||
} | ||
interface ReporterTest { | ||
testId: string | ||
title: string[] | ||
state: 'skipped' | 'passed' | 'failed' | ||
body: string | ||
displayError: any | ||
attempts: ReporterTestAttempt[] | ||
} | ||
|
||
export interface BaseReporterResults { | ||
error?: string | ||
stats: { | ||
failures: number | ||
tests: number | ||
passes: number | ||
pending: number | ||
suites: number | ||
skipped: number | ||
wallClockDuration: number | ||
wallClockStartedAt: string | ||
wallClockEndedAt: string | ||
} | ||
} | ||
|
||
export interface ReporterResults extends BaseReporterResults { | ||
reporter: string | ||
reporterStats: { | ||
suites: number | ||
tests: number | ||
passes: number | ||
pending: number | ||
failures: number | ||
start: string | ||
end: string | ||
duration: number | ||
} | ||
hooks: any[] | ||
tests: ReporterTest[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import type { ProjectBase } from '../project-base' | ||
import type { BaseReporterResults, ReporterResults } from '../types/reporter' | ||
import * as errors from '../errors' | ||
import Debug from 'debug' | ||
import pDefer, { DeferredPromise } from 'p-defer' | ||
|
||
const debug = Debug('cypress:util:crash_handling') | ||
|
||
const patchRunResultsAfterCrash = (error: Error, reporterResults: ReporterResults, mostRecentRunnable: any): ReporterResults => { | ||
const endTime: number = reporterResults?.stats?.wallClockEndedAt ? Date.parse(reporterResults?.stats?.wallClockEndedAt) : new Date().getTime() | ||
const wallClockDuration = reporterResults?.stats?.wallClockStartedAt ? | ||
endTime - Date.parse(reporterResults.stats.wallClockStartedAt) : 0 | ||
const endTimeStamp = new Date(endTime).toJSON() | ||
|
||
// in crash situations, the most recent report will not have the triggering test | ||
// so the results are manually patched, which produces the expected exit=1 and | ||
// terminal output indicating the failed test | ||
return { | ||
...reporterResults, | ||
stats: { | ||
...reporterResults?.stats, | ||
wallClockEndedAt: endTimeStamp, | ||
wallClockDuration, | ||
failures: (reporterResults?.stats?.failures ?? 0) + 1, | ||
skipped: (reporterResults?.stats?.skipped ?? 1) - 1, | ||
}, | ||
reporterStats: { | ||
...reporterResults?.reporterStats, | ||
tests: (reporterResults?.reporterStats?.tests ?? 0) + 1, // crashed test does not increment this value | ||
end: reporterResults?.reporterStats?.end || endTimeStamp, | ||
duration: wallClockDuration, | ||
failures: (reporterResults?.reporterStats?.failures ?? 0) + 1, | ||
}, | ||
tests: (reporterResults?.tests || []).map((test) => { | ||
if (test.testId === mostRecentRunnable.id) { | ||
return { | ||
...test, | ||
state: 'failed', | ||
attempts: [ | ||
...test.attempts.slice(0, -1), | ||
{ | ||
...test.attempts[test.attempts.length - 1], | ||
state: 'failed', | ||
}, | ||
], | ||
} | ||
} | ||
|
||
return test | ||
}), | ||
error: errors.stripAnsi(error.message), | ||
} | ||
} | ||
|
||
const defaultStats = (error: Error): BaseReporterResults => { | ||
return { | ||
error: errors.stripAnsi(error.message), | ||
stats: { | ||
failures: 1, | ||
tests: 0, | ||
passes: 0, | ||
pending: 0, | ||
suites: 0, | ||
skipped: 0, | ||
wallClockDuration: 0, | ||
wallClockStartedAt: new Date().toJSON(), | ||
wallClockEndedAt: new Date().toJSON(), | ||
}, | ||
} | ||
} | ||
|
||
export class EarlyExitTerminator { | ||
private terminator: DeferredPromise<BaseReporterResults> | ||
|
||
private pendingRunnable: any | ||
private intermediateStats: ReporterResults | undefined | ||
|
||
constructor () { | ||
this.terminator = pDefer<BaseReporterResults>() | ||
} | ||
|
||
waitForEarlyExit (project: ProjectBase, exit?: boolean) { | ||
debug('waiting for early exit') | ||
|
||
project.on('test:before:run', ({ | ||
runnable, | ||
previousResults, | ||
}) => { | ||
debug('preparing to run test, previous stats reported as %O', previousResults) | ||
|
||
this.intermediateStats = previousResults | ||
this.pendingRunnable = runnable | ||
}) | ||
|
||
return this.terminator.promise | ||
} | ||
|
||
exitEarly (error) { | ||
if (error.isFatalApiErr) { | ||
this.terminator.reject(error) | ||
|
||
return | ||
} | ||
|
||
// eslint-disable-next-line no-console | ||
console.log('') | ||
errors.log(error) | ||
|
||
const runResults: BaseReporterResults = (this.intermediateStats && this.pendingRunnable) ? | ||
patchRunResultsAfterCrash(error, this.intermediateStats, this.pendingRunnable) : | ||
defaultStats(error) | ||
|
||
this.terminator.resolve(runResults) | ||
} | ||
} |
Oops, something went wrong.
31fa2ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
31fa2ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
linux arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
31fa2ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
31fa2ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
darwin arm64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally:
31fa2ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Circle has built the
win32 x64
version of the Test Runner.Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version
Run this command to install the pre-release locally: