test: update test webpack

This commit is contained in:
endiliey 2018-08-26 03:15:25 +08:00
parent be3d259ac8
commit 3530cbe173
3 changed files with 98 additions and 66 deletions

View file

@ -2,10 +2,10 @@
exports[`genRoutesConfig website with no docs/pages 1`] = ` exports[`genRoutesConfig website with no docs/pages 1`] = `
"import React from 'react'; "import React from 'react';
import Loadable from 'react-loadable';
import Loading from '@theme/Loading';
import Docs from '@theme/Docs'; import Docs from '@theme/Docs';
import NotFound from '@theme/NotFound'; import NotFound from '@theme/NotFound';
const routes = [,, const routes = [,,
{ {
path: '*', path: '*',
@ -18,39 +18,46 @@ export default routes;
exports[`genRoutesConfig website with only docs 1`] = ` exports[`genRoutesConfig website with only docs 1`] = `
"import React from 'react'; "import React from 'react';
import Loadable from 'react-loadable';
import Loading from '@theme/Loading';
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';
import MDFooBar from '@docs/foo/bar.md';
import MDFooBaz from '@docs/foo/baz.md';
const routes = [ const routes = [
{ {
path: \\"/hello\\", path: \\"/hello\\",
exact: true, exact: true,
component: (props) => ( component: Loadable({
<Docs {...props}> loader: () => import('@docs/hello.md'),
<MDHello /> loading: Loading,
</Docs> render(loaded, props) {
) let Content = loaded.default;
return <Docs {...props}><Content /></Docs>;
}
})
}, },
{ {
path: \\"/foo/bar\\", path: \\"/foo/bar\\",
exact: true, exact: true,
component: (props) => ( component: Loadable({
<Docs {...props}> loader: () => import('@docs/foo/bar.md'),
<MDFooBar /> loading: Loading,
</Docs> render(loaded, props) {
) let Content = loaded.default;
return <Docs {...props}><Content /></Docs>;
}
})
}, },
{ {
path: \\"/foo/baz\\", path: \\"/foo/baz\\",
exact: true, exact: true,
component: (props) => ( component: Loadable({
<Docs {...props}> loader: () => import('@docs/foo/baz.md'),
<MDFooBaz /> loading: Loading,
</Docs> render(loaded, props) {
) let Content = loaded.default;
return <Docs {...props}><Content /></Docs>;
}
})
},, },,
{ {
path: '*', path: '*',
@ -63,33 +70,42 @@ export default routes;
exports[`genRoutesConfig website with only pages 1`] = ` exports[`genRoutesConfig website with only pages 1`] = `
"import React from 'react'; "import React from 'react';
import Loadable from 'react-loadable';
import Loading from '@theme/Loading';
import Docs from '@theme/Docs'; import Docs from '@theme/Docs';
import NotFound from '@theme/NotFound'; import NotFound from '@theme/NotFound';
import JSFoo from '@pages/foo.js';
import JSIndex from '@pages/index.js';
import JSBarBaz from '@pages/bar/baz.js';
import JSFooIndex from '@pages/foo/index.js';
const routes = [, const routes = [,
{ {
path: \\"/foo\\", path: \\"/foo\\",
exact: true, exact: true,
component: JSFoo component: Loadable({
loader: () => import('@pages/foo.js'),
loading: Loading
})
}, },
{ {
path: \\"/\\", path: \\"/\\",
exact: true, exact: true,
component: JSIndex component: Loadable({
loader: () => import('@pages/index.js'),
loading: Loading
})
}, },
{ {
path: \\"/bar/baz\\", path: \\"/bar/baz\\",
exact: true, exact: true,
component: JSBarBaz component: Loadable({
loader: () => import('@pages/bar/baz.js'),
loading: Loading
})
}, },
{ {
path: \\"/foo/\\", path: \\"/foo/\\",
exact: true, exact: true,
component: JSFooIndex component: Loadable({
loader: () => import('@pages/foo/index.js'),
loading: Loading
})
}, },
{ {
path: '*', path: '*',
@ -102,62 +118,78 @@ export default routes;
exports[`genRoutesConfig website with pages and docs 1`] = ` exports[`genRoutesConfig website with pages and docs 1`] = `
"import React from 'react'; "import React from 'react';
import Loadable from 'react-loadable';
import Loading from '@theme/Loading';
import Docs from '@theme/Docs'; import Docs from '@theme/Docs';
import NotFound from '@theme/NotFound'; import NotFound from '@theme/NotFound';
import JSFoo from '@pages/foo.js';
import JSIndex from '@pages/index.js';
import JSBarBaz from '@pages/bar/baz.js';
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 = [ const routes = [
{ {
path: \\"/hello\\", path: \\"/hello\\",
exact: true, exact: true,
component: (props) => ( component: Loadable({
<Docs {...props}> loader: () => import('@docs/hello.md'),
<MDHello /> loading: Loading,
</Docs> render(loaded, props) {
) let Content = loaded.default;
}, return <Docs {...props}><Content /></Docs>;
{ }
path: \\"/foo/baz\\", })
exact: true,
component: (props) => (
<Docs {...props}>
<MDFooBaz />
</Docs>
)
}, },
{ {
path: \\"/foo/bar\\", path: \\"/foo/bar\\",
exact: true, exact: true,
component: (props) => ( component: Loadable({
<Docs {...props}> loader: () => import('@docs/foo/bar.md'),
<MDFooBar /> loading: Loading,
</Docs> render(loaded, props) {
) let Content = loaded.default;
return <Docs {...props}><Content /></Docs>;
}
})
},
{
path: \\"/foo/baz\\",
exact: true,
component: Loadable({
loader: () => import('@docs/foo/baz.md'),
loading: Loading,
render(loaded, props) {
let Content = loaded.default;
return <Docs {...props}><Content /></Docs>;
}
})
}, },
{ {
path: \\"/foo\\", path: \\"/foo\\",
exact: true, exact: true,
component: JSFoo component: Loadable({
loader: () => import('@pages/foo.js'),
loading: Loading
})
}, },
{ {
path: \\"/\\", path: \\"/\\",
exact: true, exact: true,
component: JSIndex component: Loadable({
loader: () => import('@pages/index.js'),
loading: Loading
})
}, },
{ {
path: \\"/bar/baz\\", path: \\"/bar/baz\\",
exact: true, exact: true,
component: JSBarBaz component: Loadable({
loader: () => import('@pages/bar/baz.js'),
loading: Loading
})
}, },
{ {
path: \\"/foo/\\", path: \\"/foo/\\",
exact: true, exact: true,
component: JSFooIndex component: Loadable({
loader: () => import('@pages/foo/index.js'),
loading: Loading
})
}, },
{ {
path: '*', path: '*',

View file

@ -1,4 +1,4 @@
import createDevConfig from '@lib/webpack/dev'; import createClientConfig from '@lib/webpack/client';
import {validate} from 'webpack'; import {validate} from 'webpack';
import loadSetup from '../loadSetup'; import loadSetup from '../loadSetup';
@ -6,7 +6,7 @@ describe('webpack dev config', () => {
test('simple', async () => { test('simple', async () => {
console.log = jest.fn(); console.log = jest.fn();
const props = await loadSetup('simple'); const props = await loadSetup('simple');
const config = createDevConfig(props).toConfig(); const config = createClientConfig(props).toConfig();
const errors = validate(config); const errors = validate(config);
expect(errors.length).toBe(0); expect(errors.length).toBe(0);
}); });
@ -14,7 +14,7 @@ describe('webpack dev config', () => {
test('custom', async () => { test('custom', async () => {
console.log = jest.fn(); console.log = jest.fn();
const props = await loadSetup('custom'); const props = await loadSetup('custom');
const config = createDevConfig(props).toConfig(); const config = createClientConfig(props).toConfig();
const errors = validate(config); const errors = validate(config);
expect(errors.length).toBe(0); expect(errors.length).toBe(0);
}); });

View file

@ -1,4 +1,4 @@
import createProdConfig from '@lib/webpack/prod'; import createServerConfig from '@lib/webpack/server';
import {validate} from 'webpack'; import {validate} from 'webpack';
import loadSetup from '../loadSetup'; import loadSetup from '../loadSetup';
@ -6,7 +6,7 @@ describe('webpack production config', () => {
test('simple', async () => { test('simple', async () => {
console.log = jest.fn(); console.log = jest.fn();
const props = await loadSetup('simple'); const props = await loadSetup('simple');
const config = createProdConfig(props).toConfig(); const config = createServerConfig(props).toConfig();
const errors = validate(config); const errors = validate(config);
expect(errors.length).toBe(0); expect(errors.length).toBe(0);
}); });
@ -14,7 +14,7 @@ describe('webpack production config', () => {
test('custom', async () => { test('custom', async () => {
console.log = jest.fn(); console.log = jest.fn();
const props = await loadSetup('custom'); const props = await loadSetup('custom');
const config = createProdConfig(props).toConfig(); const config = createServerConfig(props).toConfig();
const errors = validate(config); const errors = validate(config);
expect(errors.length).toBe(0); expect(errors.length).toBe(0);
}); });