-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
32 lines (27 loc) · 912 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const fs = require("fs/promises");
const path = require("path");
/** Returns a random tmp directory name */
function randomDirName(tmpDir) {
return fs.mkdtemp(path.join(tmpDir, "node_modules-"));
}
/** Returns a random integer between min (inclusive) and max (inclusive) */
function getRandomArbitrary(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* NodeJS require cache is a global object that caches the result of the
* require function. To measure the speed of the require function we need to
* clear the cache. */
function clearRequireCache(spinner) {
spinner.text = `Clearing require cache, removing ${Object.keys(require.cache).length} items`;
Object.keys(require.cache).forEach((key) => {
delete require.cache[key];
});
}
module.exports = {
randomDirName,
getRandomArbitrary,
clearRequireCache,
};