Skip to content

Commit

Permalink
Only run es6 node tests in browsers that support it
Browse files Browse the repository at this point in the history
  • Loading branch information
feross committed Apr 20, 2016
1 parent da047a3 commit 338d0f2
Show file tree
Hide file tree
Showing 26 changed files with 139 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.zuul.yml
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.zuul.yml
perf/
5 changes: 4 additions & 1 deletion bin/download-node-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function testfixer (filename) {
if (firstline) {
// require buffer explicitly
var preamble = 'var Buffer = require(\'../../\').Buffer;\n' +
'if (!Buffer.TYPED_ARRAY_SUPPORT) return;'
'if (Buffer.TYPED_ARRAY_SUPPORT) {'
if (/use strict/.test(line)) line += '\n' + preamble
else line + preamble + '\n' + line
firstline = false
Expand Down Expand Up @@ -103,5 +103,8 @@ function testfixer (filename) {
}

cb(null, line + '\n')
}, function (cb) {
// flush function
this.push('\n}')
})
}
35 changes: 29 additions & 6 deletions bin/test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
#!/usr/bin/env node

var cp = require('child_process')
var fs = require('fs')
var path = require('path')

var runBrowserTests = !process.env.TRAVIS_PULL_REQUEST ||
var shouldRunBrowserTests = !process.env.TRAVIS_PULL_REQUEST ||
process.env.TRAVIS_PULL_REQUEST === 'false'

