-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
6,137 additions
and
48 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,14 @@ | ||
|
||
|
||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
coverage | ||
dist | ||
node_modules |
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 |
---|---|---|
@@ -1,4 +1,7 @@ | ||
.gitignore | ||
__mocks__ | ||
__tests__ | ||
coverage | ||
prettier.config.js | ||
src | ||
tsconfig.json |
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,74 @@ | ||
const fs = jest.genMockFromModule("fs") as any; | ||
|
||
interface FileMap { | ||
[fname: string]: string; | ||
} | ||
|
||
let mockDirs: string[] = []; | ||
fs.__setMockDirs = (dirs: string[]) => { | ||
mockDirs = dirs; | ||
} | ||
|
||
let mockFiles: FileMap = {}; | ||
fs.__setMockFiles = (files: FileMap) => { | ||
mockFiles = files; | ||
} | ||
|
||
let mockRealPaths: FileMap = {}; | ||
fs.__setMockRealPaths = (realPaths: FileMap) => { | ||
mockRealPaths = realPaths; | ||
} | ||
|
||
let mockWrittenFiles: FileMap = {}; | ||
fs.__getMockWrittenFiles = (): FileMap => { | ||
return mockWrittenFiles; | ||
} | ||
|
||
fs.existsSync = (name: string): boolean => { | ||
if (name in mockFiles || `./${name}` in mockFiles) { | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
fs.mkdirSync = (name: string): void => { | ||
} | ||
|
||
fs.readFileSync = (name: string): string => { | ||
if (name in mockFiles) { | ||
return mockFiles[name]; | ||
} | ||
if (mockFiles[`./${name}`]) { | ||
return mockFiles[`./${name}`]; | ||
} | ||
throw new Error(`Unknown file ${name}`); | ||
} | ||
|
||
fs.realpathSync = (name: string) => { | ||
if (name in mockRealPaths) { | ||
return mockRealPaths[name]; | ||
} | ||
if (`./${name}` in mockRealPaths) { | ||
return mockRealPaths[`./${name}`]; | ||
} | ||
throw new Error(`Unknown realpath ${name}`); | ||
} | ||
|
||
fs.statSync = (name: string) => { | ||
if (name in mockFiles) { | ||
return { isFile: () => true }; | ||
} | ||
if (`./${name}` in mockFiles) { | ||
return { isFile: () => true }; | ||
} | ||
if (mockDirs.includes(name)) { | ||
return { isFile: () => false }; | ||
} | ||
throw new Error(`Unknown file ${name}`); | ||
} | ||
|
||
fs.writeFileSync = (name: string, contents: string): void => { | ||
mockWrittenFiles[name] = contents; | ||
} | ||
|
||
module.exports = fs; |
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,43 @@ | ||
const path = jest.genMockFromModule("path") as any; | ||
|
||
interface PathMap { | ||
[fname: string]: string; | ||
} | ||
|
||
let mockBasename: PathMap = {}; | ||
path.__setMockBasenames = (basenames: PathMap) => { | ||
mockBasename = basenames; | ||
}; | ||
|
||
let mockDirname: PathMap = {}; | ||
path.__setMockDirnames = (dirnames: PathMap) => { | ||
mockDirname = dirnames; | ||
}; | ||
|
||
let mockRelative: PathMap = {}; | ||
path.__setMockRelatives = (relatives: PathMap) => { | ||
mockRelative = relatives; | ||
}; | ||
|
||
path.basename = (name: string): string => { | ||
if (name in mockBasename) { | ||
return mockBasename[name]; | ||
} | ||
throw new Error(`Unknown file ${name}`); | ||
}; | ||
|
||
path.dirname = (name: string): string => { | ||
if (name in mockDirname) { | ||
return mockDirname[name]; | ||
} | ||
throw new Error(`Unknown dirname ${name}`); | ||
}; | ||
|
||
path.relative = (folder: string, name: string): string => { | ||
if (`${folder}#${name}` in mockRelative) { | ||
return mockRelative[`${folder}#${name}`]; | ||
} | ||
throw new Error(`Unknown relative ${folder}, ${name}`); | ||
}; | ||
|
||
module.exports = path; |
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,4 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
Oops, something went wrong.