Skip to content

Commit 5ebdbc1

Browse files
committed
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.
1 parent d932e80 commit 5ebdbc1

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

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

Lines changed: 5 additions & 11 deletions
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)