Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing package.json to use concat-stream "^2.0.0" and tap "^12.5.3"… #1899

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"make-generator-function": "^1.1.0",
"semver": "^5.5.0",
"seq": "0.3.5",
"tap": "^10.7.2",
"tap": "~12.4.0",
"temp": "^0.8.1",
"through": "^2.3.4"
},
Expand Down
4 changes: 2 additions & 2 deletions test/bare.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ test('bare', function (t) {
}
});
vm.runInNewContext(body, {
Buffer: Buffer,
Buffer: function (s) { return Buffer.from ? Buffer.from(s) : Buffer(s) },
console: {
log: function (msg) {
t.ok(Buffer.isBuffer(msg));
Expand Down Expand Up @@ -57,7 +57,7 @@ test('bare api', function (t) {
}
});
vm.runInNewContext(body, {
Buffer: Buffer,
Buffer: function (s) { return Buffer.from ? Buffer.from(s) : Buffer(s) },
console: {
log: function (msg) {
t.ok(Buffer.isBuffer(msg));
Expand Down
2 changes: 1 addition & 1 deletion test/bare_shebang.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('bare shebang', function (t) {
}
});
vm.runInNewContext(body, {
Buffer: Buffer,
Buffer: function (s) { return Buffer.from ? Buffer.from(s) : Buffer(s) },
console: {
log: function (msg) {
t.ok(Buffer.isBuffer(msg));
Expand Down
124 changes: 91 additions & 33 deletions test/buffer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
var browserify = require('../');
var test = require('tap').test;
var vm = require('vm');
var usesSafeBuffer = Buffer.from ? true : false;

if (!ArrayBuffer.isView) ArrayBuffer.isView = function () { return false; };


test('utf8 buffer to base64', function (t) {
t.plan(1);
var b = browserify();
Expand All @@ -12,10 +14,17 @@ test('utf8 buffer to base64', function (t) {
if (err) return t.fail(err);
var c = context();
vm.runInNewContext(src, c);
t.equal(
new c.require('buffer').Buffer("Ձאab", "utf8").toString("base64"),
new Buffer("Ձאab", "utf8").toString("base64")
);
if (usesSafeBuffer) {
t.equal(
new c.require('buffer').Buffer.from("Ձאab", "utf8").toString("base64"),
new Buffer.from("Ձאab", "utf8").toString("base64")
);
} else {
t.equal(
new c.require('buffer').Buffer("Ձאab", "utf8").toString("base64"),
new Buffer("Ձאab", "utf8").toString("base64")
);
}
});
});

Expand All @@ -26,10 +35,17 @@ test('utf8 buffer to hex', function (t) {
b.bundle(function (err, src) {
var c = context();
vm.runInNewContext(src, c);
t.equal(
new c.require('buffer').Buffer("Ձאab", "utf8").toString("hex"),
new Buffer("Ձאab", "utf8").toString("hex")
);
if (usesSafeBuffer) {
t.equal(
new c.require('buffer').Buffer.from("Ձאab", "utf8").toString("hex"),
new Buffer.from("Ձאab", "utf8").toString("hex")
);
} else {
t.equal(
new c.require('buffer').Buffer("Ձאab", "utf8").toString("hex"),
new Buffer("Ձאab", "utf8").toString("hex")
);
}
});
});

Expand All @@ -41,10 +57,17 @@ test('ascii buffer to base64', function (t) {
b.bundle(function (err, src) {
var c = context();
vm.runInNewContext(src, c);
t.equal(
new c.require('buffer').Buffer("123456!@#$%^", "ascii").toString("base64"),
new Buffer("123456!@#$%^", "ascii").toString("base64")
);
if (usesSafeBuffer) {
t.equal(
new c.require('buffer').Buffer.from("123456!@#$%^", "ascii").toString("base64"),
new Buffer.from("123456!@#$%^", "ascii").toString("base64")
);
} else {
t.equal(
new c.require('buffer').Buffer("123456!@#$%^", "ascii").toString("base64"),
new Buffer("123456!@#$%^", "ascii").toString("base64")
);
}
});
});

Expand All @@ -55,10 +78,17 @@ test('ascii buffer to hex', function (t) {
b.bundle(function (err, src) {
var c = context();
vm.runInNewContext(src, c);
t.equal(
new c.require('buffer').Buffer("123456!@#$%^", "ascii").toString("hex"),
new Buffer("123456!@#$%^", "ascii").toString("hex")
);
if (usesSafeBuffer) {
t.equal(
new c.require('buffer').Buffer.from("123456!@#$%^", "ascii").toString("hex"),
new Buffer.from("123456!@#$%^", "ascii").toString("hex")
);
} else {
t.equal(
new c.require('buffer').Buffer("123456!@#$%^", "ascii").toString("hex"),
new Buffer("123456!@#$%^", "ascii").toString("hex")
);
}
});
});

Expand All @@ -69,10 +99,17 @@ test('base64 buffer to utf8', function (t) {
b.bundle(function (err, src) {
var c = context();
vm.runInNewContext(src, c);
t.equal(
new c.require('buffer').Buffer("1YHXkGFi", "base64").toString("utf8"),
new Buffer("1YHXkGFi", "base64").toString("utf8")
);
if (usesSafeBuffer) {
t.equal(
new c.require('buffer').Buffer.from("1YHXkGFi", "base64").toString("utf8"),
new Buffer.from("1YHXkGFi", "base64").toString("utf8")
);
} else {
t.equal(
new c.require('buffer').Buffer("1YHXkGFi", "base64").toString("utf8"),
new Buffer("1YHXkGFi", "base64").toString("utf8")
);
}
});
});

Expand All @@ -84,10 +121,17 @@ test('hex buffer to utf8', function (t) {
var c = context();
vm.runInNewContext(src, c);
var B = c.require('buffer');
t.equal(
new B.Buffer("d581d7906162", "hex").toString("utf8"),
new Buffer("d581d7906162", "hex").toString("utf8")
);
if (usesSafeBuffer) {
t.equal(
new B.Buffer.from("d581d7906162", "hex").toString("utf8"),
new Buffer.from("d581d7906162", "hex").toString("utf8")
);
} else {
t.equal(
new B.Buffer("d581d7906162", "hex").toString("utf8"),
new Buffer("d581d7906162", "hex").toString("utf8")
);
}
});
});

Expand All @@ -98,10 +142,17 @@ test('base64 buffer to ascii', function (t) {
b.bundle(function (err, src) {
var c = context();
vm.runInNewContext(src, c);
t.equal(
new c.require('buffer').Buffer("MTIzNDU2IUAjJCVe", "base64").toString("ascii"),
new Buffer("MTIzNDU2IUAjJCVe", "base64").toString("ascii")
);
if (usesSafeBuffer) {
t.equal(
new c.require('buffer').Buffer.from("MTIzNDU2IUAjJCVe", "base64").toString("ascii"),
new Buffer.from("MTIzNDU2IUAjJCVe", "base64").toString("ascii")
);
} else {
t.equal(
new c.require('buffer').Buffer("MTIzNDU2IUAjJCVe", "base64").toString("ascii"),
new Buffer("MTIzNDU2IUAjJCVe", "base64").toString("ascii")
);
}
});
});

Expand All @@ -112,10 +163,17 @@ test('hex buffer to ascii', function (t) {
b.bundle(function (err, src) {
var c = context();
vm.runInNewContext(src, c);
t.equal(
new c.require('buffer').Buffer("31323334353621402324255e", "hex").toString("ascii"),
new Buffer("31323334353621402324255e", "hex").toString("ascii")
);
if (usesSafeBuffer) {
t.equal(
new c.require('buffer').Buffer.from("31323334353621402324255e", "hex").toString("ascii"),
new Buffer.from("31323334353621402324255e", "hex").toString("ascii")
);
} else {
t.equal(
new c.require('buffer').Buffer("31323334353621402324255e", "hex").toString("ascii"),
new Buffer("31323334353621402324255e", "hex").toString("ascii")
);
}
});
});

Expand All @@ -126,7 +184,7 @@ test('indexing a buffer', function (t) {
b.bundle(function (err, src) {
var c = context();
vm.runInNewContext(src, c);
var buf = c.require('buffer').Buffer('abc');
var buf = c.require('buffer').Buffer.from('abc');
t.equal(buf[0], 97);
t.equal(buf[1], 98);
t.equal(buf[2], 99);
Expand Down