Skip to content
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

Allow overriding of looks-same options #27

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
22 changes: 7 additions & 15 deletions screenshot_helper/screenshot_helper.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import * as fs from 'fs';
import * as os from 'os';
import * as path from 'path';
import * as looksSame from 'looks-same';

import { browser, ElementFinder, WebElement } from 'protractor';

let mask_fn = require('./mask').MASK_FN;

/*
* Create shim for LooksSame typing.
*/
export interface LooksSame {
(img1: string, img2: string, options: Object, check: (error: any, equal: any) => void);
(img1: string, img2: string, check: (error: any, equal: any) => void);
createDiff(options: Object, err: Function);
}

// Require looks-same casted with shim interface LooksSame typing.
let looksSame: LooksSame = require('looks-same');

/**
* Compare a screenshot to a reference, or "golden" image.
* Returns a Promise that resolves to whether or not the
Expand All @@ -32,7 +21,7 @@ let looksSame: LooksSame = require('looks-same');

* saved.
*/
export async function compareScreenshot(data, golden, outputFolder = undefined): Promise<string> {
export async function compareScreenshot(data, golden, outputFolder = undefined, looksSameOptions: looksSame.LooksSameOptions = {}): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
const tempFolder = createTempFolder();
const screenshotPath = await writeScreenshot(tempFolder, data);
Expand All @@ -45,8 +34,11 @@ export async function compareScreenshot(data, golden, outputFolder = undefined):
}
const goldenName = path.basename(golden);
looksSame(screenshotPath, golden, {
strict: false,
tolerance: 2.5,
...{
strict: false,
tolerance: 2.5,
},
...looksSameOptions,
}, async (error, equal) => {
if (error) {
reject("There has been an error. Error: " + error);
Expand Down