Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Commit

Permalink
Merge adc0e70 into 0b3802f
Browse files Browse the repository at this point in the history
  • Loading branch information
Amri91 committed Aug 17, 2018
2 parents 0b3802f + adc0e70 commit 57acfa7
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"lint": "eslint .",
"jest": "jest .",
"c": "git-cz",
"test": "npm run lint && npm run jest",
"release": "xyz --repo git@github.com:wearereasonablepeople/webpacker.git --increment"
},
Expand All @@ -34,6 +35,7 @@
"babel-preset-stage-2": "^6.24.1",
"chalk": "^2.4.1",
"chokidar": "^2.0.4",
"compression-webpack-plugin": "^1.1.11",
"connect-history-api-fallback": "^1.5.0",
"copy-webpack-plugin": "^4.5.2",
"css-loader": "^1.0.0",
Expand Down Expand Up @@ -70,6 +72,7 @@
"eslint": "^5.2.0",
"eslint-config-warp": "^3.0.0",
"eslint-plugin-jest": "^21.18.0",
"git-cz": "^1.7.1",
"jest-cli": "^23.4.2",
"jest-config": "^23.4.2",
"xyz": "^3.0.0"
Expand Down
7 changes: 7 additions & 0 deletions plugins/compress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const CompressionPlugin = require('compression-webpack-plugin');

module.exports = ({devServer}) => !devServer ? new CompressionPlugin({
test: /\.js$|\.css$|\.html$/,
threshold: 1024 * 10
}) : null;

2 changes: 2 additions & 0 deletions plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const css = require('./css');
const favicon = require('./favicon');
const html = require('./html');
const stats = require('./stats');
const compress = require('./compress');

module.exports = {
configure,
Expand All @@ -12,4 +13,5 @@ module.exports = {
favicon,
html,
stats,
compress
};
14 changes: 14 additions & 0 deletions tests/loaders/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const path = require('path');
const fs = require('fs');
const {promisify} = require('util');
const index = require('../../loaders');

const readDir = promisify(fs.readdir);

describe('Plugin index', () => {
it('Should return an option for each file in the loaders', async () => {
const files = await readDir(path.join(__dirname, '../../loaders'));
// - 2 because the utils and the index are not included.
expect(Object.keys(index).length).toBe(files.length - 2);
});
});
20 changes: 20 additions & 0 deletions tests/plugins/compress.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const compress = require('../../plugins/compress');

describe('Compression plugin', () => {
const defaults = {
options: {
test: /\.js$|\.css$|\.html$/,
threshold: 1024 * 10
},
};

it('should return the plugin with default values', () => {
expect(compress({})).toMatchObject(defaults);
});

describe('receives an options object to customize the config', () => {
it('allows to enable devServer and disable compression', () => {
expect(compress({devServer: true})).toBe(null);
});
});
});
13 changes: 13 additions & 0 deletions tests/plugins/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const path = require('path');
const fs = require('fs');
const {promisify} = require('util');
const index = require('../../plugins');

const readDir = promisify(fs.readdir);

describe('Plugin index', () => {
it('Should return an option for each file in the plugins', async () => {
const files = await readDir(path.join(__dirname, '../../plugins'));
expect(Object.keys(index).length).toBe(files.length - 1);
});
});

0 comments on commit 57acfa7

Please sign in to comment.