forked from nuxt/nuxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.test.js
More file actions
50 lines (43 loc) · 1.51 KB
/
webpack.test.js
File metadata and controls
50 lines (43 loc) · 1.51 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
import path from 'path'
import util from 'util'
import consola from 'consola'
import prettyFormat from 'pretty-format'
import { NuxtCommand, getWebpackConfig } from '../..'
import webpackCommand from '../../src/commands/webpack'
const replaceAll = (str, a, b) => str.split(a).join(b)
const nuxtDir = path.join(__dirname, '../../../..')
const maskDir = str => replaceAll(str, nuxtDir, '<nuxtDir>')
const tests = [
'devtool',
'resolve alias',
'module.rules',
'module.rules test=.jsx',
'module.rules loader=vue-',
'module.rules loader=.*-loader',
'nuxt webpack module rules test=.pug oneOf use.0=raw'
]
describe('webpack', () => {
beforeAll(() => {
process.stdout.isTTY = false
util.formatWithOptions = (opts, obj) => prettyFormat(obj)
})
afterEach(() => {
jest.resetAllMocks()
})
test.posix('getWebpackConfig()', async () => {
const webpackConfig = await getWebpackConfig('Client')
expect(maskDir(prettyFormat(webpackConfig.module.rules[0]))).toMatchSnapshot()
})
test.posix('nuxt webpack no match', async () => {
const cmd = NuxtCommand.from(webpackCommand, ['module.rules', 'loader=foobar'])
await cmd.run()
expect(maskDir(consola.warn.mock.calls[0][0])).toBe('No match in webpack config for `loader=foobar`')
})
for (const testCase of tests) {
test.posix('nuxt webpack ' + testCase, async () => {
const cmd = NuxtCommand.from(webpackCommand, testCase.split(' '))
await cmd.run()
expect(maskDir(consola.log.mock.calls[0][0])).toMatchSnapshot()
})
}
})