-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathutils.server.test.js
More file actions
78 lines (66 loc) · 2.24 KB
/
utils.server.test.js
File metadata and controls
78 lines (66 loc) · 2.24 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
/**
* @jest-environment node
*/
/*
* Copyright (c) 2022, Salesforce, 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
*/
// Jest requires the @jest-environment comment at the start of file, which
// conflicts with the eslint header rule.
/* eslint-disable header/header */
import * as utils from './utils'
import {proxyConfigs} from '@salesforce/pwa-kit-runtime/utils/ssr-shared'
import {getConfig} from '@salesforce/pwa-kit-runtime/utils/ssr-config'
import {getEnvBasePath} from '@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths'
jest.mock('@salesforce/pwa-kit-runtime/utils/ssr-config', () => ({
getConfig: jest.fn()
}))
jest.mock('@salesforce/pwa-kit-runtime/utils/ssr-namespace-paths', () => ({
getEnvBasePath: jest.fn()
}))
describe('getProxyConfigs (server-side)', () => {
test('should return the currently used proxy configs', () => {
expect(utils.getProxyConfigs()).toEqual(proxyConfigs)
})
})
describe('getRouterBasePath (server-side)', () => {
beforeEach(() => {
jest.clearAllMocks()
})
test('should return base path when showBasePath is true', () => {
const mockBasePath = '/test-base'
getEnvBasePath.mockReturnValue(mockBasePath)
getConfig.mockReturnValue({
app: {
url: {
showBasePath: true
}
}
})
expect(utils.getRouterBasePath()).toBe(mockBasePath)
})
test('should return empty string when showBasePath is undefined', () => {
getConfig.mockReturnValue({
app: {
url: {}
}
})
expect(utils.getRouterBasePath()).toBe('')
})
test('should return empty string when showBasePath is false', () => {
getConfig.mockReturnValue({
app: {
url: {
showBasePath: false
}
}
})
expect(utils.getRouterBasePath()).toBe('')
})
test('should return empty string when app config is missing', () => {
getConfig.mockReturnValue({})
expect(utils.getRouterBasePath()).toBe('')
})
})