-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathsetup-jest.js
More file actions
59 lines (57 loc) · 2.19 KB
/
setup-jest.js
File metadata and controls
59 lines (57 loc) · 2.19 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
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
/* eslint-env jest */
import 'regenerator-runtime/runtime'
import '@testing-library/jest-dom'
import {performance} from 'perf_hooks'
// Mock the application configuration to be used in all tests.
jest.mock('@salesforce/pwa-kit-runtime/utils/ssr-config', () => {
return {
getConfig: () => ({
externals: [],
pageNotFoundURL: '/page-not-found',
ssrEnabled: true,
ssrOnly: ['ssr.js', 'ssr.js.map', 'node_modules/**/*.*'],
ssrShared: [
'static/ico/favicon.ico',
'static/robots.txt',
'**/*.js',
'**/*.js.map',
'**/*.json'
],
ssrParameters: {
ssrFunctionNodeVersion: '22.x',
proxyConfigs: [
{
host: 'kv7kzm78.api.commercecloud.salesforce.com',
path: 'api'
}
]
}
})
}
})
// The global performance object is available in production
// environments for both the server and the client.
// It's just the jest environment that this is not available
if (global.performance) {
// global.performance exists but is missing methods from perf_hooks in jest
if (typeof performance.mark === 'function' && !global.performance.mark) {
global.performance.mark = performance.mark.bind(performance)
}
if (typeof performance.measure === 'function' && !global.performance.measure) {
global.performance.measure = performance.measure.bind(performance)
}
if (typeof performance.clearMarks === 'function' && !global.performance.clearMarks) {
global.performance.clearMarks = performance.clearMarks.bind(performance)
}
if (typeof performance.clearMeasures === 'function' && !global.performance.clearMeasures) {
global.performance.clearMeasures = performance.clearMeasures.bind(performance)
}
} else {
global.performance = performance
}