Skip to content

Commit

Permalink
Save jest experimentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mmgoodnow committed Oct 24, 2020
1 parent 7fa98b7 commit 6935e52
Show file tree
Hide file tree
Showing 21 changed files with 4,447 additions and 378 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Expand Up @@ -2,7 +2,8 @@
"env": {
"node": true,
"commonjs": true,
"es2021": true
"es2021": true,
"jest": true
},
"extends": "eslint:recommended",
"parserOptions": {
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -118,3 +118,5 @@ dist
*.torrent
torrents/
config.js
output/
input/
5 changes: 4 additions & 1 deletion .idea/cross-seed.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions __mocks__/fs.js
@@ -0,0 +1,32 @@
"use strict";

const path = require("path");

const fs = jest.createMockFromModule("fs");

// This is a custom function that our tests can use during setup to specify
// what the files on the "mock" filesystem should look like when any of the
// `fs` APIs are used.
let mockFiles = Object.create(null);
function __setMockFiles(newMockFiles) {
mockFiles = Object.create(null);
for (const file in newMockFiles) {
const dir = path.dirname(file);

if (!mockFiles[dir]) {
mockFiles[dir] = [];
}
mockFiles[dir].push(path.basename(file));
}
}

// A custom version of `readdirSync` that reads from the special mocked out
// file list set via __setMockFiles
function readdirSync(directoryPath) {
return mockFiles[directoryPath] || [];
}

fs.__setMockFiles = __setMockFiles;
fs.readdirSync = readdirSync;

module.exports = fs;
13 changes: 13 additions & 0 deletions __mocks__/path.js
@@ -0,0 +1,13 @@
"use strict";

const path = jest.createMockFromModule("path");

// A custom version of `readdirSync` that reads from the special mocked out
// file list set via __setMockFiles
function join(...args) {
return args.join("/");
}

path.join = join;

module.exports = path;

0 comments on commit 6935e52

Please sign in to comment.