Skip to content

Commit 2ecc5ea

Browse files
TrottMylesBorins
authored andcommitted
test: refactor test-fs-readfile-unlink
* Use tmp directory instead of mutating the fixtures directory. * Add comment explaining that the unlinkSync() at the end of the test is part of the test. Otherwise it may be tempting to remove it as unnecessary tmp directory cleanup. PR-URL: #15173 Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0115bd7 commit 2ecc5ea

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

test/parallel/test-fs-readfile-unlink.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@ const assert = require('assert');
44
const fs = require('fs');
55
const path = require('path');
66
const dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink');
7-
const fileName = path.resolve(dirName, 'test.bin');
7+
const fileName = path.resolve(common.tmpDir, 'test.bin');
8+
89
const buf = Buffer.alloc(512 * 1024, 42);
910

10-
try {
11-
fs.mkdirSync(dirName);
12-
} catch (e) {
13-
// Ignore if the directory already exists.
14-
if (e.code !== 'EEXIST') throw e;
15-
}
11+
common.refreshTmpDir();
1612

1713
fs.writeFileSync(fileName, buf);
1814

@@ -21,6 +17,7 @@ fs.readFile(fileName, function(err, data) {
2117
assert.strictEqual(data.length, buf.length);
2218
assert.strictEqual(buf[0], 42);
2319

20+
// Unlink should not throw. This is part of the test. It used to throw on
21+
// Windows due to a bug.
2422
fs.unlinkSync(fileName);
25-
fs.rmdirSync(dirName);
2623
});

0 commit comments

Comments
 (0)