forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: increase coverage for fs.promises.truncate
To increase test coverage, added tests for fs.promises.truncate and FileHandle.truncate. PR-URL: nodejs#20638 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const path = require('path'); | ||
const { open, readFile } = require('fs').promises; | ||
const tmpdir = require('../common/tmpdir'); | ||
|
||
tmpdir.refresh(); | ||
common.crashOnUnhandledRejection(); | ||
|
||
async function validateTruncate() { | ||
const text = 'Hello world'; | ||
const filename = path.resolve(tmpdir.path, 'truncate-file.txt'); | ||
const fileHandle = await open(filename, 'w+'); | ||
|
||
const buffer = Buffer.from(text, 'utf8'); | ||
await fileHandle.write(buffer, 0, buffer.length); | ||
|
||
assert.deepStrictEqual((await readFile(filename)).toString(), text); | ||
|
||
await fileHandle.truncate(5); | ||
assert.deepStrictEqual((await readFile(filename)).toString(), 'Hello'); | ||
} | ||
|
||
validateTruncate().then(common.mustCall()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters