diff --git a/.airtap.yml b/.airtap.yml new file mode 100644 index 0000000000..38e6f0349e --- /dev/null +++ b/.airtap.yml @@ -0,0 +1,17 @@ +sauce_connect: true +browsers: + - name: chrome + version: latest + platform: Windows 10 + - name: internet explorer + version: latest + platform: Windows 10 + - name: firefox + version: latest + platform: Windows 10 + - name: safari + version: latest + platform: Mac 10.13 + - name: microsoftedge + version: latest + platform: Windows 10 diff --git a/.gitignore b/.gitignore index f768783ace..27e4893f19 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/ coverage package-lock.json *.tap +.airtaprc diff --git a/.travis.yml b/.travis.yml index c129e2c5ac..94374dc018 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,17 @@ matrix: fast_finish: true include: - node_js: 6 + env: CMD=test - node_js: 8 + env: CMD=test - node_js: 9 + env: CMD=test - node_js: 10 -script: "npm test" -env: - global: - - secure: rE2Vvo7vnjabYNULNyLFxOyt98BoJexDqsiOnfiD6kLYYsiQGfr/sbZkPMOFm9qfQG7pjqx+zZWZjGSswhTt+626C0t/njXqug7Yps4c3dFblzGfreQHp7wNX5TFsvrxd6dAowVasMp61sJcRnB2w8cUzoe3RAYUDHyiHktwqMc= - - secure: g9YINaKAdMatsJ28G9jCGbSaguXCyxSTy+pBO6Ch0Cf57ZLOTka3HqDj8p3nV28LUIHZ3ut5WO43CeYKwt4AUtLpBS3a0dndHdY6D83uY6b2qh5hXlrcbeQTq2cvw2y95F7hm4D1kwrgZ7ViqaKggRcEupAL69YbJnxeUDKWEdI= + env: CMD=test + - node_js: stable + env: CMD=test-browsers + addons: + sauce_connect: true + hosts: + - airtap.local +script: npm run $CMD diff --git a/README.md b/README.md index 65d066663c..3ba2efcba4 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,13 @@ # readable-stream -***Node-core v10.5.0 streams for userland*** [![Build Status](https://travis-ci.org/nodejs/readable-stream.svg?branch=master)](https://travis-ci.org/nodejs/readable-stream) +***Node-core v10.5.0 streams for userland*** [![Build Status](https://travis-ci.com/nodejs/readable-stream.svg?branch=master)](https://travis-ci.com/nodejs/readable-stream) [![NPM](https://nodei.co/npm/readable-stream.png?downloads=true&downloadRank=true)](https://nodei.co/npm/readable-stream/) [![NPM](https://nodei.co/npm-dl/readable-stream.png?&months=6&height=3)](https://nodei.co/npm/readable-stream/) -[![Sauce Test Status](https://saucelabs.com/browser-matrix/readable-stream.svg)](https://saucelabs.com/u/readable-stream) +[![Sauce Test Status](https://saucelabs.com/browser-matrix/readabe-stream.svg)](https://saucelabs.com/u/readabe-stream) ```bash npm install --save readable-stream diff --git a/build/package.json b/build/package.json deleted file mode 100644 index 585b9b51fe..0000000000 --- a/build/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "readable-stream-build", - "version": "0.0.0", - "description": "", - "main": "build.js", - "dependencies": { - "babel-core": "^6.26.3", - "babel-plugin-transform-es2015-arrow-functions": "^6.5.2", - "babel-plugin-transform-es2015-block-scoping": "^6.26.0", - "babel-plugin-transform-es2015-classes": "^6.24.1", - "babel-plugin-transform-es2015-computed-properties": "^6.24.1", - "babel-plugin-transform-es2015-destructuring": "^6.18.0", - "babel-plugin-transform-es2015-for-of": "^6.8.0", - "babel-plugin-transform-es2015-parameters": "^6.24.1", - "babel-plugin-transform-es2015-shorthand-properties": "^6.24.1", - "babel-plugin-transform-es2015-spread": "^6.22.0", - "babel-plugin-transform-es2015-template-literals": "^6.8.0", - "babel-plugin-transform-inline-imports-commonjs": "^1.2.0", - "babel-plugin-transform-runtime": "^6.23.0", - "bl": "^2.0.0", - "glob": "^7.1.2", - "gunzip-maybe": "^1.4.1", - "hyperquest": "^2.1.3", - "pump": "^3.0.0", - "rimraf": "^2.6.2", - "tar-fs": "^1.16.2" - }, - "devDependencies": { - "babel-plugin-transform-async-generator-functions": "^6.24.1", - "babel-plugin-transform-async-to-generator": "^6.24.1" - } -} diff --git a/errors-browser.js b/errors-browser.js new file mode 100644 index 0000000000..26c5d2635e --- /dev/null +++ b/errors-browser.js @@ -0,0 +1,61 @@ +'use strict'; + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var codes = {}; + +function createErrorType(code, message, Base) { + if (!Base) { + Base = Error; + } + + function getMessage(arg1, arg2) { + if (typeof message === 'string') { + return message; + } else { + return message(arg1, arg2); + } + } + + var NodeError = function (_Base) { + _inherits(NodeError, _Base); + + function NodeError(arg1, arg2) { + _classCallCheck(this, NodeError); + + return _possibleConstructorReturn(this, (NodeError.__proto__ || Object.getPrototypeOf(NodeError)).call(this, getMessage(arg1, arg2))); + } + + return NodeError; + }(Base); + + NodeError.prototype.name = Base.name; + NodeError.prototype.code = code; + + codes[code] = NodeError; +} + +createErrorType('ERR_INVALID_OPT_VALUE', function (name, value) { + return 'The value "' + value + '" is invalid for option "' + name + '"'; +}, TypeError); +createErrorType('ERR_INVALID_ARG_TYPE', 'argument must be of the right type', TypeError); +createErrorType('ERR_STREAM_PUSH_AFTER_EOF', 'stream.push() after EOF'); +createErrorType('ERR_METHOD_NOT_IMPLEMENTED', function (name) { + return 'The ' + name + ' method is not implemented'; +}); +createErrorType('ERR_STREAM_PREMATURE_CLOSE', 'premature close'); +createErrorType('ERR_STREAM_DESTROYED', 'the stream was destroyed'); +createErrorType('ERR_MULTIPLE_CALLBACK', 'Callback called multiple times'); +createErrorType('ERR_STREAM_CANNOT_PIPE', 'Cannot pipe, not readable'); +createErrorType('ERR_STREAM_WRITE_AFTER_END', 'write after end'); +createErrorType('ERR_STREAM_NULL_VALUES', 'May not write null values to stream', TypeError); +createErrorType('ERR_UNKNOWN_ENCODING', function (arg) { + return 'Unknown encoding: ' + arg; +}, TypeError); +createErrorType('ERR_STREAM_UNSHIFT_AFTER_END_EVENT', 'stream.unshift() after end event'); + +module.exports.codes = codes; diff --git a/experimentalWarning.js b/experimentalWarning.js index 5b6f94540c..27003face2 100644 --- a/experimentalWarning.js +++ b/experimentalWarning.js @@ -1,10 +1,10 @@ 'use strict' -const experimentalWarnings = new Set(); +var experimentalWarnings = new Set(); function emitExperimentalWarning(feature) { if (experimentalWarnings.has(feature)) return; - const msg = `${feature} is an experimental feature. This feature could ` + + var msg = feature + ' is an experimental feature. This feature could ' + 'change at any time'; experimentalWarnings.add(feature); process.emitWarning(msg, 'ExperimentalWarning'); diff --git a/package.json b/package.json index 2b0329e35c..cf6a8e2a50 100644 --- a/package.json +++ b/package.json @@ -10,21 +10,49 @@ "util-deprecate": "^1.0.1" }, "devDependencies": { + "airtap": "0.0.9", "assert": "^1.4.0", + "babel-cli": "^6.26.0", + "babel-core": "^6.26.3", + "babel-plugin-transform-async-generator-functions": "^6.24.1", + "babel-plugin-transform-async-to-generator": "^6.24.1", + "babel-plugin-transform-es2015-arrow-functions": "^6.5.2", + "babel-plugin-transform-es2015-block-scoping": "^6.26.0", + "babel-plugin-transform-es2015-classes": "^6.24.1", + "babel-plugin-transform-es2015-computed-properties": "^6.24.1", + "babel-plugin-transform-es2015-destructuring": "^6.18.0", + "babel-plugin-transform-es2015-for-of": "^6.8.0", + "babel-plugin-transform-es2015-parameters": "^6.24.1", + "babel-plugin-transform-es2015-shorthand-properties": "^6.24.1", + "babel-plugin-transform-es2015-spread": "^6.22.0", + "babel-plugin-transform-es2015-template-literals": "^6.8.0", + "babel-plugin-transform-inline-imports-commonjs": "^1.2.0", + "babel-plugin-transform-runtime": "^6.23.0", "babel-polyfill": "^6.9.1", + "babel-preset-env": "^1.7.0", + "bl": "^2.0.0", "buffer": "^5.1.0", "deep-strict-equal": "^0.2.0", + "glob": "^7.1.2", + "gunzip-maybe": "^1.4.1", + "hyperquest": "^2.1.3", "lolex": "^2.6.0", "nyc": "^11.0.0", + "pump": "^3.0.0", + "rimraf": "^2.6.2", "tap": "^11.0.0", "tape": "^4.9.0", + "tar-fs": "^1.16.2", "util-promisify": "^2.1.0" }, "scripts": { "test": "tap -j 4 test/parallel/*.js test/ours/*.js", "ci": "TAP=1 tap test/parallel/*.js test/ours/*.js | tee test.tap", + "test-browsers": "airtap --sauce-connect --loopback airtap.local -- test/browser.js", + "test-browser-local": "airtap --local -- test/browser.js", "cover": "nyc npm test", - "report": "nyc report --reporter=lcov" + "report": "nyc report --reporter=lcov", + "update-browser-errors": "babel --presets env -o errors-browser.js errors.js" }, "repository": { "type": "git", @@ -37,6 +65,8 @@ ], "browser": { "util": false, + "worker_threads": false, + "./errors": "./errors-browser.js", "./readable.js": "./readable-browser.js", "./lib/internal/streams/stream.js": "./lib/internal/streams/stream-browser.js" }, diff --git a/test/browser.js b/test/browser.js index a82c13ae34..a3504d63f7 100644 --- a/test/browser.js +++ b/test/browser.js @@ -11,6 +11,27 @@ if (!global.console.info) { global.console.info = global.console.log; } var test = require('tape'); +var util = require('util'); + +// TODO: add replacements instead +if (!util.inspect) { + util.inspect = function () {}; + util.inspect.custom = 'custom'; +} + +// TODO: add replacements instead +global.process = { + env: {}, + on: function () {}, + cwd: function () { + return '/'; + }, + binding: function () { + return { + hasTracing: false + }; + } +}; test('streams', function (t) { require('./browser/test-stream-big-packet')(t); @@ -49,8 +70,8 @@ test('streams 2', function (t) { require('./browser/test-stream2-pipe-error-once-listener')(t); require('./browser/test-stream2-push')(t); require('./browser/test-stream2-readable-empty-buffer-no-eof')(t); - require('./browser/test-stream2-readable-from-list')(t); - require('./browser/test-stream2-transform')(t); + // require('./browser/test-stream2-readable-from-list')(t); + // require('./browser/test-stream2-transform')(t); require('./browser/test-stream2-set-encoding')(t); require('./browser/test-stream2-readable-legacy-drain')(t); require('./browser/test-stream2-readable-wrap-empty')(t);