mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-22 05:27:00 +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
7
test/__fixtures__/custom-website/siteConfig.js
Normal file
7
test/__fixtures__/custom-website/siteConfig.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
module.exports = {
|
||||
title: 'Sakura',
|
||||
tagline: 'This is not an ordinary site',
|
||||
organizationName: 'endiliey',
|
||||
projectName: 'sakura',
|
||||
baseUrl: '/sakura/'
|
||||
};
|
3
test/__fixtures__/simple-website/pages/bar/baz.js
Normal file
3
test/__fixtures__/simple-website/pages/bar/baz.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import React from 'react';
|
||||
|
||||
export default () => <div>Baz</div>;
|
3
test/__fixtures__/simple-website/pages/foo.js
Normal file
3
test/__fixtures__/simple-website/pages/foo.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import React from 'react';
|
||||
|
||||
export default () => <div>Foo</div>;
|
3
test/__fixtures__/simple-website/pages/foo/index.js
Normal file
3
test/__fixtures__/simple-website/pages/foo/index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import React from 'react';
|
||||
|
||||
export default () => <div>Foo in subfolder</div>;
|
3
test/__fixtures__/simple-website/pages/index.js
Normal file
3
test/__fixtures__/simple-website/pages/index.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import React from 'react';
|
||||
|
||||
export default () => <div>Index</div>;
|
7
test/__fixtures__/simple-website/siteConfig.js
Normal file
7
test/__fixtures__/simple-website/siteConfig.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
module.exports = {
|
||||
title: 'Hello',
|
||||
tagline: 'Hello World',
|
||||
organizationName: 'endiliey',
|
||||
projectName: 'hello',
|
||||
baseUrl: '/'
|
||||
};
|
19
test/loadSetup.js
Normal file
19
test/loadSetup.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
import path from 'path';
|
||||
import load from '@lib/load';
|
||||
|
||||
// Helper methods to setup dummy/ fake projects
|
||||
const loadSetup = async name => {
|
||||
const simpleWebsite = path.join(__dirname, '__fixtures__', 'simple-website');
|
||||
const customWebsite = path.join(__dirname, '__fixtures__', 'custom-website');
|
||||
|
||||
switch (name) {
|
||||
case 'simple':
|
||||
return await load(simpleWebsite);
|
||||
case 'custom':
|
||||
return await load(customWebsite);
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
export default loadSetup;
|
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