Skip to content

Commit d39a521

Browse files
authored
Merge pull request #25 from jeskew/feature/credential-provider-ini
Feature/credential provider ini
2 parents 6dddf93 + 3839b79 commit d39a521

File tree

7 files changed

+1276
-0
lines changed

7 files changed

+1276
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/node_modules/
2+
*.js
3+
*.js.map
4+
*.d.ts
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
interface FsModule {
2+
__addMatcher(toMatch: string, toReturn: string): void;
3+
__clearMatchers(): void;
4+
readFile: (path: string, encoding: string, cb: Function) => void;
5+
}
6+
7+
const fs: FsModule = <FsModule>jest.genMockFromModule("fs");
8+
let matchers: { [key: string]: string } = {};
9+
10+
function __addMatcher(toMatch: string, toReturn: string): void {
11+
matchers[toMatch] = toReturn;
12+
}
13+
14+
function __clearMatchers(): void {
15+
matchers = {};
16+
}
17+
18+
function readFile(
19+
path: string,
20+
encoding: string,
21+
callback: (err: Error | null, data?: string) => void
22+
): void {
23+
for (let key of Object.keys(matchers)) {
24+
if (key === path) {
25+
callback(null, matchers[key]);
26+
return;
27+
}
28+
}
29+
30+
callback(new Error("ENOENT: no such file or directory"));
31+
}
32+
33+
fs.__addMatcher = __addMatcher;
34+
fs.__clearMatchers = __clearMatchers;
35+
fs.readFile = readFile;
36+
37+
module.exports = fs;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
interface OsModule {
2+
homedir: () => string;
3+
}
4+
5+
const os: OsModule = <OsModule>jest.genMockFromModule("os");
6+
const path = require("path");
7+
8+
os.homedir = () => path.sep + path.join("home", "user");
9+
10+
module.exports = os;

0 commit comments

Comments
 (0)