var node = cp.spawn('npm', ['run', 'test-node'], { stdio: 'inherit' })
node.on('close', function (code) {
if (code === 0 && runBrowserTests) {
var browser = cp.spawn('npm', ['run', 'test-browser'], { stdio: 'inherit' })
browser.on('close', function (code) {
process.exit(code)
})
if (code === 0 && shouldRunBrowserTests) {
runBrowserTests()
} else {
process.exit(code)
}
})

function runBrowserTests () {
var zuulYmlPath = path.join(__dirname, '..', '.zuul.yml')

writeES5ZuulYml()
cp.spawn('npm', ['run', 'test-browser-es5'], { stdio: 'inherit' })
.on('close', function (code) {
if (code !== 0) process.exit(code)
writeES6ZuulYml()
cp.spawn('npm', ['run', 'test-browser-es6'], { stdio: 'inherit' })
.on('close', function (code) {
process.exit(code)
})
})

function writeES5ZuulYml () {
fs.writeFileSync(zuulYmlPath, fs.readFileSync(path.join(__dirname, 'zuul-es5.yml')))
}

function writeES6ZuulYml () {
fs.writeFileSync(zuulYmlPath, fs.readFileSync(path.join(__dirname, 'zuul-es6.yml')))
}
}

12 changes: 12 additions & 0 deletions bin/zuul-es5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ui: tape
scripts:
- ./test/_polyfill.js
browsers:
- name: safari
version: latest
- name: ie
version: 8..latest
- name: android
version: 4.4..latest
- name: iphone
version: latest
10 changes: 10 additions & 0 deletions bin/zuul-es6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ui: tape
scripts:
- ./test/_polyfill.js
browsers:
- name: chrome
version: '-2..latest'
- name: firefox
version: '-2..latest'
- name: microsoftedge
version: 13..latest
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
},
"scripts": {
"test": "standard && node ./bin/test.js",
"test-browser": "zuul -- test/*.js test/node/*.js",
"test-browser-es5": "zuul -- test/*.js",
"test-browser-es6": "zuul -- test/*.js test/node/*.js",
"test-browser-local": "zuul --local -- test/*.js test/node/*.js",
"test-node": "tape test/*.js test/node/*.js && OBJECT_IMPL=true tape test/*.js",
"perf": "browserify --debug perf/bracket-notation.js > perf/bundle.js && open perf/index.html",
Expand Down
9 changes: 6 additions & 3 deletions test/node/test-buffer-alloc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {
var common = {};
var assert = require('assert');

Expand Down Expand Up @@ -681,7 +681,7 @@ assert.equal(dot.toString('base64'), '//4uAA==');
}

// Regression test for https://github.com/nodejs/node/issues/3496.
// TODO assert.equal(Buffer.from('=bad'.repeat(1e4), 'base64').length, 0);
// assert.equal(Buffer.from('=bad'.repeat(1e4), 'base64').length, 0);

{
// Creating buffers larger than pool size.
Expand Down Expand Up @@ -1294,7 +1294,7 @@ assert.throws(function() {
}

var utf16Buf = Buffer.from('0123456789', 'utf16le');
// TODO assert.deepEqual(utf16Buf.slice(0, 6), Buffer.from('012', 'utf16le'));
// assert.deepEqual(utf16Buf.slice(0, 6), Buffer.from('012', 'utf16le'));

assert.equal(buf.slice('0', '1'), '0');
assert.equal(buf.slice('-5', '10'), '56789');
Expand Down Expand Up @@ -1447,3 +1447,6 @@ assert(ubuf);
assert(ubuf.buffer);
assert.equal(ubuf.buffer.byteLength, 10);



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-arraybuffer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {


var assert = require('assert');
Expand Down Expand Up @@ -110,3 +110,6 @@ b.writeDoubleBE(11.11, 0, true);
});
}



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-ascii.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {

var assert = require('assert');

Expand All @@ -26,3 +26,6 @@ for (var i = 0; i < expected.length; ++i) {
if (input.charCodeAt(i) > 127) ++i;
}



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-bad-overload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {

var assert = require('assert');

Expand All @@ -16,3 +16,6 @@ assert.doesNotThrow(function() {
Buffer.from('deadbeaf', 'hex');
});



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-bytelength.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {


var assert = require('assert');
Expand Down Expand Up @@ -87,3 +87,6 @@ assert.equal(Buffer.byteLength('Il était tué', 'binary'), 12);
assert.equal(24, Buffer.byteLength('Il était tué', encoding));
});



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-compare-offset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {


var assert = require('assert');
Expand Down Expand Up @@ -64,3 +64,6 @@ assert.throws(() => a.compare(b, 0, Infinity), oor);
assert.throws(() => a.compare(b, -Infinity, Infinity), oor);
assert.throws(() => a.compare(), /Argument must be a Buffer/);



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-concat.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {

var assert = require('assert');

Expand Down Expand Up @@ -38,3 +38,6 @@ function assertWrongList(value) {
});
}



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-fill.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {


var assert = require('assert');
Expand Down Expand Up @@ -242,3 +242,6 @@ function testBufs(string, offset, length, encoding) {
writeToFill.apply(null, arguments));
}



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-includes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {

var assert = require('assert');

Expand Down Expand Up @@ -259,3 +259,6 @@ assert.throws(function() {
b.includes([]);
});



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-indexof.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {

var assert = require('assert');

Expand Down Expand Up @@ -285,3 +285,6 @@ assert.throws(function() {
b.indexOf([]);
});



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-inheritance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {


var assert = require('assert');
Expand Down Expand Up @@ -40,3 +40,6 @@ vals.forEach(function(t) {
t.toString();
});



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-inspect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {

var assert = require('assert');

Expand Down Expand Up @@ -39,3 +39,6 @@ assert.doesNotThrow(function() {
assert.strictEqual(util.inspect(s), expected);
});



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-iterator.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {

var assert = require('assert');

Expand Down Expand Up @@ -63,3 +63,6 @@ assert.deepEqual(arr, [
[4, 5]
]);



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-safe-unsafe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {


var assert = require('assert');
Expand All @@ -25,3 +25,6 @@ assert(isZeroFilled(new Float64Array(10)));
Buffer.allocUnsafe(10);
assert(isZeroFilled(Buffer.alloc(10)));



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-slow.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {


var assert = require('assert');
Expand Down Expand Up @@ -57,3 +57,6 @@ assert.throws(function() {
SlowBuffer(buffer.kMaxLength + 1);
}, 'invalid Buffer length');



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-swap.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {


var assert = require('assert');
Expand Down Expand Up @@ -61,3 +61,6 @@ assert.throws(() => Buffer.from(buf3).swap32(), re32);
assert.throws(() => buf3.slice(1, 3).swap32(), re32);
assert.throws(() => Buffer.alloc(1025).swap32(), re32);



}
5 changes: 4 additions & 1 deletion test/node/test-buffer-zero-fill-cli.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
var Buffer = require('../../').Buffer;
if (!Buffer.TYPED_ARRAY_SUPPORT) return;
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Flags: --zero-fill-buffers

// when using --zero-fill-buffers, every Buffer and SlowBuffer
Expand Down Expand Up @@ -33,3 +33,6 @@ for (var i = 0; i < 50; i++) {
}
}



}
Loading

0 comments on commit 338d0f2

Please sign in to comment.