2018-03-30 03:24:51 +00:00
|
|
|
|
|
|
|
import path from 'path'
|
2018-10-17 21:28:25 +00:00
|
|
|
import PerfLoader from '../../packages/builder/src/webpack/utils/perf-loader'
|
2018-03-30 03:24:51 +00:00
|
|
|
|
|
|
|
describe('webpack configuration', () => {
|
|
|
|
test('performance loader', () => {
|
|
|
|
const perfLoader = new PerfLoader({
|
|
|
|
dev: true,
|
|
|
|
build: {
|
|
|
|
parallel: true,
|
|
|
|
cache: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
const js = { name: 'js', poolTimeout: Infinity }
|
|
|
|
const css = { name: 'css', poolTimeout: Infinity }
|
|
|
|
expect(perfLoader.workerPools).toMatchObject({ js, css })
|
|
|
|
|
2018-04-02 12:08:31 +00:00
|
|
|
perfLoader.warmup = jest.fn()
|
|
|
|
perfLoader.warmupAll()
|
|
|
|
expect(perfLoader.warmup).toHaveBeenCalledTimes(2)
|
2018-08-10 13:45:58 +00:00
|
|
|
expect(perfLoader.warmup).toHaveBeenCalledWith(js, ['babel-loader', '@babel/preset-env'])
|
2018-04-02 12:08:31 +00:00
|
|
|
expect(perfLoader.warmup).toHaveBeenCalledWith(css, ['css-loader'])
|
2018-03-30 03:24:51 +00:00
|
|
|
|
|
|
|
const loaders = perfLoader.pool('js', { loader: 'test-perf-loader' })
|
|
|
|
const cacheDirectory = path.resolve('node_modules/.cache/cache-loader')
|
|
|
|
expect(loaders).toMatchObject([
|
|
|
|
{ loader: 'cache-loader', options: { cacheDirectory } },
|
|
|
|
{ loader: 'thread-loader', options: js },
|
|
|
|
{ loader: 'test-perf-loader' }
|
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|