From 182e112acde9cfdd6a16a13e7faf9cb866953800 Mon Sep 17 00:00:00 2001 From: Maxime Bargiel Date: Mon, 9 Sep 2019 16:41:23 -0400 Subject: [PATCH] Fix copy(Sync)Fallback tests for real --- .../__tests__/copyfilesync-fallback.test.js | 38 ++++++++++--------- lib/copy/__tests__/copyfile-fallback.test.js | 32 +++++++++------- 2 files changed, 39 insertions(+), 31 deletions(-) diff --git a/lib/copy-sync/__tests__/copyfilesync-fallback.test.js b/lib/copy-sync/__tests__/copyfilesync-fallback.test.js index 7a619a3f..582437d9 100644 --- a/lib/copy-sync/__tests__/copyfilesync-fallback.test.js +++ b/lib/copy-sync/__tests__/copyfilesync-fallback.test.js @@ -1,25 +1,29 @@ -const fs = require('../../') +const fs = require('graceful-fs') const path = require('path') -/* global describe */ +/* global describe, beforeEach, afterEach */ if (typeof fs.copyFileSync === 'function') { - // Also load copy-sync tests without fs.copyFileSync - describe('> when using copyFileSyncFallback', () => { - const originalCopyFile = fs.copyFileSync + // Also load copy tests without fs.copyFileSync + describe('> when using copyFileFallback', () => { + const originalCopyFileSync = fs.copyFileSync + + beforeEach(() => { + // reset stubs + delete fs.copyFileSync + }) + + afterEach(() => { + fs.copyFileSync = originalCopyFileSync + }) - delete fs.copyFileSync const fallbackTest = path.basename(__filename) - try { - fs.readdirSync(__dirname) - .filter(filename => filename.endsWith('.test.js') && filename !== fallbackTest) - .map(filename => { - const testModule = `./${filename}` - delete require.cache[require.resolve(testModule)] - require(testModule) - }) - } finally { - fs.copyFileSync = originalCopyFile - } + fs.readdirSync(__dirname) + .filter(filename => filename.endsWith('.test.js') && filename !== fallbackTest) + .map(filename => { + const testModule = `./${filename}` + delete require.cache[require.resolve(testModule)] + require(testModule) + }) }) } diff --git a/lib/copy/__tests__/copyfile-fallback.test.js b/lib/copy/__tests__/copyfile-fallback.test.js index d32d57ba..3340ca77 100644 --- a/lib/copy/__tests__/copyfile-fallback.test.js +++ b/lib/copy/__tests__/copyfile-fallback.test.js @@ -1,25 +1,29 @@ -const fs = require('../../') +const fs = require('graceful-fs') const path = require('path') -/* global describe */ +/* global describe, beforeEach, afterEach */ if (typeof fs.copyFile === 'function') { // Also load copy tests without fs.copyFile describe('> when using copyFileFallback', () => { const originalCopyFile = fs.copyFile - delete fs.copyFile - const fallbackTest = path.basename(__filename) - try { - fs.readdirSync(__dirname) - .filter(filename => filename.endsWith('.test.js') && filename !== fallbackTest) - .map(filename => { - const testModule = `./${filename}` - delete require.cache[require.resolve(testModule)] - require(testModule) - }) - } finally { + beforeEach(() => { + // reset stubs + delete fs.copyFile + }) + + afterEach(() => { fs.copyFile = originalCopyFile - } + }) + + const fallbackTest = path.basename(__filename) + fs.readdirSync(__dirname) + .filter(filename => filename.endsWith('.test.js') && filename !== fallbackTest) + .map(filename => { + const testModule = `./${filename}` + delete require.cache[require.resolve(testModule)] + require(testModule) + }) }) }