Skip to content

Commit 8a08e0c

Browse files
author
Mert Can Altin
committed
test: remove large file limit assertion for fs.readFile
1 parent 354ee99 commit 8a08e0c

File tree

2 files changed

+39
-27
lines changed

2 files changed

+39
-27
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
require('../common');
3+
4+
const { spawnSync } = require('node:child_process');
5+
const assert = require('node:assert');
6+
7+
const result = spawnSync(process.execPath, ['-e', `
8+
const port = await getPort();
9+
`]);
10+
11+
assert.strictEqual(result.stderr.includes('Top-level await is not supported in CommonJS'), true);

test/parallel/test-fs-promises-file-handle-readFile.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ const common = require('../common');
55
// The following tests validate base functionality for the fs.promises
66
// FileHandle.readFile method.
77

8-
const fs = require('fs');
8+
const fs = require('node:fs');
99
const {
1010
open,
1111
readFile,
1212
writeFile,
13-
truncate,
1413
} = fs.promises;
15-
const path = require('path');
14+
const path = require('node:path');
15+
const os = require('node:os');
1616
const tmpdir = require('../common/tmpdir');
1717
const tick = require('../common/tick');
18-
const assert = require('assert');
18+
const assert = require('node:assert');
1919
const tmpDir = tmpdir.path;
2020

2121
tmpdir.refresh();
@@ -35,6 +35,29 @@ async function validateReadFile() {
3535
await fileHandle.close();
3636
}
3737

38+
async function validateLargeFileSupport() {
39+
const LARGE_FILE_SIZE = 3 * 1024 * 1024 * 1024; // 3 GiB
40+
const FILE_PATH = path.join(os.tmpdir(), 'large-virtual-file.bin');
41+
42+
function createVirtualLargeFile() {
43+
return Buffer.alloc(LARGE_FILE_SIZE, 'A');
44+
}
45+
46+
const virtualFile = createVirtualLargeFile();
47+
48+
await writeFile(FILE_PATH, virtualFile);
49+
50+
const buffer = await readFile(FILE_PATH);
51+
52+
assert.strictEqual(
53+
buffer.length,
54+
LARGE_FILE_SIZE,
55+
`Expected file size to be ${LARGE_FILE_SIZE}, but got ${buffer.length}`
56+
);
57+
58+
await fs.promises.unlink(FILE_PATH);
59+
}
60+
3861
async function validateReadFileProc() {
3962
// Test to make sure reading a file under the /proc directory works. Adapted
4063
// from test-fs-read-file-sync-hostname.js.
@@ -100,32 +123,10 @@ async function doReadAndCancel() {
100123

101124
await fileHandle.close();
102125
}
103-
104-
// Validate file size is within range for reading
105-
{
106-
// Variable taken from https://github.com/nodejs/node/blob/1377163f3351/lib/internal/fs/promises.js#L5
107-
const kIoMaxLength = 2 ** 31 - 1;
108-
109-
if (!tmpdir.hasEnoughSpace(kIoMaxLength)) {
110-
// truncate() will fail with ENOSPC if there is not enough space.
111-
common.printSkipMessage(`Not enough space in ${tmpDir}`);
112-
} else {
113-
const newFile = path.resolve(tmpDir, 'dogs-running3.txt');
114-
await writeFile(newFile, Buffer.from('0'));
115-
await truncate(newFile, kIoMaxLength + 1);
116-
117-
const fileHandle = await open(newFile, 'r');
118-
119-
await assert.rejects(fileHandle.readFile(), {
120-
name: 'RangeError',
121-
code: 'ERR_FS_FILE_TOO_LARGE'
122-
});
123-
await fileHandle.close();
124-
}
125-
}
126126
}
127127

128128
validateReadFile()
129+
.then(validateLargeFileSupport)
129130
.then(validateReadFileProc)
130131
.then(doReadAndCancel)
131132
.then(common.mustCall());

0 commit comments

Comments
 (0)