Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | 23x 23x 26x 26x 26x 23x 23x 26x 26x 23x 26x 23x 23x 113x 553x 553x 553x 113x 23x 13x 13x 13x 13x 23x 67x 67x 67x 67x 67x 67x 235x 235x 23x 33x 33x 23x 23x | import crypto from 'crypto';
import {tmpdir} from 'os';
import {join} from 'path';
import {existsSync, mkdirp, readFileSync} from 'fs-extra';
import rimraf from 'rimraf';
import dirTree from 'directory-tree';
import {omit} from 'ramda';
import Queue from 'p-queue';
import delay from 'delay';
import {format, maybeApply, populateQueue} from '../src/api';
// eslint-disable-next-line no-magic-numbers
export const testAsyncFunction = () => async ({skipInstall}) => await delay(skipInstall ? 0 : 1000 * Math.random());
const createTemporaryDirectory = async () => {
const tempDir = join(tmpdir(), `tomo-test-${crypto.randomBytes(20).toString('hex')}`);// eslint-disable-line no-magic-numbers
await mkdirp(tempDir);
return tempDir;
};
export const useTemporaryDirectory = () => {
let tempDir;
const setTempDirectory = async () => {
tempDir = await createTemporaryDirectory();
return tempDir;
};
const cleanupTempDirectory = async () => {
await new Promise(resolve => rimraf(tempDir, resolve));
};
return [setTempDirectory, cleanupTempDirectory];
};
export const removeAttributes = (obj, ...attrs) => {
const result = Object.entries(obj).reduce((acc, arr) => {
const [key, val] = arr;
const remove = val => removeAttributes(val, ...attrs);
return (key === 'children') ? {...acc, children: val.map(remove)} : {...acc, ...omit(attrs, {[key]: val})};
}, {});
return result;
};
export const getDirectoryTree = (directory, options = {omit: ['extension', 'path']}) => {
const {omit} = options;
const tree = dirTree(directory);
const result = Object.assign(tree, {name: tree.name.substring(0, 'tomo-test'.length)});
return format(removeAttributes(result, 'size', ...omit));
};
export const run = (tasks, options) => {
const {assign} = Object;
const queue = new Queue({concurrency: tasks.length});
const dispatch = () => {};
const defaults = {
assetsDirectory: './assets',
sourceDirectory: './source',
outputDirectory: './output',
port: 4669
};
const _options = assign({}, options, defaults);
return populateQueue({
queue,
dispatch,
tasks: tasks
.flatMap(val => maybeApply(val, _options))
.flatMap(val => maybeApply(val, _options)),
options: _options
});
};
export const fileContents = path => {
const fullpath = join(process.cwd(), path);
return existsSync(fullpath) ? readFileSync(fullpath, 'utf8') : `No file found at ${fullpath}`;
};
export const readMakefile = makefile => {
const [, ...rest] = makefile
.read()
.replace(/bin := .*\/__tests__/, 'bin := home/user/project/__tests__')
.split('\n');
return ['# Makefile created with tomo', ...rest].join('\n');
};
export const readMakefileContent = () => {
const regex = /^# Built from .*\n/;
return fileContents('./Makefile').replace(regex, '# Makefile built from /path/to/package.json');
}; |