From: Feross Aboukhadijeh Date: Wed, 20 Apr 2016 05:34:01 +0000 (-0700) Subject: Only run es6 node tests in browsers that support it X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=338d0f2a7c9eb79dfd7bf48d2e3550e607b5d7a6;p=buffer.git Only run es6 node tests in browsers that support it --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6646b77 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.zuul.yml diff --git a/.npmignore b/.npmignore index 4cea182..a274035 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,2 @@ +.zuul.yml perf/ diff --git a/bin/download-node-tests.js b/bin/download-node-tests.js index 6b327a4..6fe1f85 100755 --- a/bin/download-node-tests.js +++ b/bin/download-node-tests.js @@ -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 @@ -103,5 +103,8 @@ function testfixer (filename) { } cb(null, line + '\n') + }, function (cb) { + // flush function + this.push('\n}') }) } diff --git a/bin/test.js b/bin/test.js index 2fc368b..5a86f1b 100644 --- a/bin/test.js +++ b/bin/test.js @@ -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'))) + } +} + diff --git a/bin/zuul-es5.yml b/bin/zuul-es5.yml new file mode 100644 index 0000000..e30bf2b --- /dev/null +++ b/bin/zuul-es5.yml @@ -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 diff --git a/bin/zuul-es6.yml b/bin/zuul-es6.yml new file mode 100644 index 0000000..1fcb68d --- /dev/null +++ b/bin/zuul-es6.yml @@ -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 diff --git a/package.json b/package.json index 5e70cb7..facbe8b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/node/test-buffer-alloc.js b/test/node/test-buffer-alloc.js index 46016d1..74060f3 100644 --- a/test/node/test-buffer-alloc.js +++ b/test/node/test-buffer-alloc.js @@ -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'); @@ -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. @@ -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'); @@ -1447,3 +1447,6 @@ assert(ubuf); assert(ubuf.buffer); assert.equal(ubuf.buffer.byteLength, 10); + + +} diff --git a/test/node/test-buffer-arraybuffer.js b/test/node/test-buffer-arraybuffer.js index 9721add..b768d46 100644 --- a/test/node/test-buffer-arraybuffer.js +++ b/test/node/test-buffer-arraybuffer.js @@ -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'); @@ -110,3 +110,6 @@ b.writeDoubleBE(11.11, 0, true); }); } + + +} \ No newline at end of file diff --git a/test/node/test-buffer-ascii.js b/test/node/test-buffer-ascii.js index b0b6ea6..2f22dd9 100644 --- a/test/node/test-buffer-ascii.js +++ b/test/node/test-buffer-ascii.js @@ -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'); @@ -26,3 +26,6 @@ for (var i = 0; i < expected.length; ++i) { if (input.charCodeAt(i) > 127) ++i; } + + +} \ No newline at end of file diff --git a/test/node/test-buffer-bad-overload.js b/test/node/test-buffer-bad-overload.js index 0e61175..00a75b0 100644 --- a/test/node/test-buffer-bad-overload.js +++ b/test/node/test-buffer-bad-overload.js @@ -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'); @@ -16,3 +16,6 @@ assert.doesNotThrow(function() { Buffer.from('deadbeaf', 'hex'); }); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-bytelength.js b/test/node/test-buffer-bytelength.js index e55163a..f50df49 100644 --- a/test/node/test-buffer-bytelength.js +++ b/test/node/test-buffer-bytelength.js @@ -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'); @@ -87,3 +87,6 @@ assert.equal(Buffer.byteLength('Il était tué', 'binary'), 12); assert.equal(24, Buffer.byteLength('Il était tué', encoding)); }); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-compare-offset.js b/test/node/test-buffer-compare-offset.js index a0640d2..2051de7 100644 --- a/test/node/test-buffer-compare-offset.js +++ b/test/node/test-buffer-compare-offset.js @@ -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'); @@ -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/); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-concat.js b/test/node/test-buffer-concat.js index 7b2e572..a518593 100644 --- a/test/node/test-buffer-concat.js +++ b/test/node/test-buffer-concat.js @@ -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'); @@ -38,3 +38,6 @@ function assertWrongList(value) { }); } + + +} \ No newline at end of file diff --git a/test/node/test-buffer-fill.js b/test/node/test-buffer-fill.js index 0d76cec..3a21d37 100644 --- a/test/node/test-buffer-fill.js +++ b/test/node/test-buffer-fill.js @@ -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'); @@ -242,3 +242,6 @@ function testBufs(string, offset, length, encoding) { writeToFill.apply(null, arguments)); } + + +} \ No newline at end of file diff --git a/test/node/test-buffer-includes.js b/test/node/test-buffer-includes.js index 78b170f..c4757cf 100644 --- a/test/node/test-buffer-includes.js +++ b/test/node/test-buffer-includes.js @@ -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'); @@ -259,3 +259,6 @@ assert.throws(function() { b.includes([]); }); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-indexof.js b/test/node/test-buffer-indexof.js index 0228bd1..8b900ae 100644 --- a/test/node/test-buffer-indexof.js +++ b/test/node/test-buffer-indexof.js @@ -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'); @@ -285,3 +285,6 @@ assert.throws(function() { b.indexOf([]); }); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-inheritance.js b/test/node/test-buffer-inheritance.js index afcdb97..d0683ee 100644 --- a/test/node/test-buffer-inheritance.js +++ b/test/node/test-buffer-inheritance.js @@ -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'); @@ -40,3 +40,6 @@ vals.forEach(function(t) { t.toString(); }); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-inspect.js b/test/node/test-buffer-inspect.js index 609af30..37daa72 100644 --- a/test/node/test-buffer-inspect.js +++ b/test/node/test-buffer-inspect.js @@ -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'); @@ -39,3 +39,6 @@ assert.doesNotThrow(function() { assert.strictEqual(util.inspect(s), expected); }); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-iterator.js b/test/node/test-buffer-iterator.js index ebaca20..f9de4c1 100644 --- a/test/node/test-buffer-iterator.js +++ b/test/node/test-buffer-iterator.js @@ -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'); @@ -63,3 +63,6 @@ assert.deepEqual(arr, [ [4, 5] ]); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-safe-unsafe.js b/test/node/test-buffer-safe-unsafe.js index 5a39ae4..49a645d 100644 --- a/test/node/test-buffer-safe-unsafe.js +++ b/test/node/test-buffer-safe-unsafe.js @@ -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'); @@ -25,3 +25,6 @@ assert(isZeroFilled(new Float64Array(10))); Buffer.allocUnsafe(10); assert(isZeroFilled(Buffer.alloc(10))); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-slow.js b/test/node/test-buffer-slow.js index 1266001..f9ad815 100644 --- a/test/node/test-buffer-slow.js +++ b/test/node/test-buffer-slow.js @@ -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'); @@ -57,3 +57,6 @@ assert.throws(function() { SlowBuffer(buffer.kMaxLength + 1); }, 'invalid Buffer length'); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-swap.js b/test/node/test-buffer-swap.js index d31d9b9..db5ccd8 100644 --- a/test/node/test-buffer-swap.js +++ b/test/node/test-buffer-swap.js @@ -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'); @@ -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); + + +} \ No newline at end of file diff --git a/test/node/test-buffer-zero-fill-cli.js b/test/node/test-buffer-zero-fill-cli.js index 7cea0a9..3be6575 100644 --- a/test/node/test-buffer-zero-fill-cli.js +++ b/test/node/test-buffer-zero-fill-cli.js @@ -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 @@ -33,3 +33,6 @@ for (var i = 0; i < 50; i++) { } } + + +} \ No newline at end of file diff --git a/test/node/test-buffer-zero-fill-reset.js b/test/node/test-buffer-zero-fill-reset.js index 10146f9..3b33b2a 100644 --- a/test/node/test-buffer-zero-fill-reset.js +++ b/test/node/test-buffer-zero-fill-reset.js @@ -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'); @@ -20,3 +20,6 @@ for (var i = 0; i < 100; i++) { assert.ok(testUint8Array(ui), 'Uint8Array is not zero-filled'); } + + +} \ No newline at end of file diff --git a/test/node/test-buffer.js b/test/node/test-buffer.js index 78c4e68..4636ea2 100644 --- a/test/node/test-buffer.js +++ b/test/node/test-buffer.js @@ -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'); @@ -678,7 +678,7 @@ assert.equal(dot.toString('base64'), '//4uAA=='); } // Regression test for https://github.com/nodejs/node/issues/3496. -// TODO assert.equal(Buffer('=bad'.repeat(1e4), 'base64').length, 0); +// assert.equal(Buffer('=bad'.repeat(1e4), 'base64').length, 0); { // Creating buffers larger than pool size. @@ -1296,7 +1296,7 @@ assert.throws(function() { } var utf16Buf = new Buffer('0123456789', 'utf16le'); - // TODO assert.deepEqual(utf16Buf.slice(0, 6), Buffer('012', 'utf16le')); + // assert.deepEqual(utf16Buf.slice(0, 6), Buffer('012', 'utf16le')); assert.equal(buf.slice('0', '1'), '0'); assert.equal(buf.slice('-5', '10'), '56789'); @@ -1444,3 +1444,6 @@ assert.equal(Buffer.prototype.offset, undefined); assert.equal(SlowBuffer.prototype.parent, undefined); assert.equal(SlowBuffer.prototype.offset, undefined); + + +}