Skip to content

Commit b3fa109

Browse files
committed
test: update test-fs-write-file
Changed all instances of var to either const or let. Changed all instances of assert.equal() to assert.strictEqual(). Replaced all error checks with assert.ifError(e).
1 parent e21e129 commit b3fa109

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

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

+34-34
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,81 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
4-
var fs = require('fs');
5-
var join = require('path').join;
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const fs = require('fs');
5+
const join = require('path').join;
66

77
common.refreshTmpDir();
88

9-
var filename = join(common.tmpDir, 'test.txt');
9+
const filename = join(common.tmpDir, 'test.txt');
1010

11-
var n = 220;
12-
var s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' +
13-
'广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' +
14-
'南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' +
15-
'前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' +
16-
'南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' +
17-
'历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' +
18-
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n';
11+
const n = 220;
12+
const s = '南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、' +
13+
'广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。' +
14+
'南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。' +
15+
'前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,' +
16+
'南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,' +
17+
'历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,' +
18+
'它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\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;
25-
assert.equal(Buffer.byteLength(s), buffer.length);
24+
assert.ifError(e);
25+
assert.strictEqual(Buffer.byteLength(s), buffer.length);
2626
}));
2727
}));
2828

2929
// test that writeFile accepts buffers
30-
var filename2 = join(common.tmpDir, 'test2.txt');
31-
var buf = Buffer.from(s, 'utf8');
30+
const filename2 = join(common.tmpDir, 'test2.txt');
31+
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

39-
assert.equal(buf.length, buffer.length);
39+
assert.strictEqual(buf.length, buffer.length);
4040
}));
4141
}));
4242

4343
// test that writeFile accepts numbers.
44-
var filename3 = join(common.tmpDir, 'test3.txt');
44+
const filename3 = join(common.tmpDir, 'test3.txt');
4545

46-
var m = 0o600;
46+
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) {
52-
var st = fs.statSync(filename3);
53-
assert.equal(st.mode & 0o700, m);
52+
const st = fs.statSync(filename3);
53+
assert.strictEqual(st.mode & 0o700, m);
5454
}
5555

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

59-
assert.equal(Buffer.byteLength('' + n), buffer.length);
59+
assert.strictEqual(Buffer.byteLength('' + n), buffer.length);
6060
}));
6161
}));
6262

6363
// test that writeFile accepts file descriptors
64-
var filename4 = join(common.tmpDir, 'test4.txt');
64+
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

78-
assert.equal(Buffer.byteLength(s), buffer.length);
78+
assert.strictEqual(Buffer.byteLength(s), buffer.length);
7979
}));
8080
}));
8181
}));

0 commit comments

Comments
 (0)