Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/credential-provider-ini/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
*.js
*.js.map
*.d.ts
37 changes: 37 additions & 0 deletions packages/credential-provider-ini/__mocks__/fs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
interface FsModule {
__addMatcher(toMatch: string, toReturn: string): void;
__clearMatchers(): void;
readFile: (path: string, encoding: string, cb: Function) => void
}

const fs: FsModule = <FsModule>jest.genMockFromModule('fs');
let matchers: {[key: string]: string} = {};

function __addMatcher(toMatch: string, toReturn: string): void {
matchers[toMatch] = toReturn;
}

function __clearMatchers(): void {
matchers = {};
}

function readFile(
path: string,
encoding: string,
callback: (err: Error|null, data?: string) => void
): void {
for (let key of Object.keys(matchers)) {
if (key === path) {
callback(null, matchers[key]);
return;
}
}

callback(new Error('ENOENT: no such file or directory'));
}

fs.__addMatcher = __addMatcher;
fs.__clearMatchers = __clearMatchers;
fs.readFile = readFile;

module.exports = fs;
10 changes: 10 additions & 0 deletions packages/credential-provider-ini/__mocks__/os.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
interface OsModule {
homedir: () => string;
}

const os: OsModule = <OsModule>jest.genMockFromModule('os');
const path = require('path');

os.homedir = () => path.sep + path.join('home', 'user');

module.exports = os;
Loading