Skip to content

Commit

Permalink
Merge pull request #173 from Oblongmana/fix/theme-include-directory-j…
Browse files Browse the repository at this point in the history
…oinin

Fix: `fetchTheme` theme 'include' directory joining for absolute paths
  • Loading branch information
orta authored Aug 13, 2022
2 parents 8af5b1b + c26c14d commit 1ad7634
Show file tree
Hide file tree
Showing 5 changed files with 1,736 additions and 3 deletions.
33 changes: 33 additions & 0 deletions packages/shiki/src/__tests__/__mocks__/fs.ts
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
Loading

0 comments on commit 1ad7634

Please sign in to comment.