Skip to content

Commit 614ff99

Browse files
author
Myles Borins
committed
update tests to use Buffer.from
Using Buffer without new will soon stop working. It will throw A deprecation warning in Node v7. This commit modifies the tests in `test/bare.js` and `test/bare_shebang.js` to use the `Buffer.from` interface instead. It is a drop in replacement for Buffer that is supported by Node v4 / v6 and Browserify's Buffer implementation For the browserify test suite to pass on Node v7 we will need to land this commit as well as the two below PR's * browserify/browser-pack#75 * max-mapper/concat-stream#48
1 parent 8f5ebbf commit 614ff99

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

test.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/bare.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ test('bare', function (t) {
1616
]);
1717
ps.stdout.pipe(concat(function (body) {
1818
vm.runInNewContext(body, {
19-
Buffer: function (s) { return s.toLowerCase() },
19+
Buffer: {
20+
from: function (s) { return s.toLowerCase() }
21+
},
2022
console: {
2123
log: function (msg) { t.equal(msg, 'abc') }
2224
}
2325
});
2426
vm.runInNewContext(body, {
25-
Buffer: Buffer,
27+
Buffer: {
28+
from: Buffer.from
29+
},
2630
console: {
2731
log: function (msg) {
2832
t.ok(Buffer.isBuffer(msg));
@@ -31,7 +35,7 @@ test('bare', function (t) {
3135
}
3236
});
3337
}));
34-
ps.stdin.end('console.log(Buffer("ABC"))');
38+
ps.stdin.end('console.log(Buffer.from("ABC"))');
3539

3640
ps.on('exit', function (code) {
3741
t.equal(code, 0);

test/bare_shebang.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ test('bare shebang', function (t) {
1414
ps.stderr.pipe(process.stderr);
1515
ps.stdout.pipe(concat(function (body) {
1616
vm.runInNewContext(body, {
17-
Buffer: function (s) { return s.toLowerCase() },
17+
Buffer: {
18+
from: function (s) { return s.toLowerCase() }
19+
},
1820
console: {
1921
log: function (msg) { t.equal(msg, 'woo') }
2022
}
2123
});
2224
vm.runInNewContext(body, {
23-
Buffer: Buffer,
25+
Buffer: {
26+
from: Buffer.from
27+
},
2428
console: {
2529
log: function (msg) {
2630
t.ok(Buffer.isBuffer(msg));
@@ -29,7 +33,7 @@ test('bare shebang', function (t) {
2933
}
3034
});
3135
}));
32-
ps.stdin.end('#!/usr/bin/env node\nconsole.log(Buffer("WOO"))');
36+
ps.stdin.end('#!/usr/bin/env node\nconsole.log(Buffer.from("WOO"))');
3337

3438
ps.on('exit', function (code) {
3539
t.equal(code, 0);

0 commit comments

Comments
 (0)