From 26e87d1e63cfead9f1735f8e849675223a9fc6e2 Mon Sep 17 00:00:00 2001 From: Charlike Mike Reagent Date: Wed, 25 Oct 2017 04:23:22 +0300 Subject: [PATCH] major(release): add tests Signed-off-by: Charlike Mike Reagent --- package.json | 1 + src/gzip-plugin.js | 2 +- test/index.js | 36 +++++++++++++++++++++++++++++++++--- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 2b592e1..e6cdd03 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "devDependencies": { "hela": "1.3.12", "hela-config-tunnckocore": "2.0.0", + "isobject": "3.0.1", "mukla": "0.4.9", "rollup": "0.50.0" }, diff --git a/src/gzip-plugin.js b/src/gzip-plugin.js index 515bc37..e96135e 100644 --- a/src/gzip-plugin.js +++ b/src/gzip-plugin.js @@ -13,7 +13,7 @@ module.exports = function gzip (options) { const opts = Object.assign({ minSize: 0 }, options); return { - name: 'gzip', + name: 'just-gzip', onwrite: (details) => { // fallbacks for Rollup < 0.48 diff --git a/test/index.js b/test/index.js index c003fa9..2aaf402 100644 --- a/test/index.js +++ b/test/index.js @@ -4,8 +4,38 @@ */ const test = require('mukla'); -const fn = require('../src/index.js'); +const isObject = require('isobject'); +const plugin = require('../src/index.js'); -test('foo bar', () => { - test.ok(fn); +test('returns an object with banner, plugins, external', (done) => { + const opts = plugin(); + test.strictEqual(isObject(opts), true); + test.strictEqual(typeof opts.banner, 'string'); + test.ok(opts.plugins); + done(); +}); + +test('includes the uglify plugin when opts.uglify: true', (done) => { + const { plugins } = plugin({ uglify: true }); + const [uglifyPlugin] = plugins.filter(({ name }) => name === 'uglify'); + + test.strictEqual(isObject(uglifyPlugin), true); + test.strictEqual(uglifyPlugin.name, 'uglify'); + done(); +}); + +test('includes the gzip plugin when opts.gzip: true', (done) => { + const config = plugin({ gzip: true }); + const plugins = config.plugins.filter(({ name }) => name === 'just-gzip'); + + test.strictEqual(plugins.length, 1); + done(); +}); + +test('should includes node-resolve plugin when opts.resolve exist', (done) => { + const cfg = plugin({ resolve: 'pify' }); + + test.strictEqual(cfg.plugins.length, 3); + test.strictEqual(cfg.plugins[1].name, 'node-resolve'); + done(); });