Browse Source

test: add ES6 and strictEqual to test-fs-truncate

- use const and let for variables
- replace assert.equal with assert.strictEqual

PR-URL: https://github.com/nodejs/node/pull/10167
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Italo A. Casas <me@italoacasas.com>
v6.x
Adrian Estrada 8 years ago
committed by Myles Borins
parent
commit
c65dfa9b12
  1. 42
      test/parallel/test-fs-truncate.js

42
test/parallel/test-fs-truncate.js

@ -1,43 +1,43 @@
'use strict'; 'use strict';
var common = require('../common'); const common = require('../common');
var assert = require('assert'); const assert = require('assert');
var path = require('path'); const path = require('path');
var fs = require('fs'); const fs = require('fs');
var tmp = common.tmpDir; const tmp = common.tmpDir;
var filename = path.resolve(tmp, 'truncate-file.txt'); const filename = path.resolve(tmp, 'truncate-file.txt');
var data = Buffer.alloc(1024 * 16, 'x'); const data = Buffer.alloc(1024 * 16, 'x');
common.refreshTmpDir(); common.refreshTmpDir();
var stat; let stat;
// truncateSync // truncateSync
fs.writeFileSync(filename, data); fs.writeFileSync(filename, data);
stat = fs.statSync(filename); stat = fs.statSync(filename);
assert.equal(stat.size, 1024 * 16); assert.strictEqual(stat.size, 1024 * 16);
fs.truncateSync(filename, 1024); fs.truncateSync(filename, 1024);
stat = fs.statSync(filename); stat = fs.statSync(filename);
assert.equal(stat.size, 1024); assert.strictEqual(stat.size, 1024);
fs.truncateSync(filename); fs.truncateSync(filename);
stat = fs.statSync(filename); stat = fs.statSync(filename);
assert.equal(stat.size, 0); assert.strictEqual(stat.size, 0);
// ftruncateSync // ftruncateSync
fs.writeFileSync(filename, data); fs.writeFileSync(filename, data);
var fd = fs.openSync(filename, 'r+'); const fd = fs.openSync(filename, 'r+');
stat = fs.statSync(filename); stat = fs.statSync(filename);
assert.equal(stat.size, 1024 * 16); assert.strictEqual(stat.size, 1024 * 16);
fs.ftruncateSync(fd, 1024); fs.ftruncateSync(fd, 1024);
stat = fs.statSync(filename); stat = fs.statSync(filename);
assert.equal(stat.size, 1024); assert.strictEqual(stat.size, 1024);
fs.ftruncateSync(fd); fs.ftruncateSync(fd);
stat = fs.statSync(filename); stat = fs.statSync(filename);
assert.equal(stat.size, 0); assert.strictEqual(stat.size, 0);
fs.closeSync(fd); fs.closeSync(fd);
@ -54,19 +54,19 @@ function testTruncate(cb) {
if (er) return cb(er); if (er) return cb(er);
fs.stat(filename, function(er, stat) { fs.stat(filename, function(er, stat) {
if (er) return cb(er); if (er) return cb(er);
assert.equal(stat.size, 1024 * 16); assert.strictEqual(stat.size, 1024 * 16);
fs.truncate(filename, 1024, function(er) { fs.truncate(filename, 1024, function(er) {
if (er) return cb(er); if (er) return cb(er);
fs.stat(filename, function(er, stat) { fs.stat(filename, function(er, stat) {
if (er) return cb(er); if (er) return cb(er);
assert.equal(stat.size, 1024); assert.strictEqual(stat.size, 1024);
fs.truncate(filename, function(er) { fs.truncate(filename, function(er) {
if (er) return cb(er); if (er) return cb(er);
fs.stat(filename, function(er, stat) { fs.stat(filename, function(er, stat) {
if (er) return cb(er); if (er) return cb(er);
assert.equal(stat.size, 0); assert.strictEqual(stat.size, 0);
cb(); cb();
}); });
}); });
@ -82,7 +82,7 @@ function testFtruncate(cb) {
if (er) return cb(er); if (er) return cb(er);
fs.stat(filename, function(er, stat) { fs.stat(filename, function(er, stat) {
if (er) return cb(er); if (er) return cb(er);
assert.equal(stat.size, 1024 * 16); assert.strictEqual(stat.size, 1024 * 16);
fs.open(filename, 'w', function(er, fd) { fs.open(filename, 'w', function(er, fd) {
if (er) return cb(er); if (er) return cb(er);
@ -90,13 +90,13 @@ function testFtruncate(cb) {
if (er) return cb(er); if (er) return cb(er);
fs.stat(filename, function(er, stat) { fs.stat(filename, function(er, stat) {
if (er) return cb(er); if (er) return cb(er);
assert.equal(stat.size, 1024); assert.strictEqual(stat.size, 1024);
fs.ftruncate(fd, function(er) { fs.ftruncate(fd, function(er) {
if (er) return cb(er); if (er) return cb(er);
fs.stat(filename, function(er, stat) { fs.stat(filename, function(er, stat) {
if (er) return cb(er); if (er) return cb(er);
assert.equal(stat.size, 0); assert.strictEqual(stat.size, 0);
fs.close(fd, cb); fs.close(fd, cb);
}); });
}); });

Loading…
Cancel
Save