1 | var test = require('tap').test;
|
2 | var browserify = require('browserify');
|
3 |
|
4 | var vm = require('vm');
|
5 | var path = require('path');
|
6 |
|
7 | if (!ArrayBuffer.isView) ArrayBuffer.isView = function () { return false; };
|
8 |
|
9 | test('sync string encoding', function (t) {
|
10 | t.plan(2);
|
11 | var b = browserify(__dirname + '/files/buffer.js');
|
12 | b.require('buffer', { expose: 'buffer' });
|
13 | b.transform(path.dirname(__dirname));
|
14 | b.bundle(function (err, src) {
|
15 | if (err) t.fail(err);
|
16 | var context = {
|
17 | setTimeout: setTimeout,
|
18 | console: { log: log },
|
19 | ArrayBuffer: ArrayBuffer,
|
20 | Uint8Array: Uint8Array,
|
21 | DataView: DataView
|
22 | };
|
23 | var buffers = [];
|
24 | vm.runInNewContext(src, context);
|
25 |
|
26 | t.ok(context.require('buffer').Buffer.isBuffer(buffers[0]), 'isBuffer');
|
27 | t.equal(buffers[0].toString('utf8'), '<b>beep boop</b>\n');
|
28 |
|
29 | function log (msg) { buffers.push(msg) }
|
30 | });
|
31 | });
|