mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +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 Docs from '@theme/Docs';
|
||||||
import NotFound from '@theme/NotFound';
|
import NotFound from '@theme/NotFound';
|
||||||
|
|
||||||
|
import MDHello from '@docs/hello.md';
|
||||||
const routes = [,,
|
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: '*',
|
path: '*',
|
||||||
component: NotFound
|
component: NotFound
|
||||||
|
@ -77,10 +106,39 @@ import Docs from '@theme/Docs';
|
||||||
import NotFound from '@theme/NotFound';
|
import NotFound from '@theme/NotFound';
|
||||||
import JSFoo from '@pages/foo.js';
|
import JSFoo from '@pages/foo.js';
|
||||||
import JSIndex from '@pages/index.js';
|
import JSIndex from '@pages/index.js';
|
||||||
import JSFooIndex from '@pages/foo/index.js';
|
|
||||||
import JSBarBaz from '@pages/bar/baz.js';
|
import JSBarBaz from '@pages/bar/baz.js';
|
||||||
|
import JSFooIndex from '@pages/foo/index.js';
|
||||||
const routes = [,
|
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\\",
|
path: \\"/foo\\",
|
||||||
exact: true,
|
exact: true,
|
||||||
|
@ -91,16 +149,16 @@ const routes = [,
|
||||||
exact: true,
|
exact: true,
|
||||||
component: JSIndex
|
component: JSIndex
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: \\"/foo/\\",
|
|
||||||
exact: true,
|
|
||||||
component: JSFooIndex
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: \\"/bar/baz\\",
|
path: \\"/bar/baz\\",
|
||||||
exact: true,
|
exact: true,
|
||||||
component: JSBarBaz
|
component: JSBarBaz
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: \\"/foo/\\",
|
||||||
|
exact: true,
|
||||||
|
component: JSFooIndex
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '*',
|
path: '*',
|
||||||
component: NotFound
|
component: NotFound
|
||||||
|
|
|
@ -1,29 +1,21 @@
|
||||||
import createDevConfig from '@lib/webpack/dev';
|
import createBaseConfig from '@lib/webpack/base';
|
||||||
import compile from './compile';
|
import {validate} from 'webpack';
|
||||||
import loadSetup from '../loadSetup';
|
import loadSetup from '../loadSetup';
|
||||||
|
|
||||||
describe('webpack dev config', () => {
|
describe('webpack base config', () => {
|
||||||
const timeOut = 20000; // 20 seconds
|
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(
|
test('custom', async () => {
|
||||||
'simple',
|
console.log = jest.fn();
|
||||||
async () => {
|
const props = await loadSetup('custom');
|
||||||
console.log = jest.fn();
|
const config = createBaseConfig(props).toConfig();
|
||||||
const props = await loadSetup('simple');
|
const errors = validate(config);
|
||||||
const config = createDevConfig(props).toConfig();
|
expect(errors.length).toBe(0);
|
||||||
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
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -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 createProdConfig from '@lib/webpack/prod';
|
||||||
import compile from './compile';
|
import {validate} from 'webpack';
|
||||||
import loadSetup from '../loadSetup';
|
import loadSetup from '../loadSetup';
|
||||||
|
|
||||||
describe('webpack production config', () => {
|
describe('webpack production config', () => {
|
||||||
const timeOut = 20000; // 20 seconds
|
test('simple', async () => {
|
||||||
test(
|
console.log = jest.fn();
|
||||||
'simple',
|
const props = await loadSetup('simple');
|
||||||
async () => {
|
const config = createProdConfig(props).toConfig();
|
||||||
console.log = jest.fn();
|
const errors = validate(config);
|
||||||
const props = await loadSetup('simple');
|
expect(errors.length).toBe(0);
|
||||||
const config = createProdConfig(props).toConfig();
|
});
|
||||||
return expect(compile(config)).resolves.toBe('Compiled successfully');
|
|
||||||
},
|
|
||||||
timeOut
|
|
||||||
);
|
|
||||||
|
|
||||||
test(
|
test('custom', async () => {
|
||||||
'custom',
|
console.log = jest.fn();
|
||||||
async () => {
|
const props = await loadSetup('custom');
|
||||||
console.log = jest.fn();
|
const config = createProdConfig(props).toConfig();
|
||||||
const props = await loadSetup('custom');
|
const errors = validate(config);
|
||||||
const config = createProdConfig(props).toConfig();
|
expect(errors.length).toBe(0);
|
||||||
return expect(compile(config)).resolves.toBe('Compiled successfully');
|
});
|
||||||
},
|
|
||||||
timeOut
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue