Skip to content

Commit 16164b5

Browse files
Richard KarmazinMylesBorins
authored andcommitted
test: test-file-write-stream3.js refactor
PR-URL: #10035 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 7391983 commit 16164b5

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

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

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const filepath = path.join(common.tmpDir, 'write_pos.txt');
99

1010

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

1414
constfileDataInitial='abcdefghijklmnopqrstuvwxyz';
1515

@@ -34,10 +34,8 @@ common.refreshTmpDir();
3434

3535

3636
functionrun_test_1(){
37-
varfile,buffer,options;
38-
39-
options={};
40-
file=fs.createWriteStream(filepath,options);
37+
constoptions={};
38+
constfile=fs.createWriteStream(filepath,options);
4139
console.log(' (debug: start ',file.start);
4240
console.log(' (debug: pos ',file.pos);
4341

@@ -51,10 +49,10 @@ function run_test_1(){
5149
console.log(' (debug: start ',file.start);
5250
console.log(' (debug: pos ',file.pos);
5351
assert.strictEqual(file.bytesWritten,buffer.length);
54-
varfileData=fs.readFileSync(filepath,'utf8');
52+
constfileData=fs.readFileSync(filepath,'utf8');
5553
console.log(' (debug: file data ',fileData);
5654
console.log(' (debug: expected ',fileDataExpected_1);
57-
assert.equal(fileData,fileDataExpected_1);
55+
assert.strictEqual(fileData,fileDataExpected_1);
5856

5957
run_test_2();
6058
});
@@ -65,7 +63,7 @@ function run_test_1(){
6563
throwerr;
6664
});
6765

68-
buffer=newBuffer(fileDataInitial);
66+
constbuffer=Buffer.from(fileDataInitial);
6967
file.write(buffer);
7068
cb_occurred+='write ';
7169

@@ -74,13 +72,12 @@ function run_test_1(){
7472

7573

7674
functionrun_test_2(){
77-
varfile,buffer,options;
7875

79-
buffer=newBuffer('123456');
76+
constbuffer=Buffer.from('123456');
8077

81-
options={start: 10,
82-
flags: 'r+'};
83-
file=fs.createWriteStream(filepath,options);
78+
constoptions={start: 10,
79+
flags: 'r+'};
80+
constfile=fs.createWriteStream(filepath,options);
8481
console.log(' (debug: start ',file.start);
8582
console.log(' (debug: pos ',file.pos);
8683

@@ -94,10 +91,10 @@ function run_test_2(){
9491
console.log(' (debug: start ',file.start);
9592
console.log(' (debug: pos ',file.pos);
9693
assert.strictEqual(file.bytesWritten,buffer.length);
97-
varfileData=fs.readFileSync(filepath,'utf8');
94+
constfileData=fs.readFileSync(filepath,'utf8');
9895
console.log(' (debug: file data ',fileData);
9996
console.log(' (debug: expected ',fileDataExpected_2);
100-
assert.equal(fileData,fileDataExpected_2);
97+
assert.strictEqual(fileData,fileDataExpected_2);
10198

10299
run_test_3();
103100
});
@@ -116,13 +113,12 @@ function run_test_2(){
116113

117114

118115
functionrun_test_3(){
119-
varfile,options;
120116

121117
constdata='\u2026\u2026';// 3 bytes * 2 = 6 bytes in UTF-8
122118

123-
options={start: 10,
124-
flags: 'r+'};
125-
file=fs.createWriteStream(filepath,options);
119+
constoptions={start: 10,
120+
flags: 'r+'};
121+
constfile=fs.createWriteStream(filepath,options);
126122
console.log(' (debug: start ',file.start);
127123
console.log(' (debug: pos ',file.pos);
128124

@@ -139,7 +135,7 @@ function run_test_3(){
139135
constfileData=fs.readFileSync(filepath,'utf8');
140136
console.log(' (debug: file data ',fileData);
141137
console.log(' (debug: expected ',fileDataExpected_3);
142-
assert.equal(fileData,fileDataExpected_3);
138+
assert.strictEqual(fileData,fileDataExpected_3);
143139

144140
run_test_4();
145141
});

0 commit comments

Comments
(0)