Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(format): use a consistent format
Utilize the `xo` module to enforce a consistent JavaScript code format throughout the module code and unit tests.
- Loading branch information
1 parent
03c672a
commit 735e04d
Showing
12 changed files
with
403 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,100 @@ | ||
'use strict'; | ||
var test = require('tape'), | ||
Vinyl = require('vinyl'), | ||
gulpUglify = require('../'); | ||
|
||
|
||
test('should preserve all comments', function(t) { | ||
t.plan(3); | ||
|
||
var testFile1 = new Vinyl({ | ||
cwd: "/home/terin/broken-promises/", | ||
base: "/home/terin/broken-promises/test", | ||
path: "/home/terin/broken-promises/test/test1.js", | ||
contents: new Buffer('/* comment one *//*! comment two *//* comment three */') | ||
}); | ||
|
||
var stream = gulpUglify({ preserveComments: 'all' }); | ||
|
||
stream.on('data', function(newFile) { | ||
var contents = newFile.contents.toString(); | ||
t.ok(/one/.test(contents), 'has comment one'); | ||
t.ok(/two/.test(contents), 'has comment two'); | ||
t.ok(/three/.test(contents), 'has comment three'); | ||
}); | ||
|
||
stream.write(testFile1); | ||
stream.end(); | ||
var test = require('tape'); | ||
var Vinyl = require('vinyl'); | ||
var gulpUglify = require('../'); | ||
|
||
test('should preserve all comments', function (t) { | ||
t.plan(3); | ||
|
||
var testFile1 = new Vinyl({ | ||
cwd: '/home/terin/broken-promises/', | ||
base: '/home/terin/broken-promises/test', | ||
path: '/home/terin/broken-promises/test/test1.js', | ||
contents: new Buffer('/* comment one *//*! comment two *//* comment three */') | ||
}); | ||
|
||
var stream = gulpUglify({preserveComments: 'all'}); | ||
|
||
stream.on('data', function (newFile) { | ||
var contents = newFile.contents.toString(); | ||
t.ok(/one/.test(contents), 'has comment one'); | ||
t.ok(/two/.test(contents), 'has comment two'); | ||
t.ok(/three/.test(contents), 'has comment three'); | ||
}); | ||
|
||
stream.write(testFile1); | ||
stream.end(); | ||
}); | ||
|
||
test('should preserve some comments', function(t) { | ||
t.plan(3); | ||
test('should preserve some comments', function (t) { | ||
t.plan(3); | ||
|
||
var testFile1 = new Vinyl({ | ||
cwd: "/home/terin/broken-promises/", | ||
base: "/home/terin/broken-promises/test", | ||
path: "/home/terin/broken-promises/test/test1.js", | ||
contents: new Buffer('/* comment one *//*! comment two *//* comment three */') | ||
}); | ||
var testFile1 = new Vinyl({ | ||
cwd: '/home/terin/broken-promises/', | ||
base: '/home/terin/broken-promises/test', | ||
path: '/home/terin/broken-promises/test/test1.js', | ||
contents: new Buffer('/* comment one *//*! comment two *//* comment three */') | ||
}); | ||
|
||
var stream = gulpUglify({ preserveComments: 'some' }); | ||
var stream = gulpUglify({preserveComments: 'some'}); | ||
|
||
stream.on('data', function(newFile) { | ||
var contents = newFile.contents.toString(); | ||
t.false(/one/.test(contents), 'does not have comment one'); | ||
t.ok(/two/.test(contents), 'has comment two'); | ||
t.false(/three/.test(contents), 'does not have comment three'); | ||
}); | ||
stream.on('data', function (newFile) { | ||
var contents = newFile.contents.toString(); | ||
t.false(/one/.test(contents), 'does not have comment one'); | ||
t.ok(/two/.test(contents), 'has comment two'); | ||
t.false(/three/.test(contents), 'does not have comment three'); | ||
}); | ||
|
||
stream.write(testFile1); | ||
stream.end(); | ||
stream.write(testFile1); | ||
stream.end(); | ||
}); | ||
|
||
test('should preserve license comments', function(t) { | ||
t.plan(3); | ||
test('should preserve license comments', function (t) { | ||
t.plan(3); | ||
|
||
var testFile1 = new Vinyl({ | ||
cwd: "/home/terin/broken-promises/", | ||
base: "/home/terin/broken-promises/test", | ||
path: "/home/terin/broken-promises/test/test1.js", | ||
contents: new Buffer('"use strict";\nfunction foobar(){}\n/* comment one */\n/* comment two MIT */\nfunction itsatrap(){}\n/* comment three */') | ||
}); | ||
var testFile1 = new Vinyl({ | ||
cwd: '/home/terin/broken-promises/', | ||
base: '/home/terin/broken-promises/test', | ||
path: '/home/terin/broken-promises/test/test1.js', | ||
contents: new Buffer('"use strict";\nfunction foobar(){}\n/* comment one */\n/* comment two MIT */\nfunction itsatrap(){}\n/* comment three */') | ||
}); | ||
|
||
var stream = gulpUglify({ preserveComments: 'license' }); | ||
var stream = gulpUglify({preserveComments: 'license'}); | ||
|
||
stream.on('data', function(newFile) { | ||
var contents = newFile.contents.toString(); | ||
t.false(/one/.test(contents), 'does not have comment one'); | ||
t.ok(/two/.test(contents), 'has comment two'); | ||
t.false(/three/.test(contents), 'does not have comment three'); | ||
}); | ||
stream.on('data', function (newFile) { | ||
var contents = newFile.contents.toString(); | ||
t.false(/one/.test(contents), 'does not have comment one'); | ||
t.ok(/two/.test(contents), 'has comment two'); | ||
t.false(/three/.test(contents), 'does not have comment three'); | ||
}); | ||
|
||
stream.write(testFile1); | ||
stream.end(); | ||
stream.write(testFile1); | ||
stream.end(); | ||
}); | ||
|
||
test('should preserve comments that fn returns true for', function(t) { | ||
t.plan(3); | ||
|
||
var testFile1 = new Vinyl({ | ||
cwd: "/home/terin/broken-promises/", | ||
base: "/home/terin/broken-promises/test", | ||
path: "/home/terin/broken-promises/test/test1.js", | ||
contents: new Buffer('/* comment one *//*! comment two *//* comment three */') | ||
}); | ||
|
||
var stream = gulpUglify({ | ||
preserveComments: function(node, comment) { | ||
return /three/.test(comment.value); | ||
} | ||
}); | ||
|
||
stream.on('data', function(newFile) { | ||
var contents = newFile.contents.toString(); | ||
t.false(/one/.test(contents), 'does not have comment one'); | ||
t.false(/two/.test(contents), 'does not have comment two'); | ||
t.true(/three/.test(contents), 'has comment three'); | ||
}); | ||
|
||
stream.write(testFile1); | ||
stream.end(); | ||
test('should preserve comments that fn returns true for', function (t) { | ||
t.plan(3); | ||
|
||
var testFile1 = new Vinyl({ | ||
cwd: '/home/terin/broken-promises/', | ||
base: '/home/terin/broken-promises/test', | ||
path: '/home/terin/broken-promises/test/test1.js', | ||
contents: new Buffer('/* comment one *//*! comment two *//* comment three */') | ||
}); | ||
|
||
var stream = gulpUglify({ | ||
preserveComments: function (node, comment) { | ||
return /three/.test(comment.value); | ||
} | ||
}); | ||
|
||
stream.on('data', function (newFile) { | ||
var contents = newFile.contents.toString(); | ||
t.false(/one/.test(contents), 'does not have comment one'); | ||
t.false(/two/.test(contents), 'does not have comment two'); | ||
t.true(/three/.test(contents), 'has comment three'); | ||
}); | ||
|
||
stream.write(testFile1); | ||
stream.end(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
'use strict'; | ||
var test = require('tape'), | ||
Vinyl = require('vinyl'), | ||
gulpUglify = require('../'); | ||
var test = require('tape'); | ||
var Vinyl = require('vinyl'); | ||
var gulpUglify = require('../'); | ||
|
||
var testContentsInput = 'function errorFunction(error)\n{'; | ||
var testOkContentsInput = '"use strict"; (function(console, first, second) { console.log(first + second) }(5, 10))'; | ||
|
||
var testFile1 = new Vinyl({ | ||
cwd: "/home/terin/broken-promises/", | ||
base: "/home/terin/broken-promises/test", | ||
path: "/home/terin/broken-promises/test/test1.js", | ||
contents: new Buffer(testContentsInput) | ||
cwd: '/home/terin/broken-promises/', | ||
base: '/home/terin/broken-promises/test', | ||
path: '/home/terin/broken-promises/test/test1.js', | ||
contents: new Buffer(testContentsInput) | ||
}); | ||
|
||
var testFile2 = new Vinyl({ | ||
cwd: "/home/terin/broken-promises/", | ||
base: "/home/terin/broken-promises/test", | ||
path: "/home/terin/broken-promises/test/test2.js", | ||
contents: new Buffer(testOkContentsInput) | ||
cwd: '/home/terin/broken-promises/', | ||
base: '/home/terin/broken-promises/test', | ||
path: '/home/terin/broken-promises/test/test2.js', | ||
contents: new Buffer(testOkContentsInput) | ||
}); | ||
|
||
test('should report files in error', function(t) { | ||
t.plan(6); | ||
test('should report files in error', function (t) { | ||
t.plan(6); | ||
|
||
var stream = gulpUglify(); | ||
var stream = gulpUglify(); | ||
|
||
stream.on('data', function() { | ||
t.fail('we shouldn\'t have gotten here'); | ||
}); | ||
stream.on('data', function () { | ||
t.fail('we shouldn\'t have gotten here'); | ||
}); | ||
|
||
stream.on('error', function(e) { | ||
t.ok(e instanceof Error, 'argument should be of type error'); | ||
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify'); | ||
t.equal(e.fileName, testFile1.path, 'error reports correct file name'); | ||
t.equal(e.lineNumber, 2, 'error reports correct line number'); | ||
t.ok(e.stack, 'error has a stack'); | ||
t.false(e.showStack, 'error is configured to not print the stack'); | ||
}); | ||
stream.on('error', function (e) { | ||
t.ok(e instanceof Error, 'argument should be of type error'); | ||
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify'); | ||
t.equal(e.fileName, testFile1.path, 'error reports correct file name'); | ||
t.equal(e.lineNumber, 2, 'error reports correct line number'); | ||
t.ok(e.stack, 'error has a stack'); | ||
t.false(e.showStack, 'error is configured to not print the stack'); | ||
}); | ||
|
||
stream.write(testFile1); | ||
stream.end(); | ||
stream.write(testFile1); | ||
stream.end(); | ||
}); | ||
|
||
test('shouldn\'t blow up when given output options', function(t) { | ||
t.plan(5); | ||
test('shouldn\'t blow up when given output options', function (t) { | ||
t.plan(5); | ||
|
||
var stream = gulpUglify({ | ||
output: { | ||
exportAll: true | ||
} | ||
}); | ||
var stream = gulpUglify({ | ||
output: { | ||
exportAll: true | ||
} | ||
}); | ||
|
||
stream.on('data', function() { | ||
t.fail('We shouldn\'t have gotten here'); | ||
}); | ||
stream.on('data', function () { | ||
t.fail('We shouldn\'t have gotten here'); | ||
}); | ||
|
||
stream.on('error', function(e) { | ||
t.ok(e instanceof Error, 'argument should be of type error'); | ||
t.equals(e.message, testFile2.path + ': `exportAll` is not a supported option'); | ||
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify'); | ||
t.equal(e.fileName, testFile2.path, 'error reports correct file name'); | ||
t.false(e.showStack, 'error is configured to not print the stack'); | ||
}); | ||
stream.on('error', function (e) { | ||
t.ok(e instanceof Error, 'argument should be of type error'); | ||
t.equals(e.message, testFile2.path + ': `exportAll` is not a supported option'); | ||
t.equal(e.plugin, 'gulp-uglify', 'error is from gulp-uglify'); | ||
t.equal(e.fileName, testFile2.path, 'error reports correct file name'); | ||
t.false(e.showStack, 'error is configured to not print the stack'); | ||
}); | ||
|
||
stream.write(testFile2); | ||
stream.end(); | ||
stream.write(testFile2); | ||
stream.end(); | ||
}); |
Oops, something went wrong.