From 922c4573657f7fdc4f5ea7203d2d974fd3df2913 Mon Sep 17 00:00:00 2001 From: Luca Maraschi Date: Wed, 12 Apr 2017 09:34:27 +0200 Subject: [PATCH] test: buffer should always be stringified This test makes sure that independently of the buffer type, the input is always stringified and generates a valid input. PR-URL: https://github.com/nodejs/node/pull/12355 Reviewed-By: Vse Mozhet Byt Reviewed-By: James M Snell Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Sakthipriyan Vairamani --- test/parallel/test-fs-buffertype-writesync.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/parallel/test-fs-buffertype-writesync.js diff --git a/test/parallel/test-fs-buffertype-writesync.js b/test/parallel/test-fs-buffertype-writesync.js new file mode 100644 index 00000000000000..0c8bf4b0fcf811 --- /dev/null +++ b/test/parallel/test-fs-buffertype-writesync.js @@ -0,0 +1,20 @@ +'use strict'; +const common = 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 filePath = path.join(common.tmpDir, 'test_buffer_type'); +const v = [true, false, 0, 1, Infinity, common.noop, {}, [], undefined, null]; + +common.refreshTmpDir(); + +v.forEach((value) => { + const fd = fs.openSync(filePath, 'w'); + fs.writeSync(fd, value); + assert.strictEqual(fs.readFileSync(filePath).toString(), value + ''); +});