Skip to content

Commit 0b9fde4

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 da5e6d3 commit 0b9fde4

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

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

+5-11
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,15 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const assert = require('assert');
2525
const fs = require('fs');
2626
const path = require('path');
27-
const fixtures = require('../common/fixtures');
2827

29-
const dirName = fixtures.path('test-readfile-unlink');
30-
const fileName = path.resolve(dirName, 'test.bin');
28+
const fileName = path.resolve(common.tmpDir, 'test.bin');
3129
const buf = Buffer.alloc(512 * 1024, 42);
3230

33-
try {
34-
fs.mkdirSync(dirName);
35-
} catch (e) {
36-
// Ignore if the directory already exists.
37-
if (e.code !== 'EEXIST') throw e;
38-
}
31+
common.refreshTmpDir();
3932

4033
fs.writeFileSync(fileName, buf);
4134

@@ -44,6 +37,7 @@ fs.readFile(fileName, function(err, data) {
4437
assert.strictEqual(data.length, buf.length);
4538
assert.strictEqual(buf[0], 42);
4639

40+
// Unlink should not throw. This is part of the test. It used to throw on
41+
// Windows due to a bug.
4742
fs.unlinkSync(fileName);
48-
fs.rmdirSync(dirName);
4943
});

0 commit comments

Comments
 (0)