Skip to content

Commit 6bb7999

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
test: refactor test-file-write-stream3
* use common.mustCall() to verify all tests have run * eliminate unneeded removeTestFile() * eliminate unneeded var leaking into global scope * var -> const * remove instance of let PR-URL: #6050 Reviewed-By: James M Snell <[email protected]>
1 parent 632e6b9 commit 6bb7999

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

test/parallel/test-file-write-stream3.js

+9-22
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ const path = require('path');
55
const fs = require('fs');
66

77

8-
var filepath = path.join(common.tmpDir, 'write_pos.txt');
8+
const filepath = path.join(common.tmpDir, 'write_pos.txt');
99

1010

1111
const cb_expected = 'write open close write open close write open close ';
12-
let cb_occurred = '';
12+
var cb_occurred = '';
1313

14-
var fileDataInitial = 'abcdefghijklmnopqrstuvwxyz';
14+
const fileDataInitial = 'abcdefghijklmnopqrstuvwxyz';
1515

16-
var fileDataExpected_1 = 'abcdefghijklmnopqrstuvwxyz';
17-
var fileDataExpected_2 = 'abcdefghij123456qrstuvwxyz';
18-
var fileDataExpected_3 = 'abcdefghij\u2026\u2026qrstuvwxyz';
16+
const fileDataExpected_1 = 'abcdefghijklmnopqrstuvwxyz';
17+
const fileDataExpected_2 = 'abcdefghij123456qrstuvwxyz';
18+
const fileDataExpected_3 = 'abcdefghij\u2026\u2026qrstuvwxyz';
1919

2020

2121
process.on('exit', function() {
22-
removeTestFile();
2322
if (cb_occurred !== cb_expected) {
2423
console.log(' Test callback events missing or out of order:');
2524
console.log(' expected: %j', cb_expected);
@@ -30,12 +29,6 @@ process.on('exit', function() {
3029
}
3130
});
3231

33-
function removeTestFile() {
34-
try {
35-
fs.unlinkSync(filepath);
36-
} catch (ex) { }
37-
}
38-
3932

4033
common.refreshTmpDir();
4134

@@ -164,20 +157,14 @@ function run_test_3() {
164157
}
165158

166159

167-
function run_test_4() {
168-
var options;
169-
170-
options = { start: -5,
171-
flags: 'r+' };
172-
160+
const run_test_4 = common.mustCall(function() {
173161
// Error: start must be >= zero
174162
assert.throws(
175163
function() {
176-
file = fs.createWriteStream(filepath, options);
164+
fs.createWriteStream(filepath, { start: -5, flags: 'r+' });
177165
},
178166
/start must be/
179167
);
180-
181-
}
168+
});
182169

183170
run_test_1();

0 commit comments

Comments
 (0)