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 Apr 4, 2018
1 parent b1a6cc3 commit 81fd08a
Show file tree
Hide file tree
Showing 36 changed files with 2,875 additions and 1,733 deletions.
5 changes: 0 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ workflows:
version: 2
node-multi-build:
jobs:
- node-v4
- node-v6
- node-v8
- node-v9
Expand Down Expand Up @@ -42,10 +41,6 @@ jobs:
- /usr/local/share/.cache/yarn
- /root/.cache/yarn

node-v4:
<<: *node-base
docker:
- image: circleci/node:4-browsers
node-v6:
<<: *node-base
docker:
Expand Down
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
21 changes: 2 additions & 19 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
.DS_Store
.idea
.vscode
._*
.history
node_modules
coverage
examples
__tests__
.circleci
.editorconfig
.gitignore
.npmignore
.npmrc
.travis.yml
.yarnrc
appveyor.yml
codecov.yml
yarn.lock
*
!lib/*
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ node_js:
- 9
- 8
- 6
- 4

before_install:
- curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.2.1
Expand Down
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 81fd08a

Please sign in to comment.