Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add ES6 and improve test-fs-truncate #10167

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions test/parallel/test-fs-truncate.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');
var tmp = common.tmpDir;
var filename = path.resolve(tmp, 'truncate-file.txt');
var data = Buffer.alloc(1024 * 16, 'x');
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmp = common.tmpDir;
const filename = path.resolve(tmp, 'truncate-file.txt');
const data = Buffer.alloc(1024 * 16, 'x');

common.refreshTmpDir();

var stat;
let stat;

// truncateSync
fs.writeFileSync(filename, data);
stat = fs.statSync(filename);
assert.equal(stat.size, 1024 * 16);
assert.strictEqual(stat.size, 1024 * 16);

fs.truncateSync(filename, 1024);
stat = fs.statSync(filename);
assert.equal(stat.size, 1024);
assert.strictEqual(stat.size, 1024);

fs.truncateSync(filename);
stat = fs.statSync(filename);
assert.equal(stat.size, 0);
assert.strictEqual(stat.size, 0);

// ftruncateSync
fs.writeFileSync(filename, data);
var fd = fs.openSync(filename, 'r+');
const fd = fs.openSync(filename, 'r+');

stat = fs.statSync(filename);
assert.equal(stat.size, 1024 * 16);
assert.strictEqual(stat.size, 1024 * 16);

fs.ftruncateSync(fd, 1024);
stat = fs.statSync(filename);
assert.equal(stat.size, 1024);
assert.strictEqual(stat.size, 1024);

fs.ftruncateSync(fd);
stat = fs.statSync(filename);
assert.equal(stat.size, 0);
assert.strictEqual(stat.size, 0);

fs.closeSync(fd);

Expand All @@ -54,19 +54,19 @@ function testTruncate(cb) {
if (er) return cb(er);
fs.stat(filename, function(er, stat) {
if (er) return cb(er);
assert.equal(stat.size, 1024 * 16);
assert.strictEqual(stat.size, 1024 * 16);

fs.truncate(filename, 1024, function(er) {
if (er) return cb(er);
fs.stat(filename, function(er, stat) {
if (er) return cb(er);
assert.equal(stat.size, 1024);
assert.strictEqual(stat.size, 1024);

fs.truncate(filename, function(er) {
if (er) return cb(er);
fs.stat(filename, function(er, stat) {
if (er) return cb(er);
assert.equal(stat.size, 0);
assert.strictEqual(stat.size, 0);
cb();
});
});
Expand All @@ -82,21 +82,21 @@ function testFtruncate(cb) {
if (er) return cb(er);
fs.stat(filename, function(er, stat) {
if (er) return cb(er);
assert.equal(stat.size, 1024 * 16);
assert.strictEqual(stat.size, 1024 * 16);

fs.open(filename, 'w', function(er, fd) {
if (er) return cb(er);
fs.ftruncate(fd, 1024, function(er) {
if (er) return cb(er);
fs.stat(filename, function(er, stat) {
if (er) return cb(er);
assert.equal(stat.size, 1024);
assert.strictEqual(stat.size, 1024);

fs.ftruncate(fd, function(er) {
if (er) return cb(er);
fs.stat(filename, function(er, stat) {
if (er) return cb(er);
assert.equal(stat.size, 0);
assert.strictEqual(stat.size, 0);
fs.close(fd, cb);
});
});
Expand Down