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

[INFRA] use @types/jest-image-snapshot instead of custom types #825

Merged
merged 1 commit into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"@types/debug": "^4.1.5",
"@types/jest": "^26.0.15",
"@types/jest-environment-puppeteer": "^4.3.2",
"@types/jest-image-snapshot": "^4.1.2",
"@types/minimist": "^1.2.0",
"@types/puppeteer": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^4.4.1",
Expand Down
5 changes: 1 addition & 4 deletions test/e2e/config/jest.image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// TODO give a try to import when we will use 'jest-image-snapshot' types
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { toMatchImageSnapshot } = require('jest-image-snapshot');

import { toMatchImageSnapshot } from 'jest-image-snapshot';
expect.extend({ toMatchImageSnapshot });
22 changes: 3 additions & 19 deletions test/e2e/helpers/visu-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,9 @@
* limitations under the License.
*/
import { ElementHandle } from 'puppeteer';

// TODO use 'jest-image-snapshot' definition types when the lib will be updated
// The type lib does not support setting config for ssim (4.2.0 released on july 2020)
// typescript integration: https://github.com/americanexpress/jest-image-snapshot#usage-in-typescript
//
// inspired from https://medium.com/javascript-in-plain-english/jest-how-to-use-extend-with-typescript-4011582a2217
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace jest {
interface Matchers<R> {
toMatchImageSnapshot(imageSnapshotConfig?: ImageSnapshotConfig): R;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface ImageSnapshotConfig {}
}
}

import debugLogger from 'debug';
import { copyFileSync, loadBpmnContentForUrlQueryParam } from '../../helpers/file-helper';
import { MatchImageSnapshotOptions } from 'jest-image-snapshot';

const log = debugLogger('test');

Expand All @@ -55,7 +39,7 @@ export interface ImageSnapshotThresholdConfig {
windows: number;
}

const defaultImageSnapshotConfig = {
const defaultImageSnapshotConfig: MatchImageSnapshotOptions = {
diffDirection: 'vertical',
dumpDiffToConsole: true, // useful on CI (no need to retrieve the diff image, copy/paste image content from logs)
// use SSIM to limit false positive
Expand All @@ -74,7 +58,7 @@ export class ImageSnapshotConfigurator {
*/
constructor(readonly thresholdConfig: Map<string, ImageSnapshotThresholdConfig>) {}

getConfig(fileName: string): jest.ImageSnapshotConfig {
getConfig(fileName: string): MatchImageSnapshotOptions {
// minimal threshold to make tests for diagram renders pass on local
// macOS: Expected image to match or be a close match to snapshot but was 0.00031509446166699817% different from snapshot
let failureThreshold = 0.000004;
Expand Down