chore: eslint & prettier nits

This commit is contained in:
endiliey 2018-08-11 02:54:34 +08:00
parent a4cc782858
commit 15ce4a95e2
4 changed files with 68 additions and 69 deletions

View file

@ -1 +1,3 @@
generated generated
__fixtures__
dist

View file

@ -68,7 +68,6 @@
"semver": "^5.5.0", "semver": "^5.5.0",
"static-site-generator-webpack-plugin": "^3.4.1", "static-site-generator-webpack-plugin": "^3.4.1",
"webpack": "^4.16.3", "webpack": "^4.16.3",
"webpack-bundle-analyzer": "^2.13.1",
"webpack-chain": "^4.8.0", "webpack-chain": "^4.8.0",
"webpack-nicelog": "^2.2.1", "webpack-nicelog": "^2.2.1",
"webpack-serve": "^2.0.2" "webpack-serve": "^2.0.2"

View file

@ -1,19 +1,19 @@
import path from 'path'; import path from 'path';
import load from '@lib/load'; import load from '@lib/load';
// Helper methods to setup dummy/ fake projects // Helper methods to setup dummy/ fake projects
const loadSetup = async name => { const loadSetup = async name => {
const simpleWebsite = path.join(__dirname, '__fixtures__', 'simple-website'); const simpleWebsite = path.join(__dirname, '__fixtures__', 'simple-website');
const customWebsite = path.join(__dirname, '__fixtures__', 'custom-website'); const customWebsite = path.join(__dirname, '__fixtures__', 'custom-website');
switch (name) { switch (name) {
case 'simple': case 'simple':
return await load(simpleWebsite); return load(simpleWebsite);
case 'custom': case 'custom':
return await load(customWebsite); return load(customWebsite);
default: default:
return {}; return {};
} }
}; };
export default loadSetup; export default loadSetup;

View file

@ -1,48 +1,46 @@
import webpack from 'webpack'; import webpack from 'webpack';
import path from 'path'; import createDevConfig from '@lib/webpack/dev';
import createBaseConfig from '@lib/webpack/base'; import createProdConfig from '@lib/webpack/prod';
import createDevConfig from '@lib/webpack/dev'; import loadSetup from '../loadSetup';
import createProdConfig from '@lib/webpack/prod';
import loadSetup from '../loadSetup'; // webpack compiler helper function
function compile(config) {
// webpack compiler helper function return new Promise((resolve, reject) => {
function compile(config) { webpack(config, (err, stats) => {
return new Promise((resolve, reject) => { if (err || stats.hasErrors()) {
webpack(config, (err, stats) => { reject(new Error(`Failed to compile with errors`));
if (err || stats.hasErrors()) { }
reject(new Error(`Failed to compile with errors`)); resolve('Compiled successfully');
} });
resolve('Compiled successfully'); });
}); }
});
} describe('webpack', () => {
test('dev simple', async () => {
describe('webpack', () => { console.log = jest.fn();
test('dev simple', async () => { const props = await loadSetup('simple');
console.log = jest.fn(); const config = createDevConfig(props).toConfig();
const props = await loadSetup('simple'); return expect(compile(config)).resolves.toBe('Compiled successfully');
const config = createDevConfig(props).toConfig(); });
return expect(compile(config)).resolves.toBe('Compiled successfully');
}); test('dev custom', async () => {
console.log = jest.fn();
test('dev custom', async () => { const props = await loadSetup('custom');
console.log = jest.fn(); const config = createDevConfig(props).toConfig();
const props = await loadSetup('custom'); return expect(compile(config)).resolves.toBe('Compiled successfully');
const config = createDevConfig(props).toConfig(); });
return expect(compile(config)).resolves.toBe('Compiled successfully');
}); test('prod simple', async () => {
console.log = jest.fn();
test('prod simple', async () => { const props = await loadSetup('simple');
console.log = jest.fn(); const config = createProdConfig(props).toConfig();
const props = await loadSetup('simple'); return expect(compile(config)).resolves.toBe('Compiled successfully');
const config = createProdConfig(props).toConfig(); });
return expect(compile(config)).resolves.toBe('Compiled successfully');
}); test('prod custom', async () => {
console.log = jest.fn();
test('prod custom', async () => { const props = await loadSetup('custom');
console.log = jest.fn(); const config = createProdConfig(props).toConfig();
const props = await loadSetup('custom'); return expect(compile(config)).resolves.toBe('Compiled successfully');
const config = createProdConfig(props).toConfig(); });
return expect(compile(config)).resolves.toBe('Compiled successfully'); });
});
});