forked from grafana/pyroscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setupAfterEnv.ts
43 lines (37 loc) · 1.38 KB
/
setupAfterEnv.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import '@testing-library/jest-dom';
import 'jest-canvas-mock';
import timezoneMock from 'timezone-mock';
import { configureToMatchImageSnapshot } from 'jest-image-snapshot';
import type { MatchImageSnapshotOptions } from 'jest-image-snapshot';
import nodeFetch from 'node-fetch';
import 'regenerator-runtime/runtime';
expect.extend({
toMatchImageSnapshot(received: string, options: MatchImageSnapshotOptions) {
// If these checks pass, assume we're in a JSDOM environment with the 'canvas' package.
if (process.env.RUN_SNAPSHOTS) {
const toMatchImageSnapshot = configureToMatchImageSnapshot({
// Big enough threshold to account for different font rendering
// TODO: fix it
failureThreshold: 0.1,
failureThresholdType: 'percent',
}) as any;
// TODO
// for some reason it fails with
// Expected 1 arguments, but got 3.
// hence the any
return toMatchImageSnapshot.call(this, received, options);
}
return {
pass: true,
message: () =>
`Skipping 'toMatchImageSnapshot' assertion since env var 'RUN_SNAPSHOTS' is not set.`,
};
},
});
timezoneMock.register('UTC');
globalThis.fetch = nodeFetch as unknown as typeof fetch;
// When testing redux we can assume this will be populated
// Which will be used for setting up the initialState
(globalThis.window as any).initialState = {
appNames: [],
};