Skip to content

Commit ba3b775

Browse files
committed
Add a credential provider that reads from shared ini files
1 parent cebedea commit ba3b775

File tree

7 files changed

+1139
-0
lines changed

7 files changed

+1139
-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+
const matchers = new Map<string, string>();
9+
10+
function __addMatcher(toMatch: string, toReturn: string): void {
11+
matchers.set(toMatch, toReturn);
12+
}
13+
14+
function __clearMatchers(): void {
15+
matchers.clear();
16+
}
17+
18+
function readFile(
19+
path: string,
20+
encoding: string,
21+
callback: (err: Error|null, data?: string) => void
22+
): void {
23+
for (let [matcher, data] of matchers.entries()) {
24+
if (matcher === path) {
25+
callback(null, data);
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)