-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathnormalizeOptions.test.js
More file actions
88 lines (75 loc) · 2.5 KB
/
Copy pathnormalizeOptions.test.js
File metadata and controls
88 lines (75 loc) · 2.5 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
const normalizeOptions = require('../../lib/utils/normalizeOptions');
const ReactRefreshEntry = require.resolve('../../client/ReactRefreshEntry');
/** @type {Partial<import('../../types/types').ReactRefreshPluginOptions>} */
const DEFAULT_OPTIONS = {
exclude: /node_modules/i,
include: /\.([cm]js|[jt]sx?|flow)$/i,
runtimeEntry: ReactRefreshEntry,
overlay: {
entry: require.resolve('../../client/ErrorOverlayEntry'),
module: require.resolve('../../overlay'),
sockIntegration: 'wds',
},
};
describe('normalizeOptions', () => {
it('should return default options when an empty object is received', () => {
expect(normalizeOptions({})).toStrictEqual(DEFAULT_OPTIONS);
});
it('should return user options', () => {
expect(
normalizeOptions({
exclude: 'exclude',
forceEnable: true,
include: 'include',
library: 'library',
runtimeEntry: 'runtimeEntry',
overlay: {
entry: 'entry',
module: 'overlay',
sockIntegration: 'whm',
},
})
).toStrictEqual({
exclude: 'exclude',
forceEnable: true,
include: 'include',
library: 'library',
runtimeEntry: 'runtimeEntry',
overlay: {
entry: 'entry',
module: 'overlay',
sockIntegration: 'whm',
},
});
});
it('should return default for overlay options when it is true', () => {
expect(normalizeOptions({ overlay: true })).toStrictEqual(DEFAULT_OPTIONS);
});
it('should return false for overlay options when it is false', () => {
expect(normalizeOptions({ overlay: false })).toStrictEqual({
...DEFAULT_OPTIONS,
overlay: false,
});
});
it('should keep "runtimeEntry" when it is false', () => {
expect(normalizeOptions({ runtimeEntry: false })).toStrictEqual({
...DEFAULT_OPTIONS,
runtimeEntry: false,
});
});
it('should keep "overlay.entry" when it is false', () => {
const options = { ...DEFAULT_OPTIONS };
options.overlay.entry = false;
expect(normalizeOptions(options)).toStrictEqual(options);
});
it('should keep "overlay.module" when it is false', () => {
const options = { ...DEFAULT_OPTIONS };
options.overlay.module = false;
expect(normalizeOptions(options)).toStrictEqual(options);
});
it('should keep "overlay.sockIntegration" when it is false', () => {
const options = { ...DEFAULT_OPTIONS };
options.overlay.sockIntegration = false;
expect(normalizeOptions(options)).toStrictEqual(options);
});
});