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

update test/parallel/test-fs-read-stream-inherit.js to use ES6 variable declarations and assert.strictEqual #9894

Closed
Closed
Changes from 2 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
82 changes: 41 additions & 41 deletions test/parallel/test-fs-read-stream-inherit.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

var path = require('path');
var fs = require('fs');
var fn = path.join(common.fixturesDir, 'elipses.txt');
var rangeFile = path.join(common.fixturesDir, 'x.txt');
const path = require('path');
const fs = require('fs');
const fn = path.join(common.fixturesDir, 'elipses.txt');
const rangeFile = path.join(common.fixturesDir, 'x.txt');

var callbacks = { open: 0, end: 0, close: 0 };
const callbacks = { open: 0, end: 0, close: 0 };

var paused = false;
let paused = false;

var file = fs.ReadStream(fn);
const file = fs.ReadStream(fn);

file.on('open', function(fd) {
file.length = 0;
callbacks.open++;
assert.equal('number', typeof fd);
assert.strictEqual('number', typeof fd);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can you please swap the arguments here and throughout the rest of the file? The function signature is assert.strictEqual(actual, expected[, message]);

assert.ok(file.readable);

// GH-535
Expand Down Expand Up @@ -49,18 +49,18 @@ file.on('end', function(chunk) {
file.on('close', function() {
callbacks.close++;

//assert.equal(fs.readFileSync(fn), fileContent);
//assert.strictEqual(fs.readFileSync(fn), fileContent);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just remove this?

});

var file3 = fs.createReadStream(fn, Object.create({encoding: 'utf8'}));
const file3 = fs.createReadStream(fn, Object.create({encoding: 'utf8'}));
file3.length = 0;
file3.on('data', function(data) {
assert.equal('string', typeof data);
assert.strictEqual('string', typeof data);
file3.length += data.length;

for (var i = 0; i < data.length; i++) {
for (let i = 0; i < data.length; i++) {
// http://www.fileformat.info/info/unicode/char/2026/index.htm
assert.equal('\u2026', data[i]);
assert.strictEqual('\u2026', data[i]);
}
});

Expand All @@ -69,74 +69,74 @@ file3.on('close', function() {
});

process.on('exit', function() {
assert.equal(1, callbacks.open);
assert.equal(1, callbacks.end);
assert.equal(2, callbacks.close);
assert.equal(30000, file.length);
assert.equal(10000, file3.length);
assert.strictEqual(1, callbacks.open);
assert.strictEqual(1, callbacks.end);
assert.strictEqual(2, callbacks.close);
assert.strictEqual(30000, file.length);
assert.strictEqual(10000, file3.length);
console.error('ok');
});

var file4 = fs.createReadStream(rangeFile, Object.create({bufferSize: 1,
const file4 = fs.createReadStream(rangeFile, Object.create({bufferSize: 1,
start: 1, end: 2}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: would you mind to align start with rangeFile?

assert.equal(file4.start, 1);
assert.equal(file4.end, 2);
var contentRead = '';
assert.strictEqual(file4.start, 1);
assert.strictEqual(file4.end, 2);
let contentRead = '';
file4.on('data', function(data) {
contentRead += data.toString('utf-8');
});
file4.on('end', function(data) {
assert.equal(contentRead, 'yz');
assert.strictEqual(contentRead, 'yz');
});

var file5 = fs.createReadStream(rangeFile, Object.create({bufferSize: 1,
const file5 = fs.createReadStream(rangeFile, Object.create({bufferSize: 1,
start: 1}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

assert.equal(file5.start, 1);
assert.strictEqual(file5.start, 1);
file5.data = '';
file5.on('data', function(data) {
file5.data += data.toString('utf-8');
});
file5.on('end', function() {
assert.equal(file5.data, 'yz\n');
assert.strictEqual(file5.data, 'yz\n');
});

// https://github.com/joyent/node/issues/2320
var file6 = fs.createReadStream(rangeFile, Object.create({bufferSize: 1.23,
const file6 = fs.createReadStream(rangeFile, Object.create({bufferSize: 1.23,
start: 1}));
Copy link
Member

@lpinca lpinca Dec 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, there are also a couple more below.

assert.equal(file6.start, 1);
assert.strictEqual(file6.start, 1);
file6.data = '';
file6.on('data', function(data) {
file6.data += data.toString('utf-8');
});
file6.on('end', function() {
assert.equal(file6.data, 'yz\n');
assert.strictEqual(file6.data, 'yz\n');
});

assert.throws(function() {
fs.createReadStream(rangeFile, Object.create({start: 10, end: 2}));
}, /"start" option must be <= "end" option/);

var stream = fs.createReadStream(rangeFile, Object.create({ start: 0,
const stream = fs.createReadStream(rangeFile, Object.create({ start: 0,
end: 0 }));
assert.equal(stream.start, 0);
assert.equal(stream.end, 0);
assert.strictEqual(stream.start, 0);
assert.strictEqual(stream.end, 0);
stream.data = '';

stream.on('data', function(chunk) {
stream.data += chunk;
});

stream.on('end', function() {
assert.equal('x', stream.data);
assert.strictEqual('x', stream.data);
});

// pause and then resume immediately.
var pauseRes = fs.createReadStream(rangeFile);
const pauseRes = fs.createReadStream(rangeFile);
pauseRes.pause();
pauseRes.resume();

var file7 = fs.createReadStream(rangeFile, Object.create({autoClose: false }));
assert.equal(file7.autoClose, false);
let file7 = fs.createReadStream(rangeFile, Object.create({autoClose: false }));
assert.strictEqual(file7.autoClose, false);
file7.on('data', function() {});
file7.on('end', function() {
process.nextTick(function() {
Expand All @@ -154,18 +154,18 @@ function file7Next() {
file7.data += data;
});
file7.on('end', function(err) {
assert.equal(file7.data, 'xyz\n');
assert.strictEqual(file7.data, 'xyz\n');
});
}

// Just to make sure autoClose won't close the stream because of error.
var file8 = fs.createReadStream(null, Object.create({fd: 13337,
const file8 = fs.createReadStream(null, Object.create({fd: 13337,
autoClose: false }));
file8.on('data', function() {});
file8.on('error', common.mustCall(function() {}));

// Make sure stream is destroyed when file does not exist.
var file9 = fs.createReadStream('/path/to/file/that/does/not/exist');
const file9 = fs.createReadStream('/path/to/file/that/does/not/exist');
file9.on('data', function() {});
file9.on('error', common.mustCall(function() {}));

Expand Down