docusaurus/test/webpack/index.test.js
2018-08-11 14:23:11 +08:00

48 lines
1.5 KiB
JavaScript

import webpack from 'webpack';
import createDevConfig from '@lib/webpack/dev';
import createProdConfig from '@lib/webpack/prod';
import loadSetup from '../loadSetup';
// webpack compiler helper function
function compile(config) {
return new Promise((resolve, reject) => {
webpack(config, (err, stats) => {
if (err || stats.hasErrors()) {
reject(new Error(`Failed to compile with errors`));
}
resolve('Compiled successfully');
});
});
}
describe('webpack', () => {
const timeOut = 10000; // 10 seconds
test('dev simple', async () => {
console.log = jest.fn();
const props = await loadSetup('simple');
const config = createDevConfig(props).toConfig();
return expect(compile(config)).resolves.toBe('Compiled successfully');
}, timeOut);
test('dev custom', async () => {
console.log = jest.fn();
const props = await loadSetup('custom');
const config = createDevConfig(props).toConfig();
return expect(compile(config)).resolves.toBe('Compiled successfully');
}, timeOut);
test('prod simple', async () => {
console.log = jest.fn();
const props = await loadSetup('simple');
const config = createProdConfig(props).toConfig();
return expect(compile(config)).resolves.toBe('Compiled successfully');
}, timeOut);
test('prod custom', async () => {
console.log = jest.fn();
const props = await loadSetup('custom');
const config = createProdConfig(props).toConfig();
return expect(compile(config)).resolves.toBe('Compiled successfully');
}, timeOut);
});