0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/parallel/test-fs-promises-file-handle-writeFile.js
willhayslett 126b03e2f9 test: add tests for fs/promises.js fileHandle methods
Working to increase test code coverage for fs/promises.js.
Added tests for fileHandle.appendFile and fileHandle.chmod.

PR-URL: https://github.com/nodejs/node/pull/19605
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2018-04-04 19:05:29 -07:00

30 lines
845 B
JavaScript

'use strict';
const common = require('../common');
// The following tests validate base functionality for the fs/promises
// FileHandle.readFile method.
const fs = require('fs');
const { open } = require('fs/promises');
const path = require('path');
const tmpdir = require('../common/tmpdir');
const assert = require('assert');
const tmpDir = tmpdir.path;
tmpdir.refresh();
common.crashOnUnhandledRejection();
async function validateWriteFile() {
const filePathForHandle = path.resolve(tmpDir, 'tmp-write-file2.txt');
const fileHandle = await open(filePathForHandle, 'w+');
const buffer = Buffer.from('Hello world'.repeat(100), 'utf8');
await fileHandle.writeFile(buffer);
const readFileData = fs.readFileSync(filePathForHandle);
assert.deepStrictEqual(buffer, readFileData);
}
validateWriteFile()
.then(common.mustCall());