GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: increase coverage for fs.promises.truncate · nodejs/node@94dcdfb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/parallel
    • test-fs-promises-file-handle-truncate.js
    • test-fs-promises.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/parallel/test-fs-promises-file-handle-truncate.js‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const path = require('path');
6+
const { open, readFile } = require('fs').promises;
7+
const tmpdir = require('../common/tmpdir');
8+
9+
tmpdir.refresh();
10+
common.crashOnUnhandledRejection();
11+
12+
async function validateTruncate() {
13+
const text = 'Hello world';
14+
const filename = path.resolve(tmpdir.path, 'truncate-file.txt');
15+
const fileHandle = await open(filename, 'w+');
16+
17+
const buffer = Buffer.from(text, 'utf8');
18+
await fileHandle.write(buffer, 0, buffer.length);
19+
20+
assert.deepStrictEqual((await readFile(filename)).toString(), text);
21+
22+
await fileHandle.truncate(5);
23+
assert.deepStrictEqual((await readFile(filename)).toString(), 'Hello');
24+
}
25+
26+
validateTruncate().then(common.mustCall());
Collapse file

‎test/parallel/test-fs-promises.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-promises.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ const {
1717
mkdir,
1818
mkdtemp,
1919
open,
20+
readFile,
2021
readdir,
2122
readlink,
2223
realpath,
2324
rename,
2425
rmdir,
2526
stat,
2627
symlink,
28+
truncate,
2729
unlink,
2830
utimes
2931
} = fsPromises;
@@ -99,6 +101,8 @@ function verifyStatObject(stat) {
99101
const ret2 = await handle.read(Buffer.alloc(buf2Len), 0, buf2Len, 0);
100102
assert.strictEqual(ret2.bytesRead, buf2Len);
101103
assert.deepStrictEqual(ret2.buffer, buf2);
104+
await truncate(dest, 5);
105+
assert.deepStrictEqual((await readFile(dest)).toString(), 'hello');
102106

103107
await chmod(dest, 0o666);
104108
await handle.chmod(0o666);

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.