node/test/parallel/test-fs-buffertype-writesync.js
Rich Trott bf6ce47259 test: move tmpdir to submodule of common
Move tmpdir functionality to its own module (common/tmpdir).

PR-URL: https://github.com/nodejs/node/pull/17856
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-01-31 22:11:07 -08:00

23 lines
616 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));
});