-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathmochaHooks.js
57 lines (45 loc) · 2.19 KB
/
mochaHooks.js
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
import * as React from 'react';
import * as ReactTransitionGroup from 'react-transition-group';
import { stub, restore } from 'sinon';
import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingDataGrid } from '@mui/x-data-grid';
import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingDataGridPro } from '@mui/x-data-grid-pro';
import { unstable_resetCleanupTracking as unstable_resetCleanupTrackingTreeView } from '@mui/x-tree-view';
import { unstable_cleanupDOM as unstable_cleanupDOMCharts } from '@mui/x-charts/internals';
import { clearWarningsCache } from '@mui/x-internals/warning';
import { generateTestLicenseKey, setupTestLicenseKey } from './testLicense';
export function createXMochaHooks(coreMochaHooks = {}) {
const mochaHooks = {
beforeAll: [...(coreMochaHooks.beforeAll ?? [])],
afterAll: [...(coreMochaHooks.afterAll ?? [])],
beforeEach: [...(coreMochaHooks.beforeEach ?? [])],
afterEach: [...(coreMochaHooks.afterEach ?? [])],
};
let licenseKey, transitionStub, cssTransitionStub;
mochaHooks.beforeAll.push(function func() {
licenseKey = generateTestLicenseKey();
function FakeTransition({ children }) { return <React.Fragment>{children}</React.Fragment>; };
function FakeCSSTransition(props) {
return props.in ? <FakeTransition>{props.children}</FakeTransition> : null;
}
transitionStub = stub(ReactTransitionGroup, 'Transition').callsFake(FakeTransition);
cssTransitionStub = stub(ReactTransitionGroup, 'CSSTransition').callsFake(FakeCSSTransition);
});
mochaHooks.beforeEach.push(function setupLicenseKey() {
setupTestLicenseKey(licenseKey);
});
mochaHooks.afterEach.push(function resetCleanupTracking() {
unstable_resetCleanupTrackingDataGrid();
unstable_resetCleanupTrackingDataGridPro();
unstable_resetCleanupTrackingTreeView();
unstable_cleanupDOMCharts();
// Restore Sinon default sandbox to avoid memory leak
// See https://github.com/sinonjs/sinon/issues/1866
restore();
});
mochaHooks.afterEach.push(clearWarningsCache);
mochaHooks.afterAll.push(function restoreTransition() {
transitionStub.restore();
cssTransitionStub.restore();
});
return mochaHooks;
}