-
-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #173 from Oblongmana/fix/theme-include-directory-j…
…oinin Fix: `fetchTheme` theme 'include' directory joining for absolute paths
- Loading branch information
Showing
5 changed files
with
1,736 additions
and
3 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,33 @@ | ||
// __mocks__/fs.ts | ||
import path from 'path' | ||
|
||
const fs = jest.createMockFromModule<any>('fs') | ||
|
||
// This is a custom function that our tests can use during setup to specify | ||
// what the files on the "mock" filesystem should look like when any of the | ||
// `fs` APIs are used. | ||
let mockFiles = Object.create(null) | ||
function __setMockFiles(newMockFiles) { | ||
mockFiles = Object.create(null) | ||
for (const file in newMockFiles) { | ||
const dir = path.dirname(file) | ||
|
||
if (!mockFiles[dir]) { | ||
mockFiles[dir] = [] | ||
} | ||
mockFiles[dir].push(path.basename(file)) | ||
} | ||
} | ||
|
||
// A custom version of `fs.promises.readFile` that reads from the special mocked out | ||
// file list set via __setMockFiles | ||
function promisesReadFile(directoryPath) { | ||
return mockFiles[directoryPath] || [] | ||
} | ||
|
||
fs.__setMockFiles = __setMockFiles | ||
fs.promises = { | ||
readFile: promisesReadFile | ||
} | ||
|
||
module.exports = fs |
Oops, something went wrong.