-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathsetup.ts
More file actions
116 lines (102 loc) · 2.9 KB
/
Copy pathsetup.ts
File metadata and controls
116 lines (102 loc) · 2.9 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import '@testing-library/jest-dom';
import { configure } from '@testing-library/react';
import { server } from './mocks/server';
import 'vitest-canvas-mock';
// scrollTo and scrollIntoView are not defined in jsdom
window.HTMLElement.prototype.scrollTo = function () {};
window.HTMLElement.prototype.scrollIntoView = function () {};
// provide a fallback *only* when window.getComputedStyle is missing
window.getComputedStyle =
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
window.getComputedStyle ||
(() => ({
getPropertyValue: () => '',
}));
// ResizeObserver is not defined and needs to be mocked and stubbed
const MockResizeObserver = vi.fn(function () {
return {
observe: vi.fn(),
unobserve: vi.fn(),
disconnect: vi.fn(),
};
});
vi.stubGlobal('ResizeObserver', MockResizeObserver);
vi.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
default: () => ({
auth: {
getUser: () =>
new Promise((resolve) => {
setTimeout(() => {
resolve({
identity: {
internal: {
org_id: 5,
},
},
});
}, 0);
}),
},
isBeta: () => true,
isProd: () => true,
getEnvironment: () => 'prod',
analytics: {
track: () => 'test',
group: () => 'test',
screen: () => 'test',
},
}),
}));
vi.mock(import('../../src/constants'), async (importOriginal) => {
const mod = await importOriginal(); // type is inferred
return {
...mod,
// replace some exports
UNIQUE_VALIDATION_DELAY: 0,
};
});
vi.mock('@unleash/proxy-client-react', () => ({
useUnleashContext: () => vi.fn(),
useFlag: vi.fn((flag) => {
switch (flag) {
case 'image-builder.images-table-revamp.enabled':
default:
return false;
}
}),
}));
// remove DOM dump from the testing-library output
configure({
getElementError: (message: string | null, _container: Element) => {
const error = new Error(message ?? '');
error.name = 'TestingLibraryElementError';
error.stack = '';
return error;
},
});
// Fail tests on console warnings and errors
beforeAll(() => {
server.listen({ onUnhandledRequest: 'error' });
vi.spyOn(console, 'error').mockImplementation((...args) => {
const message = args.join(' ');
if (message.includes('Maximum update depth exceeded')) {
return;
}
throw new Error(`Console error:\n${message}`);
});
vi.spyOn(console, 'warn').mockImplementation((...args) => {
const message = args.join(' ');
if (message.includes('Maximum update depth exceeded')) {
return;
}
if (message.includes('which is more than the warning threshold of 32ms')) {
return;
}
throw new Error(`Console warning:\n${message}`);
});
});
afterAll(() => {
server.close();
vi.restoreAllMocks();
});
afterEach(() => server.resetHandlers());