-
Notifications
You must be signed in to change notification settings - Fork 774
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copyFileFallback tests when running on more recent Node
- Loading branch information
Maxime Bargiel
committed
Jun 1, 2019
1 parent
f55125e
commit 1a6eacb
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
/* global after, describe */ | ||
|
||
if (typeof fs.copyFileSync === 'function') { | ||
// Re-run all copySync tests without fs.copyFileSync | ||
describe('> when using copyFileSyncFallback', () => { | ||
const originalCopyFile = fs.copyFileSync | ||
|
||
after(done => { | ||
fs.copyFileSync = originalCopyFile | ||
done() | ||
}) | ||
|
||
delete fs.copyFileSync | ||
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) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
/* global after, describe */ | ||
|
||
if (typeof fs.copyFile === 'function') { | ||
// Re-run all copy tests without fs.copyFile | ||
describe('> when using copyFileFallback', () => { | ||
const originalCopyFile = fs.copyFile | ||
|
||
after(done => { | ||
fs.copyFile = originalCopyFile | ||
done() | ||
}) | ||
|
||
delete fs.copyFile | ||
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) | ||
}) | ||
}) | ||
} |