Skip to content

Commit 87038bb

Browse files
radelmannaddaleax
authored andcommitted
test: refactor test-fs-write-file
Replaced all error checks with assert.ifError(e). PR-URL: #10030 Reviewed-By: Rich Trott <[email protected]>
1 parent 1f6f411 commit 87038bb

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

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

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ const s = '南越国是前203年至前111年存在于岭南地区的一个国家
1818
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n';
1919

2020
fs.writeFile(filename, s, common.mustCall(function(e) {
21-
if (e) throw e;
21+
assert.ifError(e);
2222

2323
fs.readFile(filename, common.mustCall(function(e, buffer) {
24-
if (e) throw e;
24+
assert.ifError(e);
2525
assert.strictEqual(Buffer.byteLength(s), buffer.length);
2626
}));
2727
}));
@@ -31,10 +31,10 @@ const filename2 = join(common.tmpDir, 'test2.txt');
3131
const buf = Buffer.from(s, 'utf8');
3232

3333
fs.writeFile(filename2, buf, common.mustCall(function(e) {
34-
if (e) throw e;
34+
assert.ifError(e);
3535

3636
fs.readFile(filename2, common.mustCall(function(e, buffer) {
37-
if (e) throw e;
37+
assert.ifError(e);
3838

3939
assert.strictEqual(buf.length, buffer.length);
4040
}));
@@ -45,7 +45,7 @@ const filename3 = join(common.tmpDir, 'test3.txt');
4545

4646
const m = 0o600;
4747
fs.writeFile(filename3, n, { mode: m }, common.mustCall(function(e) {
48-
if (e) throw e;
48+
assert.ifError(e);
4949

5050
// windows permissions aren't unix
5151
if (!common.isWindows) {
@@ -54,7 +54,7 @@ fs.writeFile(filename3, n, { mode: m }, common.mustCall(function(e) {
5454
}
5555

5656
fs.readFile(filename3, common.mustCall(function(e, buffer) {
57-
if (e) throw e;
57+
assert.ifError(e);
5858

5959
assert.strictEqual(Buffer.byteLength('' + n), buffer.length);
6060
}));
@@ -64,16 +64,16 @@ fs.writeFile(filename3, n, { mode: m }, common.mustCall(function(e) {
6464
const filename4 = join(common.tmpDir, 'test4.txt');
6565

6666
fs.open(filename4, 'w+', common.mustCall(function(e, fd) {
67-
if (e) throw e;
67+
assert.ifError(e);
6868

6969
fs.writeFile(fd, s, common.mustCall(function(e) {
70-
if (e) throw e;
70+
assert.ifError(e);
7171

7272
fs.close(fd, common.mustCall(function(e) {
73-
if (e) throw e;
73+
assert.ifError(e);
7474

7575
fs.readFile(filename4, common.mustCall(function(e, buffer) {
76-
if (e) throw e;
76+
assert.ifError(e);
7777

7878
assert.strictEqual(Buffer.byteLength(s), buffer.length);
7979
}));

0 commit comments

Comments
 (0)