-
-
Notifications
You must be signed in to change notification settings - Fork 597
/
validate-options.test.js
113 lines (100 loc) · 4.18 KB
/
validate-options.test.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
111
112
113
import loader from '../src/cjs';
it('validate options', () => {
const validate = (options) =>
loader.call(
Object.assign(
{},
{
query: options,
loaders: [],
remainingRequest: 'file.css',
currentRequest: 'file.css',
async: () => (error) => {
if (error) {
throw error;
}
},
}
),
'a { color: red; }'
);
expect(() => validate({ url: true })).not.toThrow();
expect(() => validate({ url: false })).not.toThrow();
expect(() => validate({ url: () => {} })).not.toThrow();
expect(() => validate({ url: 'true' })).toThrowErrorMatchingSnapshot();
expect(() => validate({ import: true })).not.toThrow();
expect(() => validate({ import: false })).not.toThrow();
expect(() => validate({ import: () => {} })).not.toThrow();
expect(() => validate({ import: 'true' })).toThrowErrorMatchingSnapshot();
expect(() => validate({ modules: true })).not.toThrow();
expect(() => validate({ modules: false })).not.toThrow();
expect(() => validate({ modules: 'global' })).not.toThrow();
expect(() => validate({ modules: 'local' })).not.toThrow();
expect(() => validate({ modules: { mode: 'local' } })).not.toThrow();
expect(() => validate({ modules: { mode: 'global' } })).not.toThrow();
expect(() => validate({ modules: 'true' })).toThrowErrorMatchingSnapshot();
expect(() => validate({ modules: 'globals' })).toThrowErrorMatchingSnapshot();
expect(() => validate({ modules: 'locals' })).toThrowErrorMatchingSnapshot();
expect(() =>
validate({ modules: { mode: true } })
).toThrowErrorMatchingSnapshot();
expect(() =>
validate({ modules: { mode: 'true' } })
).toThrowErrorMatchingSnapshot();
expect(() =>
validate({ modules: { mode: 'locals' } })
).toThrowErrorMatchingSnapshot();
expect(() =>
validate({ modules: { mode: 'globals' } })
).toThrowErrorMatchingSnapshot();
expect(() =>
validate({
modules: { localIdentName: '[path][name]__[local]--[hash:base64:5]' },
})
).not.toThrow();
expect(() =>
validate({ modules: { localIdentName: true } })
).toThrowErrorMatchingSnapshot();
expect(() => validate({ modules: { context: 'context' } })).not.toThrow();
expect(() =>
validate({ modules: { context: true } })
).toThrowErrorMatchingSnapshot();
expect(() => validate({ modules: { hashPrefix: 'hash' } })).not.toThrow();
expect(() =>
validate({ modules: { hashPrefix: true } })
).toThrowErrorMatchingSnapshot();
expect(() =>
validate({ modules: { getLocalIdent: () => {} } })
).not.toThrow();
expect(() => validate({ modules: { getLocalIdent: false } })).not.toThrow();
expect(() =>
validate({ modules: { getLocalIdent: [] } })
).toThrowErrorMatchingSnapshot();
expect(() =>
validate({ modules: { localIdentRegExp: 'page-(.*)\\.js' } })
).not.toThrow();
expect(() =>
validate({ modules: { localIdentRegExp: /page-(.*)\.js/ } })
).not.toThrow();
expect(() =>
validate({ modules: { localIdentRegExp: true } })
).toThrowErrorMatchingSnapshot();
expect(() => validate({ sourceMap: true })).not.toThrow();
expect(() => validate({ sourceMap: false })).not.toThrow();
expect(() => validate({ sourceMap: 'true' })).toThrowErrorMatchingSnapshot();
expect(() => validate({ exportLocalsStyle: 'camelCase' })).not.toThrow();
expect(() => validate({ exportLocalsStyle: 'camelCaseOnly' })).not.toThrow();
expect(() => validate({ exportLocalsStyle: 'dashes' })).not.toThrow();
expect(() => validate({ exportLocalsStyle: 'dashesOnly' })).not.toThrow();
expect(() =>
validate({ exportLocalsStyle: 'unknown' })
).toThrowErrorMatchingSnapshot();
expect(() => validate({ importLoaders: false })).not.toThrow();
expect(() => validate({ importLoaders: 0 })).not.toThrow();
expect(() => validate({ importLoaders: 1 })).not.toThrow();
expect(() => validate({ importLoaders: 2 })).not.toThrow();
expect(() => validate({ importLoaders: '1' })).toThrowErrorMatchingSnapshot();
expect(() => validate({ onlyLocals: true })).not.toThrow();
expect(() => validate({ onlyLocals: false })).not.toThrow();
expect(() => validate({ onlyLocals: 'true' })).toThrowErrorMatchingSnapshot();
});