{"size": 1095, "ext": "js", "max_stars_repo_path": "src/__mocks__/fs.js", "max_stars_repo_name": "dawsontoth/gaffer", "max_stars_repo_stars_event_min_datetime": "2019-05-09T18:26:20.000Z", "max_stars_repo_stars_event_max_datetime": "2019-08-21T19:26:47.000Z", "max_issues_repo_path": "src/__mocks__/fs.js", "max_issues_repo_name": "dawsontoth/gaffer", "max_issues_repo_issues_event_min_datetime": "2019-11-02T21:58:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T10:02:32.000Z", "max_forks_repo_path": "src/__mocks__/fs.js", "max_forks_repo_name": "dawsontoth/gaffer-generator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 48, "max_forks_count": null, "avg_line_length": 18.25, "max_line_length": 56, "alphanum_fraction": 0.6611872146}
const path = require('path');

/*
 Testing utility API.
 */
const fs = jest.genMockFromModule('fs');
const responses = {};
let mockFiles = {};
fs.__setMockFiles = __setMockFiles;
fs.__setResponse = __setResponse;
fs.__spy = {};
const mockedMethods = [
  'existsSync',
  'readFileSync',
  'writeFileSync',
  'mkdirSync',
];

/*
 Mocked API.
 */
fs.readdirSync = readdirSync;
for (const mockedMethod of mockedMethods) {
  fs[mockedMethod] = respond(mockedMethod);
  fs.__spy[mockedMethod] = jest.spyOn(fs, mockedMethod);
}

module.exports = fs;

/*
 Implementation.
 */

function __setMockFiles(newMockFiles) {
  mockFiles = {};
  for (const file of newMockFiles) {
    const dir = path.dirname(file);
    if (!mockFiles[dir]) {
      mockFiles[dir] = [];
    }
    mockFiles[dir].push(path.basename(file));
  }
}

function __setResponse(method, val) {
  responses[method] = val;
}

function readdirSync(directoryPath) {
  return mockFiles[directoryPath] || [];
}

function respond(method) {
  return () => {
    if (responses[method] !== undefined) {
      return responses[method];
    }
  };
}
