Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/reporters/VisualRegression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ export default class VisualRegression {
*/
private reportLocation: string;

/**
* Only display visual regressions in the report
*/
private onlyReportErrors: boolean;

/**
* Prefix the test name in the report with the parent test suite names
*/
private prefixTestName: boolean;

/**
* Notes exported to index.html
* @private
Expand All @@ -41,6 +51,9 @@ export default class VisualRegression {

this.errorColor = getRGBA(options.errorColor || '#F00')!;

this.onlyReportErrors = options.onlyReportErrors || false;
this.prefixTestName = options.prefixTestName || false;

executor.on('deprecated', message => this.deprecated(message));
executor.on('error', error => this.error(error));
executor.on('suiteEnd', suite => <Promise<void>>this.suiteEnd(suite));
Expand Down Expand Up @@ -114,10 +127,14 @@ export default class VisualRegression {
return Promise.resolve();
}

const results: AssertionResult[] = test.visualResults!;
let results: AssertionResult[] = test.visualResults!;
const testDirectory = getTestDirectory(test.parent);
const directory = join(this.reportLocation, testDirectory);

if (this.onlyReportErrors) {
results = results.filter((result) => result.report && !result.report.isPassing);
}

return Promise.all(
results.map(result => {
const report = result.report;
Expand Down Expand Up @@ -280,13 +297,19 @@ export default class VisualRegression {
}

private createComparisonHeader(test: Test) {
let label = test.name;
if (this.prefixTestName) {
let testDirectory = getTestDirectory(test.parent);
label = join(testDirectory, label);
}

const result = test.skipped
? 'skiped'
: test.hasPassed
? 'passed'
: 'failed';
return `
<header class="${result}">${test.name}</header>
<header class="${result}">${label}</header>
`;
}

Expand Down Expand Up @@ -340,6 +363,16 @@ export interface Options {
* 'report'.
*/
reportLocation?: string;

/**
* Only display visual regressions in the report
*/
onlyReportErrors?: boolean;

/**
* Prefix the test name in the report with the parent test suite names
*/
prefixTestName?: boolean;
}

export interface Note {
Expand Down