Skip to content

Commit

Permalink
Gulp Babili issue (#454)
Browse files Browse the repository at this point in the history
* fix gulp babili options for comments

* add test case

* fix lint issue

* better test case
  • Loading branch information
vigneshshanmugam authored and boopathi committed Mar 7, 2017
1 parent 9663c12 commit 269a8f9
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 12 deletions.
@@ -1,11 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`gulp-babili comments should remove all comments when false 1`] = `"foo(),bar(),baz();"`;
exports[`gulp-babili comments should remove all comments when false 1`] = `"function foo(){}bar();var a=baz();"`;

exports[`gulp-babili comments should remove comments by default except license and preserve 1`] = `
/**
* @license
* This is a test
*/"foo(),bar(),baz();"`;
"/**
* @license
* This is a test
*/function foo(){}bar();var a=baz();"
`;

exports[`gulp-babili comments should take a custom function 1`] = `"/* YAC - yet another comment */foo(),bar(),baz();"`;
exports[`gulp-babili comments should take a custom function 1`] = `"function foo(){}bar();/* YAC - yet another comment */var a=baz();"`;

exports[`gulp-babili should remove comments while doing DCE and simplify 1`] = `
"var a=function(){(function(){foo(),bar(),baz();// comments should be optimized away
})()};"
`;
56 changes: 50 additions & 6 deletions packages/gulp-babili/__tests__/gulp-babili-test.js
Expand Up @@ -106,11 +106,11 @@ describe("gulp-babili", () => {
* @license
* This is a test
*/
foo();
function foo(){}
// this is another comment
bar();
/* YAC - yet another comment */
baz();
var a = baz();
`);

let file;
Expand All @@ -122,7 +122,7 @@ describe("gulp-babili", () => {
});
});

xit("should remove comments by default except license and preserve", () => {
it("should remove comments by default except license and preserve", () => {
return new Promise((resolve, reject) => {
const stream = gulpBabili();
stream.on("data", function (file) {
Expand All @@ -136,7 +136,7 @@ describe("gulp-babili", () => {

it("should remove all comments when false", () => {
return new Promise((resolve, reject) => {
const stream = gulpBabili({
const stream = gulpBabili({}, {
comments: false
});
stream.on("data", () => {
Expand All @@ -148,9 +148,9 @@ describe("gulp-babili", () => {
});
});

xit("should take a custom function", () => {
it("should take a custom function", () => {
return new Promise((resolve, reject) => {
const stream = gulpBabili({
const stream = gulpBabili({}, {
comments(contents) {
return contents.indexOf("YAC") !== -1;
}
Expand All @@ -164,4 +164,48 @@ describe("gulp-babili", () => {
});
});
});

it("should remove comments while doing DCE and simplify", () => {
return new Promise((resolve, reject) => {
const stream = gulpBabili({}, {
comments(contents) {
return contents.indexOf("optimized") !== -1;
}
});

const source = unpad(`
/**
* @license
* throw away
*/
var a = function(){
// Hell yeah
function test(){
// comments should be optimized away
const flag = true;
if (flag) {
// comments
foo();
}
// remove this also
bar();
// should remove this as well
baz();
}
test();
}
`);

stream.on("data", function (file) {
expect(file.contents.toString()).toMatchSnapshot();
resolve();
});
stream.on("error", reject);

stream.write(new gutil.File({
path: "options.js",
contents: new Buffer(source)
}));
});
});
});

0 comments on commit 269a8f9

Please sign in to comment.