mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 21:16:59 +02:00
test: test compile dev/prod webpack config
This commit is contained in:
parent
80204b5617
commit
a4cc782858
15 changed files with 93 additions and 0 deletions
48
test/webpack/index.test.js
Normal file
48
test/webpack/index.test.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
import webpack from 'webpack';
|
||||
import path from 'path';
|
||||
import createBaseConfig from '@lib/webpack/base';
|
||||
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', () => {
|
||||
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');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue