Skip to content

Commit

Permalink
test: refactor test-fs-readfile-unlink
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Trott authored and MylesBorins committed Sep 21, 2017
1 parent 0115bd7 commit ec84335
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions test/parallel/test-fs-readfile-unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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 ec84335

Please sign in to comment.