forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
110 lines (90 loc) · 2.84 KB
/
setup.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
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
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import Adapter from 'enzyme-adapter-react-16';
import {configure} from 'enzyme';
import '@testing-library/jest-dom';
import './redux-persist_mock';
import './react-intl_mock';
import './react-tippy_mock';
global.performance = {};
require('isomorphic-fetch');
configure({adapter: new Adapter()});
global.window = Object.create(window);
Object.defineProperty(window, 'location', {
value: {
href: 'http:https://localhost:8065',
origin: 'http:https://localhost:8065',
port: '8065',
protocol: 'http:',
search: '',
},
});
const supportedCommands = ['copy'];
Object.defineProperty(document, 'queryCommandSupported', {
value: (cmd) => supportedCommands.includes(cmd),
});
Object.defineProperty(document, 'execCommand', {
value: (cmd) => supportedCommands.includes(cmd),
});
document.documentElement.style.fontSize = '12px';
// isDependencyWarning returns true when the given console.warn message is coming from a dependency using deprecated
// React lifecycle methods.
function isDependencyWarning(params) {
function paramsHasComponent(name) {
return params.some((param) => param.includes(name));
}
return params[0].includes('Please update the following components:') && (
// React Bootstrap
paramsHasComponent('Modal') ||
paramsHasComponent('Portal') ||
paramsHasComponent('Overlay') ||
paramsHasComponent('Position') ||
// React-Select
paramsHasComponent('Select')
);
}
let warns;
let errors;
beforeAll(() => {
console.originalWarn = console.warn;
console.warn = jest.fn((...params) => {
// Ignore any deprecation warnings coming from dependencies
if (isDependencyWarning(params)) {
return;
}
console.originalWarn(...params);
warns.push(params);
});
console.originalError = console.error;
console.error = jest.fn((...params) => {
console.originalError(...params);
errors.push(params);
});
});
beforeEach(() => {
warns = [];
errors = [];
});
afterEach(() => {
if (warns.length > 0 || errors.length > 0) {
const message = 'Unexpected console logs' + warns + errors;
throw new Error(message);
}
});
expect.extend({
arrayContainingExactly(received, actual) {
const pass = received.sort().join(',') === actual.sort().join(',');
if (pass) {
return {
message: () =>
`expected ${received} to not contain the exact same values as ${actual}`,
pass: true,
};
}
return {
message: () =>
`expected ${received} to not contain the exact same values as ${actual}`,
pass: false,
};
},
});