diff --git a/types/jest-image-snapshot/index.d.ts b/types/jest-image-snapshot/index.d.ts index 5f83e5cffab4bf..a85aa6c7b51900 100644 --- a/types/jest-image-snapshot/index.d.ts +++ b/types/jest-image-snapshot/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for jest-image-snapshot 4.1 +// Type definitions for jest-image-snapshot 4.3 // Project: https://github.com/americanexpress/jest-image-snapshot#readme // Definitions by: Janeene Beeforth // erbridge @@ -59,6 +59,12 @@ export interface MatchImageSnapshotOptions { * @default false */ dumpDiffToConsole?: boolean; + /** + * Will output the image to the terminal using iTerm's Inline Images Protocol. + * If the term is not compatible, it does the same thing as `dumpDiffToConsole`. + * @default false + */ + dumpInlineDiffToConsole?: boolean; /** * Removes coloring from the console output, useful if storing the results to a file. * @default false. @@ -117,7 +123,10 @@ export function configureToMatchImageSnapshot( /** * Mutates original state with new state */ -export function updateSnapshotState(originalSnapshotState: TObject, partialSnapshotState: TPartial): TObject & TPartial; +export function updateSnapshotState( + originalSnapshotState: TObject, + partialSnapshotState: TPartial, +): TObject & TPartial; declare global { namespace jest { diff --git a/types/jest-image-snapshot/jest-image-snapshot-tests.ts b/types/jest-image-snapshot/jest-image-snapshot-tests.ts index 9c46f38f2ef371..1f3569cdda732c 100644 --- a/types/jest-image-snapshot/jest-image-snapshot-tests.ts +++ b/types/jest-image-snapshot/jest-image-snapshot-tests.ts @@ -1,5 +1,9 @@ -// Typescript Version: 2.3 -import { configureToMatchImageSnapshot, MatchImageSnapshotOptions, toMatchImageSnapshot, updateSnapshotState } from 'jest-image-snapshot'; +import { + configureToMatchImageSnapshot, + MatchImageSnapshotOptions, + toMatchImageSnapshot, + updateSnapshotState, +} from 'jest-image-snapshot'; it('should be able to use toMatchImageSnapshot in a test', () => { expect.extend({ toMatchImageSnapshot }); @@ -35,6 +39,7 @@ it('Should be able to use configuration directly in toMatchImageSnapshot', () => }, customDiffDir: './diffs', diffDirection: 'vertical', + dumpInlineDiffToConsole: true, updatePassedSnapshot: true, failureThreshold: 10, failureThresholdType: 'percent', diff --git a/types/jest-image-snapshot/package.json b/types/jest-image-snapshot/package.json index 06ee6658e95b40..abe8696404b907 100644 --- a/types/jest-image-snapshot/package.json +++ b/types/jest-image-snapshot/package.json @@ -1,6 +1,6 @@ { "private": true, "dependencies": { - "ssim.js": "^3.1.0" + "ssim.js": "^3.1.1" } } diff --git a/types/jest-image-snapshot/v2/index.d.ts b/types/jest-image-snapshot/v2/index.d.ts deleted file mode 100644 index 95a3a8139a1d0c..00000000000000 --- a/types/jest-image-snapshot/v2/index.d.ts +++ /dev/null @@ -1,117 +0,0 @@ -// Type definitions for jest-image-snapshot 2.12 -// Project: https://github.com/americanexpress/jest-image-snapshot#readme -// Definitions by: Janeene Beeforth -// erbridge -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 3.8 - -/// - -/** - * Options to be passed to the 'pixelmatch' image diffing function. - */ -export interface PixelmatchOptions { - /** Matching threshold, ranges from 0 to 1. Smaller values make the comparison more sensitive. 0.1 by default. */ - readonly threshold?: number; - /** If true, disables detecting and ignoring anti-aliased pixels. false by default. */ - readonly includeAA?: boolean; -} - -export interface MatchImageSnapshotOptions { - /** - * Custom config passed to 'pixelmatch' - */ - customDiffConfig?: PixelmatchOptions; - /** - * Custom snapshots directory. - * Absolute path of a directory to keep the snapshot in. - */ - customSnapshotsDir?: string; - /** - * A custom absolute path of a directory to keep this diff in - */ - customDiffDir?: string; - /** - * A custom name to give this snapshot. If not provided, one is computed automatically. When a function is provided - * it is called with an object containing testPath, currentTestName, counter and defaultIdentifier as its first - * argument. The function must return an identifier to use for the snapshot. - */ - customSnapshotIdentifier?: - | ((parameters: { - testPath: string; - currentTestName: string; - counter: number; - defaultIdentifier: string; - }) => string) - | string; - /** - * Changes diff image layout direction, default is horizontal. - */ - diffDirection?: 'horizontal' | 'vertical'; - /** - * Will output base64 string of a diff image to console in case of failed tests (in addition to creating a diff image). - * This string can be copy-pasted to a browser address string to preview the diff for a failed test. - */ - dumpDiffToConsole?: boolean; - /** - * Removes coloring from the console output, useful if storing the results to a file. - * Defaults to false. - */ - noColors?: boolean; - /** - * Sets the threshold that would trigger a test failure based on the failureThresholdType selected. This is different - * to the customDiffConfig.threshold above - the customDiffConfig.threshold is the per pixel failure threshold, whereas - * this is the failure threshold for the entire comparison. - * Defaults to 0. - */ - failureThreshold?: number; - /** - * Sets the type of threshold that would trigger a failure. - * Defaults to 'pixel'. - */ - failureThresholdType?: 'pixel' | 'percent'; - /** - * Updates a snapshot even if it passed the threshold against the existing one. - * Defaults to false. - */ - updatePassedSnapshot?: boolean; - /** - * Applies Gaussian Blur on compared images, accepts radius in pixels as value. Useful when you have noise after - * scaling images per different resolutions on your target website, usually setting it's value to 1-2 should be - * enough to solve that problem. - * Defaults to 0. - */ - blur?: number; - /** - * Runs the diff in process without spawning a child process. - * Defaults to false. - */ - runInProcess?: boolean; -} - -/** - * Function to be passed to jest's expect.extend. - * Example: - * import { toMatchImageSnapshot } from 'jest-image-snapshot'; - * expect.extend({ toMatchImageSnapshot }); - */ -export function toMatchImageSnapshot(options?: MatchImageSnapshotOptions): { message(): string; pass: boolean }; - -/** - * Configurable function that can be passed to jest's expect.extend. - * Example: - * import { configureToMatchImageSnapshot } from 'jest-image-snapshot'; - * const toMatchImageSnapshot = configureToMatchImageSnapshot({ noColors: true }); - * expect.extend({ toMatchImageSnapshot }); - */ -export function configureToMatchImageSnapshot( - options: MatchImageSnapshotOptions, -): () => { message(): string; pass: boolean }; - -declare global { - namespace jest { - interface Matchers { - toMatchImageSnapshot(options?: MatchImageSnapshotOptions): R; - } - } -} diff --git a/types/jest-image-snapshot/v2/jest-image-snapshot-tests.ts b/types/jest-image-snapshot/v2/jest-image-snapshot-tests.ts deleted file mode 100644 index 1c8401e07e90fe..00000000000000 --- a/types/jest-image-snapshot/v2/jest-image-snapshot-tests.ts +++ /dev/null @@ -1,58 +0,0 @@ -// Typescript Version: 2.3 -import { configureToMatchImageSnapshot, MatchImageSnapshotOptions, toMatchImageSnapshot } from 'jest-image-snapshot'; - -it('should be able to use toMatchImageSnapshot in a test', () => { - expect.extend({ toMatchImageSnapshot }); - - expect(400).toMatchImageSnapshot(); -}); - -it('should be able to use configureToMatchImageSnapshot in a test', () => { - const matchFn = configureToMatchImageSnapshot({ - noColors: true, - customDiffConfig: { - threshold: 5, - includeAA: false - }, - failureThreshold: 10, - failureThresholdType: 'percent' - }); - expect.extend({ toMatchImageSnapshot: matchFn }); - - expect('Me').toMatchImageSnapshot(); -}); - -it('Should be able to use configuration directly in toMatchImageSnapshot', () => { - expect.extend({ toMatchImageSnapshot }); - - const options: MatchImageSnapshotOptions = { - noColors: true, - customDiffConfig: { - threshold: 5, - includeAA: false - }, - customDiffDir: './diffs', - diffDirection: 'vertical', - updatePassedSnapshot: true, - failureThreshold: 10, - failureThresholdType: 'percent' - }; - - expect('Me').toMatchImageSnapshot(options); -}); - -it('Should be able to use string as customSnapshotIdentifier', () => { - const options: MatchImageSnapshotOptions = { - customSnapshotIdentifier: 'string identifier', - }; - - expect('Me').toMatchImageSnapshot(options); -}); - -it('Should be able to use callback as customSnapshotIdentifier', () => { - const options: MatchImageSnapshotOptions = { - customSnapshotIdentifier: () => 'string identifier', - }; - - expect('Me').toMatchImageSnapshot(options); -}); diff --git a/types/jest-image-snapshot/v2/tsconfig.json b/types/jest-image-snapshot/v2/tsconfig.json deleted file mode 100644 index 1f1544ad9938d4..00000000000000 --- a/types/jest-image-snapshot/v2/tsconfig.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "baseUrl": "../../", - "typeRoots": [ - "../../" - ], - "paths": { - "jest-image-snapshot": [ - "jest-image-snapshot/v2" - ] - }, - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "jest-image-snapshot-tests.ts" - ] -} diff --git a/types/jest-image-snapshot/v2/tslint.json b/types/jest-image-snapshot/v2/tslint.json deleted file mode 100644 index 3db14f85eaf7b9..00000000000000 --- a/types/jest-image-snapshot/v2/tslint.json +++ /dev/null @@ -1 +0,0 @@ -{ "extends": "dtslint/dt.json" }