-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.test.js
89 lines (72 loc) · 2.04 KB
/
index.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
'use strict';
const alwaysOneOf = require('./index');
const createConfig = (loaderRules = []) => ({
module: {
rules: [...loaderRules],
},
});
it('should return in .oneOf rules sent in .rules', () => {
const rules = [{
test: /\.js$/,
}];
const webpackConfig = alwaysOneOf().webpack(createConfig(rules));
expect(webpackConfig).toMatchSnapshot();
});
it('should add condition to Next.js built-in oneOf rule that adds JS & CSS support', () => {
const rules = [{
oneOf: [
{
test: /\.(tsx|ts|js|cjs|mjs|jsx)$/,
},
{
test: /\.module\.css$/,
},
],
}];
const webpackConfig = alwaysOneOf().webpack(createConfig(rules));
expect(webpackConfig).toMatchSnapshot();
});
it('should not wrap rule JS rules that should be fallthrough', () => {
const rules = [
{
test: /\.m?js/,
resolve: {
fullySpecified: false,
},
},
{
test: /\.(js|cjs|mjs)$/,
issuerLayer: 'api',
},
{
oneOf: [
{
test: /\.(tsx|ts|js|cjs|mjs|jsx)$/,
},
{
test: /\.module\.css$/,
},
],
},
];
const webpackConfig = alwaysOneOf().webpack(createConfig(rules));
expect(webpackConfig).toMatchSnapshot();
});
it('should add noop SVG rule at the root if a SVG rule was detected', () => {
const rules = [
{
test: /\.svg$/,
loader: 'foo',
},
];
const webpackConfig = alwaysOneOf().webpack(createConfig(rules));
expect(webpackConfig).toMatchSnapshot();
});
it('should call nextConfig webpack if defined', () => {
const nextConfig = {
webpack: jest.fn(() => 'foo'),
};
const webpackConfig = alwaysOneOf(nextConfig).webpack(createConfig());
expect(nextConfig.webpack).toHaveBeenCalledTimes(1);
expect(webpackConfig).toBe('foo');
});