-
Notifications
You must be signed in to change notification settings - Fork 7
/
plugin.test.js
47 lines (36 loc) · 1.41 KB
/
plugin.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
const nextIntlPlugin = require('./plugin');
const webpackOptions = {
isServer: true,
};
const createWebpackConfig = () => ({
module: {
rules: [
{
test: 'foo',
loader: 'foo-loader',
},
],
},
externals: () => {},
});
it('should add a rule for canvas that uses null-loader', () => {
const config = nextIntlPlugin().webpack(createWebpackConfig(), webpackOptions);
const rule = config.module.rules[0];
expect(rule.test).toBe(require.resolve('canvas'));
expect(rule.loader).toBe(require.resolve('null-loader'));
});
it('should add no canvas rule when not server', () => {
const config = nextIntlPlugin().webpack(createWebpackConfig(), { ...webpackOptions, isServer: false });
expect(config.module.rules[0].test).toBe('foo');
});
it('should add ws\'s optional dependencies to externals', () => {
const config = nextIntlPlugin().webpack(createWebpackConfig(), webpackOptions);
expect(config.externals).toHaveLength(3);
expect(config.externals[0]).toBe('bufferutil');
expect(config.externals[1]).toBe('utf-8-validate');
expect(typeof config.externals[2]).toBe('function');
});
it('should leave externals untouched when not server', () => {
const config = nextIntlPlugin().webpack(createWebpackConfig(), { ...webpackOptions, isServer: false });
expect(typeof config.externals).toBe('function');
});