Skip to content

Commit 93c4874

Browse files
sudarakaFishrock123
authored andcommitted
test: refactor test-file-write-stream
Replace all `var` occurrences in test-file-write-stream.js with `const` (where they are not being reassigned) and `let` (where they are being reassigned). Add strict comparison to the asserts and if statements: - Replace `assert.equal` with `assert.strictEqual` where: 1. Result of `typeof` being compared to a string literal. 2. Result of `fs.readFileSync` with UTF-8 encoding being compared to a string constant. - Replace `==` with `===` where integer values are being compared to integer literals. Remove unnecessary very IIFE. Use template literals. PR-URL: #8894 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 5164865 commit 93c4874

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed
Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
2+
const common = require('../common');
3+
const assert = require('assert');
44

5-
var path = require('path');
6-
var fs = require('fs');
7-
var fn = path.join(common.tmpDir, 'write.txt');
5+
const path = require('path');
6+
const fs = require('fs');
7+
const fn = path.join(common.tmpDir, 'write.txt');
88
common.refreshTmpDir();
9-
var file = fs.createWriteStream(fn, {
9+
const file = fs.createWriteStream(fn, {
1010
highWaterMark: 10
1111
});
1212

13-
var EXPECTED = '012345678910';
13+
const EXPECTED = '012345678910';
1414

15-
var callbacks = {
15+
const callbacks = {
1616
open: -1,
1717
drain: -2,
1818
close: -1
@@ -22,19 +22,19 @@ file
2222
.on('open', function(fd) {
2323
console.error('open!');
2424
callbacks.open++;
25-
assert.equal('number', typeof fd);
25+
assert.strictEqual('number', typeof fd);
2626
})
2727
.on('error', function(err) {
2828
throw err;
2929
})
3030
.on('drain', function() {
3131
console.error('drain!', callbacks.drain);
3232
callbacks.drain++;
33-
if (callbacks.drain == -1) {
34-
assert.equal(EXPECTED, fs.readFileSync(fn, 'utf8'));
33+
if (callbacks.drain === -1) {
34+
assert.strictEqual(EXPECTED, fs.readFileSync(fn, 'utf8'));
3535
file.write(EXPECTED);
36-
} else if (callbacks.drain == 0) {
37-
assert.equal(EXPECTED + EXPECTED, fs.readFileSync(fn, 'utf8'));
36+
} else if (callbacks.drain === 0) {
37+
assert.strictEqual(EXPECTED + EXPECTED, fs.readFileSync(fn, 'utf8'));
3838
file.end();
3939
}
4040
})
@@ -51,15 +51,13 @@ file
5151
fs.unlinkSync(fn);
5252
});
5353

54-
for (var i = 0; i < 11; i++) {
55-
(function(i) {
56-
file.write('' + i);
57-
})(i);
54+
for (let i = 0; i < 11; i++) {
55+
file.write(`${i}`);
5856
}
5957

6058
process.on('exit', function() {
61-
for (var k in callbacks) {
62-
assert.equal(0, callbacks[k], k + ' count off by ' + callbacks[k]);
59+
for (const k in callbacks) {
60+
assert.strictEqual(0, callbacks[k], `${k} count off by ${callbacks[k]}`);
6361
}
6462
console.log('ok');
6563
});

0 commit comments

Comments
 (0)