node/test/parallel/test-fs-truncate-fd.js
Nigel Kibodeaux c9945672fc test: modernize test-fs-truncate-fd
- changed `var` to `const` where variables were not reassigned.
- changed `assert.equal` to `assert.strictEqual` because there was no
downside to being more rigorous.

PR-URL: https://github.com/nodejs/node/pull/9978
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-12-05 12:41:20 -08:00

22 lines
587 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');
const fs = require('fs');
const tmp = common.tmpDir;
common.refreshTmpDir();
const filename = path.resolve(tmp, 'truncate-file.txt');
fs.writeFileSync(filename, 'hello world', 'utf8');
const fd = fs.openSync(filename, 'r+');
fs.truncate(fd, 5, common.mustCall(function(err) {
assert.ok(!err);
assert.strictEqual(fs.readFileSync(filename, 'utf8'), 'hello');
}));
process.on('exit', function() {
fs.closeSync(fd);
fs.unlinkSync(filename);
console.log('ok');
});