Permalink
Browse files

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 <hello@about-hiroppy.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
Trott authored and MylesBorins committed Sep 3, 2017
1 parent a260190 commit 2babae4cd4313e7a14e4a8f2cfe33ea9b58347b1
Showing with 5 additions and 9 deletions.
  1. +5 −9 test/parallel/test-fs-readfile-unlink.js
@@ -3,16 +3,11 @@ const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const dirName = path.resolve(common.fixturesDir, 'test-readfile-unlink');
const fileName = path.resolve(dirName, 'test.bin');
const fileName = path.resolve(common.tmpDir, 'test.bin');
const buf = Buffer.alloc(512 * 1024, 42);
try {
fs.mkdirSync(dirName);
} catch (e) {
// Ignore if the directory already exists.
if (e.code !== 'EEXIST') throw e;
}
common.refreshTmpDir();
fs.writeFileSync(fileName, buf);
@@ -21,6 +16,7 @@ fs.readFile(fileName, function(err, data) {
assert.strictEqual(data.length, buf.length);
assert.strictEqual(buf[0], 42);
// Unlink should not throw. This is part of the test. It used to throw on
// Windows due to a bug.
fs.unlinkSync(fileName);
fs.rmdirSync(dirName);
});

0 comments on commit 2babae4

Please sign in to comment.