-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: remove mock-fs, to run unit tests in nodefs v20
- Loading branch information
Showing
18 changed files
with
82 additions
and
46 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 |
---|---|---|
|
@@ -11,4 +11,5 @@ dist | |
/coverage | ||
/package-lock.json | ||
/yarn.lock | ||
/tmpdir* | ||
.npmrc |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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,42 @@ | ||
const { mkdtempSync, rmSync, mkdirSync, writeFileSync } = require('fs'); | ||
const { join, dirname } = require('path'); | ||
const tmpdir = mkdtempSync(join(__dirname, '..', '..', 'tmpdir-')); | ||
// By default work in a child folder. Some tests run against parent folder | ||
const defaultdir = join(tmpdir, 'a'); | ||
|
||
function fillFiles(fileTree, baseDir = defaultdir) { | ||
mkdirSync(baseDir, { recursive: true }); | ||
for (const key in fileTree) { | ||
const val = fileTree[key]; | ||
const p = join(baseDir, key); | ||
if (typeof val === 'string') { | ||
mkdirSync(dirname(p), { recursive: true }); | ||
writeFileSync(p, val); | ||
} else if (typeof val === 'object') { | ||
fillFiles(val, p); | ||
} | ||
} | ||
} | ||
|
||
let oldCwd; | ||
|
||
// Simple implementation of mockfs in local tmp dir. | ||
function mockfs(fileTree) { | ||
fillFiles(fileTree); | ||
if (!oldCwd) { | ||
oldCwd = process.cwd(); | ||
process.chdir(defaultdir); | ||
} | ||
} | ||
|
||
mockfs.restore = function() { | ||
if (oldCwd) { | ||
process.chdir(oldCwd); | ||
oldCwd = undefined; | ||
} | ||
rmSync(tmpdir, { force: true, recursive: true }); | ||
} | ||
|
||
process.on('exit', mockfs.restore); | ||
|
||
module.exports = mockfs; |