Nuxt/test/dev/wp.config.test.js

42 lines
1.2 KiB
JavaScript
Raw Normal View History

import path from 'path'
import PerfLoader from '../../packages/webpack/src/utils/perf-loader'
describe('webpack configuration', () => {
test('performance loader', () => {
const js = { name: 'js', poolTimeout: Infinity }
const css = { name: 'css', poolTimeout: Infinity }
const resolveModule = jest.fn(id => id)
2018-11-08 22:26:52 +00:00
PerfLoader.warmup = jest.fn()
PerfLoader.warmupAll({ dev: true, resolveModule })
2018-11-08 22:26:52 +00:00
expect(PerfLoader.warmup).toHaveBeenCalledTimes(2)
expect(PerfLoader.warmup).toHaveBeenCalledWith(js, [
'babel-loader',
'@babel/preset-env'
])
2018-11-08 22:26:52 +00:00
expect(PerfLoader.warmup).toHaveBeenCalledWith(css, ['css-loader'])
const perfLoader = new PerfLoader(
'test-perf',
{
options: {
dev: true
},
buildOptions: {
2018-11-08 22:26:52 +00:00
parallel: true,
cache: true
}
},
{
resolveModule
2018-11-08 22:26:52 +00:00
}
)
2018-11-08 22:26:52 +00:00
expect(perfLoader.workerPools).toMatchObject({ js, css })
const loaders = perfLoader.use('js')
const cacheDirectory = path.resolve('node_modules/.cache/cache-loader/test-perf')
expect(loaders).toMatchObject([
{ loader: 'cache-loader', options: { cacheDirectory } },
2018-11-08 22:26:52 +00:00
{ loader: 'thread-loader', options: js }
])
})
})