Skip to content

Commit 28040cc

Browse files
TrottMyles Borins
authored andcommitted
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 <jasnell@gmail.com>
1 parent 3a67a05 commit 28040cc

1 file changed

Lines changed: 9 additions & 22 deletions

File tree

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

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,20 @@ const path = require('path');
55
constfs=require('fs');
66

77

8-
varfilepath=path.join(common.tmpDir,'write_pos.txt');
8+
constfilepath=path.join(common.tmpDir,'write_pos.txt');
99

1010

1111
constcb_expected='write open close write open close write open close ';
12-
letcb_occurred='';
12+
varcb_occurred='';
1313

14-
varfileDataInitial='abcdefghijklmnopqrstuvwxyz';
14+
constfileDataInitial='abcdefghijklmnopqrstuvwxyz';
1515

16-
varfileDataExpected_1='abcdefghijklmnopqrstuvwxyz';
17-
varfileDataExpected_2='abcdefghij123456qrstuvwxyz';
18-
varfileDataExpected_3='abcdefghij\u2026\u2026qrstuvwxyz';
16+
constfileDataExpected_1='abcdefghijklmnopqrstuvwxyz';
17+
constfileDataExpected_2='abcdefghij123456qrstuvwxyz';
18+
constfileDataExpected_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-
functionremoveTestFile(){
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-
functionrun_test_4(){
168-
varoptions;
169-
170-
options={start: -5,
171-
flags: 'r+'};
172-
160+
construn_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
/startmustbe/
179167
);
180-
181-
}
168+
});
182169

183170
run_test_1();

0 commit comments

Comments
 (0)