Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

used es6 conventions for variables and anonymous functions declaration #9669

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions test/parallel/test-fs-read-stream-err.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var fs = require('fs');
const common = require('../common');
const assert = require('assert');
const fs = require('fs');

var stream = fs.createReadStream(__filename, {
const stream = fs.createReadStream(__filename, {
bufferSize: 64
});
var err = new Error('BAM');
const err = new Error('BAM');

stream.on('error', common.mustCall(function errorHandler(err_) {
console.error('error event');
process.nextTick(function() {
assert.equal(stream.fd, null);
assert.equal(err_, err);
});
stream.on('error', common.mustCall((err_) => {
process.nextTick(common.mustCall(() => {
assert.strictEqual(stream.fd, null);
assert.strictEqual(err_, err);
}));
}));

fs.close = common.mustCall(function(fd_, cb) {
assert.equal(fd_, stream.fd);
fs.close = common.mustCall((fd_, cb) => {
assert.strictEqual(fd_, stream.fd);
process.nextTick(cb);
});

var read = fs.read;
const read = fs.read;
fs.read = function() {
// first time is ok.
read.apply(fs, arguments);
// then it breaks
fs.read = function() {
var cb = arguments[arguments.length - 1];
process.nextTick(function() {
fs.read = common.mustCall(function() {
const cb = arguments[arguments.length - 1];
process.nextTick(() => {
cb(err);
});
// and should not be called again!
fs.read = function() {
fs.read = () => {
throw new Error('BOOM!');
};
};
});
};

stream.on('data', function(buf) {
stream.on('data', common.fail); // no more 'data' events should follow
stream.on('data', (buf) => {
stream.on('data', () => common.fail("no more 'data' events should follow"));
});