Skip to content

Commit 7fe5303

Browse files
Trottjasnell
authored andcommitted
test: fix disabled test-fs-largefile
Add `common.refreshTmpDir()` before using the tmp directory. fs.writeSync no longer requires an integer for the position argument, so change test from `assert.throws()` to `assert.doesNotThrow()`. The test now passes. Because it involves a 5 GB file, we're not going to activate the test, although that is possible if we add checking for appropriate available resources (definitely disk space, likely memory, maybe check that it's a 64-bit OS). PR-URL: #13147 Reviewed-By: James M Snell <[email protected]>
1 parent 39785c7 commit 7fe5303

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

test/disabled/test-fs-largefile.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121

2222
'use strict';
2323
const common = require('../common');
24+
2425
const assert = require('assert');
25-
const path = require('path'),
26-
fs = require('fs'),
27-
filepath = path.join(common.tmpDir, 'large.txt'),
28-
fd = fs.openSync(filepath, 'w+'),
29-
offset = 5 * 1024 * 1024 * 1024, // 5GB
30-
message = 'Large File';
26+
const fs = require('fs');
27+
const path = require('path');
28+
29+
common.refreshTmpDir();
30+
31+
const filepath = path.join(common.tmpDir, 'large.txt');
32+
const fd = fs.openSync(filepath, 'w+');
33+
const offset = 5 * 1024 * 1024 * 1024; // 5GB
34+
const message = 'Large File';
3135

3236
fs.truncateSync(fd, offset);
3337
assert.strictEqual(fs.statSync(filepath).size, offset);
@@ -39,17 +43,13 @@ assert.strictEqual(readBuf.toString(), message);
3943
fs.readSync(fd, readBuf, 0, 1, 0);
4044
assert.strictEqual(readBuf[0], 0);
4145

42-
var exceptionRaised = false;
43-
try {
44-
fs.writeSync(fd, writeBuf, 0, writeBuf.length, 42.000001);
45-
} catch (err) {
46-
console.log(err);
47-
exceptionRaised = true;
48-
assert.strictEqual(err.message, 'Not an integer');
49-
}
50-
assert.ok(exceptionRaised);
46+
assert.doesNotThrow(
47+
() => { fs.writeSync(fd, writeBuf, 0, writeBuf.length, 42.000001); }
48+
);
5149
fs.close(fd);
5250

51+
// Normally, we don't clean up tmp files at the end of a test, but we'll make an
52+
// exception for a 5 GB file.
5353
process.on('exit', function() {
5454
fs.unlinkSync(filepath);
5555
});

0 commit comments

Comments
 (0)