Skip to content

Commit

Permalink
refactor(es2015+): refactoring in es2015+ syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
srod committed Jun 12, 2018
1 parent a8bee65 commit d307914
Show file tree
Hide file tree
Showing 33 changed files with 2,491 additions and 1,870 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
node_modules
coverage
.history
dist
lib
25 changes: 2 additions & 23 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,2 @@
.DS_Store
.idea
.vscode
._*
.history
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.svg
yarn.lock
*
!lib/*
88 changes: 43 additions & 45 deletions __tests__/cli-test.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,63 @@
'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 { minify } from '../src/node-minify';
import * as cli from '../src/cli';
import { utils } from '../src/utils';

describe('cli', function() {
test('should minify to have been called', function() {
var spy = jest.spyOn(nodeMinify, 'minify');
cli({
describe('cli', () => {
test('should minify to have been called', () => {
const spy = jest.spyOn(cli, 'run');
cli.run({
compressor: 'gcc',
input: 'examples/public/js/sample.js',
output: 'examples/public/js-dist/babili-es6.js'
});
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: 'all',
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 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'
})
.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 d307914

Please sign in to comment.