forked from rails/webpacker
/
base.js
74 lines (58 loc) · 2.24 KB
/
base.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
/* global test expect, describe, afterAll, beforeEach */
// environment.js expects to find config/webpacker.yml and resolved modules from
// the root of a Rails project
const { chdirTestApp, chdirCwd } = require('../../utils/helpers')
chdirTestApp()
const { resolve } = require('path')
const rules = require('../../rules')
const { ConfigList } = require('../../config_types')
const Environment = require('../base')
describe('Environment', () => {
afterAll(chdirCwd)
let environment
describe('toWebpackConfig', () => {
beforeEach(() => {
environment = new Environment()
})
test('should return entry', () => {
const config = environment.toWebpackConfig()
expect(config.entry.application).toEqual(
resolve('app', 'javascript', 'packs', 'application.js')
)
})
test('should return output', () => {
const config = environment.toWebpackConfig()
expect(config.output.filename).toEqual('js/[name]-[contenthash].js')
expect(config.output.chunkFilename).toEqual('js/[name]-[contenthash].chunk.js')
})
test('should return default loader rules for each file in config/loaders', () => {
const config = environment.toWebpackConfig()
const defaultRules = Object.keys(rules)
const configRules = config.module.rules
expect(defaultRules.length).toEqual(8)
expect(configRules.length).toEqual(9)
})
test('should return default plugins', () => {
const config = environment.toWebpackConfig()
expect(config.plugins.length).toEqual(4)
})
test('should return default resolveLoader', () => {
const config = environment.toWebpackConfig()
expect(config.resolveLoader.modules).toEqual(['node_modules'])
})
test('should return default resolve.modules with additions', () => {
const config = environment.toWebpackConfig()
expect(config.resolve.modules).toEqual([
resolve('app', 'javascript'),
resolve('app/assets'),
resolve('/etc/yarn'),
'node_modules'
])
})
test('returns plugins property as Array', () => {
const config = environment.toWebpackConfig()
expect(config.plugins).toBeInstanceOf(Array)
expect(config.plugins).not.toBeInstanceOf(ConfigList)
})
})
})