shelljs/test/utils/utils.js
Brandon Freitag 7fa4b995bf Finalize moving to ava (#630)
* Move ava-test/ directory to test/

* Remove unnecessary run-tests.js script

* Run only ava during npm test script
2016-12-20 11:27:02 -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;