node/test/parallel/test-fs-buffertype-writesync.js
João Reis 8ef68e66d0 test: clean tmpdir on process exit
PR-URL: https://github.com/nodejs/node/pull/28858
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2019-08-10 19:22:11 -07:00

24 lines
636 B
JavaScript

'use strict';
require('../common');
// This test ensures that writeSync does support inputs which
// are then correctly converted into string buffers.
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const filePath = path.join(tmpdir.path, 'test_buffer_type');
const v = [true, false, 0, 1, Infinity, () => {}, {}, [], undefined, null];
tmpdir.refresh();
v.forEach((value) => {
const fd = fs.openSync(filePath, 'w');
fs.writeSync(fd, value);
assert.strictEqual(fs.readFileSync(filePath).toString(), String(value));
fs.closeSync(fd);
});