mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
test: validate generated webpack config instead of compiling
This commit is contained in:
parent
1564edae4c
commit
3eb9823105
5 changed files with 121 additions and 69 deletions
|
@ -21,8 +21,37 @@ exports[`genRoutesConfig website with only docs 1`] = `
|
|||
import Docs from '@theme/Docs';
|
||||
import NotFound from '@theme/NotFound';
|
||||
|
||||
|
||||
const routes = [,,
|
||||
import MDHello from '@docs/hello.md';
|
||||
import MDFooBar from '@docs/foo/bar.md';
|
||||
import MDFooBaz from '@docs/foo/baz.md';
|
||||
const routes = [
|
||||
{
|
||||
path: \\"/hello\\",
|
||||
exact: true,
|
||||
component: (props) => (
|
||||
<Docs {...props}>
|
||||
<MDHello />
|
||||
</Docs>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: \\"/foo/bar\\",
|
||||
exact: true,
|
||||
component: (props) => (
|
||||
<Docs {...props}>
|
||||
<MDFooBar />
|
||||
</Docs>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: \\"/foo/baz\\",
|
||||
exact: true,
|
||||
component: (props) => (
|
||||
<Docs {...props}>
|
||||
<MDFooBaz />
|
||||
</Docs>
|
||||
)
|
||||
},,
|
||||
{
|
||||
path: '*',
|
||||
component: NotFound
|
||||
|
@ -77,10 +106,39 @@ import Docs from '@theme/Docs';
|
|||
import NotFound from '@theme/NotFound';
|
||||
import JSFoo from '@pages/foo.js';
|
||||
import JSIndex from '@pages/index.js';
|
||||
import JSFooIndex from '@pages/foo/index.js';
|
||||
import JSBarBaz from '@pages/bar/baz.js';
|
||||
|
||||
const routes = [,
|
||||
import JSFooIndex from '@pages/foo/index.js';
|
||||
import MDHello from '@docs/hello.md';
|
||||
import MDFooBaz from '@docs/foo/baz.md';
|
||||
import MDFooBar from '@docs/foo/bar.md';
|
||||
const routes = [
|
||||
{
|
||||
path: \\"/hello\\",
|
||||
exact: true,
|
||||
component: (props) => (
|
||||
<Docs {...props}>
|
||||
<MDHello />
|
||||
</Docs>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: \\"/foo/baz\\",
|
||||
exact: true,
|
||||
component: (props) => (
|
||||
<Docs {...props}>
|
||||
<MDFooBaz />
|
||||
</Docs>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: \\"/foo/bar\\",
|
||||
exact: true,
|
||||
component: (props) => (
|
||||
<Docs {...props}>
|
||||
<MDFooBar />
|
||||
</Docs>
|
||||
)
|
||||
},
|
||||
{
|
||||
path: \\"/foo\\",
|
||||
exact: true,
|
||||
|
@ -91,16 +149,16 @@ const routes = [,
|
|||
exact: true,
|
||||
component: JSIndex
|
||||
},
|
||||
{
|
||||
path: \\"/foo/\\",
|
||||
exact: true,
|
||||
component: JSFooIndex
|
||||
},
|
||||
{
|
||||
path: \\"/bar/baz\\",
|
||||
exact: true,
|
||||
component: JSBarBaz
|
||||
},
|
||||
{
|
||||
path: \\"/foo/\\",
|
||||
exact: true,
|
||||
component: JSFooIndex
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
component: NotFound
|
||||
|
|
|
@ -1,29 +1,21 @@
|
|||
import createDevConfig from '@lib/webpack/dev';
|
||||
import compile from './compile';
|
||||
import createBaseConfig from '@lib/webpack/base';
|
||||
import {validate} from 'webpack';
|
||||
import loadSetup from '../loadSetup';
|
||||
|
||||
describe('webpack dev config', () => {
|
||||
const timeOut = 20000; // 20 seconds
|
||||
describe('webpack base config', () => {
|
||||
test('simple', async () => {
|
||||
console.log = jest.fn();
|
||||
const props = await loadSetup('simple');
|
||||
const config = createBaseConfig(props).toConfig();
|
||||
const errors = validate(config);
|
||||
expect(errors.length).toBe(0);
|
||||
});
|
||||
|
||||
test(
|
||||
'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(
|
||||
'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('custom', async () => {
|
||||
console.log = jest.fn();
|
||||
const props = await loadSetup('custom');
|
||||
const config = createBaseConfig(props).toConfig();
|
||||
const errors = validate(config);
|
||||
expect(errors.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
import webpack from 'webpack';
|
||||
|
||||
export default 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');
|
||||
});
|
||||
});
|
||||
}
|
21
test/webpack/dev.test.js
Normal file
21
test/webpack/dev.test.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
import createDevConfig from '@lib/webpack/dev';
|
||||
import {validate} from 'webpack';
|
||||
import loadSetup from '../loadSetup';
|
||||
|
||||
describe('webpack dev config', () => {
|
||||
test('simple', async () => {
|
||||
console.log = jest.fn();
|
||||
const props = await loadSetup('simple');
|
||||
const config = createDevConfig(props).toConfig();
|
||||
const errors = validate(config);
|
||||
expect(errors.length).toBe(0);
|
||||
});
|
||||
|
||||
test('custom', async () => {
|
||||
console.log = jest.fn();
|
||||
const props = await loadSetup('custom');
|
||||
const config = createDevConfig(props).toConfig();
|
||||
const errors = validate(config);
|
||||
expect(errors.length).toBe(0);
|
||||
});
|
||||
});
|
|
@ -1,28 +1,21 @@
|
|||
import createProdConfig from '@lib/webpack/prod';
|
||||
import compile from './compile';
|
||||
import {validate} from 'webpack';
|
||||
import loadSetup from '../loadSetup';
|
||||
|
||||
describe('webpack production config', () => {
|
||||
const timeOut = 20000; // 20 seconds
|
||||
test(
|
||||
'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('simple', async () => {
|
||||
console.log = jest.fn();
|
||||
const props = await loadSetup('simple');
|
||||
const config = createProdConfig(props).toConfig();
|
||||
const errors = validate(config);
|
||||
expect(errors.length).toBe(0);
|
||||
});
|
||||
|
||||
test(
|
||||
'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
|
||||
);
|
||||
test('custom', async () => {
|
||||
console.log = jest.fn();
|
||||
const props = await loadSetup('custom');
|
||||
const config = createProdConfig(props).toConfig();
|
||||
const errors = validate(config);
|
||||
expect(errors.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue