Skip to content

Commit 2babae4

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 a260190 commit 2babae4

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

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

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@ const common = require('../common');
33
const assert = require('assert');
44
const fs = require('fs');
55
const path = require('path');
6-
const dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink');
7-
const fileName = path.resolve(dirName, 'test.bin');
6+
const fileName = path.resolve(common.tmpDir, 'test.bin');
7+
88
const buf = Buffer.alloc(512 * 1024, 42);
99

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

1712
fs.writeFileSync(fileName, buf);
1813

@@ -21,6 +16,7 @@ fs.readFile(fileName, function(err, data) {
2116
assert.strictEqual(data.length, buf.length);
2217
assert.strictEqual(buf[0], 42);
2318

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

0 commit comments

Comments
 (0)