Skip to content

Commit

Permalink
Merge pull request #140 from srod/es6
Browse files Browse the repository at this point in the history
feat(es6): refactor to es6
  • Loading branch information
srod authored Aug 12, 2018
2 parents 1263df7 + d3f5696 commit b5f99cd
Show file tree
Hide file tree
Showing 34 changed files with 2,255 additions and 1,688 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"extends": ["eslint:recommended", "prettier"],
"rules": {
"prettier/prettier": "error",
"no-console": 0
"no-console": 0,
"no-var": "error",
"strict": [2, "never"]
},
"parserOptions": {
"sourceType": "module"
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ node_modules
coverage
dist
.history
dist
26 changes: 2 additions & 24 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,2 @@
.DS_Store
.idea
.vscode
._*
.history
docs
node_modules
coverage
examples
__tests__
.circleci
.editorconfig
.eslintrc
.gitignore
.npmignore
.npmrc
.prettierignore
.travis.yml
.yarnrc
appveyor.yml
codecov.yml
static/cli.png
static/node-minify.png
yarn.lock
*
!lib/*
100 changes: 49 additions & 51 deletions __tests__/cli-test.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,64 @@
'use strict';
/*!
* node-minify
* Copyright(c) 2011-2018 Rodolphe Stoclin
* MIT Licensed
*/

jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;

var childProcess = require('child_process');
var nodeMinify = require('../lib/node-minify');
var cli = require('../lib/cli');
var utils = require('../lib/utils');
import childProcess from 'child_process';
import * as cli from '../lib/cli';
import { utils } from '../lib/utils';

describe('cli', function() {
test('should minify to have been called', function() {
var spy = jest.spyOn(nodeMinify, 'minify');
cli({
compressor: 'gcc',
input: 'examples/public/js/sample.js',
output: 'examples/public/js-dist/babili-es6.js',
option: '{"createSourceMap": true}'
});
expect(spy).toHaveBeenCalled();
describe('cli', () => {
test('should minify to have been called with gcc', () => {
const spy = jest.spyOn(cli, 'run');
return cli
.run({
compressor: 'gcc',
input: 'examples/public/js/sample.js',
output: 'examples/public/js-dist/babili-es6.js',
option: '{"createSourceMap": true}'
})
.then(() => expect(spy).toHaveBeenCalled());
});
test('should minify to have been called with all compressors', function() {
var spy = jest.spyOn(nodeMinify, 'minify');
return cli({
compressor: 'all',
input: 'examples/public/js/sample.js',
output: 'examples/public/js-dist/babili-es6.js'
}).then(function() {
expect(spy).toHaveBeenCalled();
});
test('should minify to have been called with all compressors', () => {
const spy = jest.spyOn(cli, 'run');
return cli
.run({
compressor: 'all',
input: 'examples/public/js/sample.js',
output: 'examples/public/js-dist/babili-es6.js'
})
.then(() => expect(spy).toHaveBeenCalled());
});
});

describe('cli error', function() {
beforeEach(function() {
spyOn(childProcess, 'spawn').and.throwError('UnsupportedClassVersionError');
});
test('should minify to throw with all compressors', function() {
var spy = jest.spyOn(nodeMinify, 'minify');
return cli({
compressor: 'gcc-java',
input: 'examples/public/js/sample.js',
output: 'examples/public/js-dist/babili-es6.js'
}).catch(function(err) {
expect(spy).toHaveBeenCalled();
return expect(err.message).toMatch(
/(UnsupportedClassVersionError)|(Latest Google Closure Compiler requires Java >= 1.7, please update Java or use gcc-legacy)/
);
});
describe('cli error', () => {
beforeEach(() => spyOn(childProcess, 'spawn').and.throwError('UnsupportedClassVersionError'));
test('should minify to throw with gcc error', () => {
const spy = jest.spyOn(cli, 'run');
return cli
.run({
compressor: 'gcc-java',
input: 'examples/public/js/sample.js',
output: 'examples/public/js-dist/babili-es6.js'
})
.catch(err => {
expect(spy).toHaveBeenCalled();
return expect(err.message).toMatch(
/(UnsupportedClassVersionError)|(Latest Google Closure Compiler requires Java >= 1.7, please update Java or use gcc-legacy)/
);
});
});
});

describe('pretty bytes', function() {
test('should throw when not a number', function() {
expect(function() {
utils.prettyBytes('a');
}).toThrow();
describe('pretty bytes', () => {
test('should throw when not a number', () => {
expect(() => utils.prettyBytes('a')).toThrow();
});

test('should return a negative number', function() {
expect(utils.prettyBytes(-1)).toBe('-1 B');
});
test('should return a negative number', () => expect(utils.prettyBytes(-1)).toBe('-1 B'));

test('should return 0', function() {
expect(utils.prettyBytes(0)).toBe('0 B');
});
test('should return 0', () => expect(utils.prettyBytes(0)).toBe('0 B'));
});
Loading

0 comments on commit b5f99cd

Please sign in to comment.