From 0b9fde4d4a4394debd1c3035d8e0f60dde852a83 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 3 Sep 2017 11:09:13 -0700 Subject: [PATCH] test: refactor test-fs-readfile-unlink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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: https://github.com/nodejs/node/pull/15173 Reviewed-By: Yuta Hiroto Reviewed-By: Michaƫl Zasso Reviewed-By: Benjamin Gruenbaum Reviewed-By: Daniel Bevenius Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/parallel/test-fs-readfile-unlink.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-fs-readfile-unlink.js b/test/parallel/test-fs-readfile-unlink.js index 9c931c5f4e5195..abcbed7ad5df53 100644 --- a/test/parallel/test-fs-readfile-unlink.js +++ b/test/parallel/test-fs-readfile-unlink.js @@ -20,22 +20,15 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const fs = require('fs'); const path = require('path'); -const fixtures = require('../common/fixtures'); -const dirName = fixtures.path('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); @@ -44,6 +37,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); });