Nate Fischer 81e2803c45 test: set up ava and move cd.js (#561)
* test: set up ava and move cd.js

Set up ava as the new test framework. Migrate the tests for the cd command to
use the ava framework.

* refactor: reorder imports, remove useless dep
2016-11-18 19:50:36 -08:00

37 lines
1.1 KiB
JavaScript

const child = require('child_process');
function numLines(str) {
return typeof str === 'string' ? (str.match(/\n/g) || []).length + 1 : 0;
}
exports.numLines = numLines;
function getTempDir() {
// a very random directory
return ('tmp' + Math.random() + Math.random()).replace(/\./g, '');
}
exports.getTempDir = getTempDir;
// On Windows, symlinks for files need admin permissions. This helper
// skips certain tests if we are on Windows and got an EPERM error
function skipOnWinForEPERM(action, testCase) {
const ret = action();
const error = ret.code;
const isWindows = process.platform === 'win32';
if (isWindows && error && /EPERM:/.test(error)) {
console.warn('Got EPERM when testing symlinks on Windows. Assuming non-admin environment and skipping test.');
} else {
testCase();
}
}
exports.skipOnWinForEPERM = skipOnWinForEPERM;
function runScript(script, cb) {
child.execFile(process.execPath, ['-e', script], cb);
}
exports.runScript = runScript;
function sleep(time) {
child.execFileSync(process.execPath, ['resources/exec/slow.js', time.toString()]);
}
exports.sleep = sleep;