Last active
July 9, 2018 23:21
-
-
Save Nxt3/03750b968dd9cfa363ced708265718dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const glob = require('glob'); | |
const argv = require('yargs').argv; | |
const projectArg: string = argv.project; | |
const spawn = require('child_process').spawn; | |
// Prints out a message in bold, cyan letters | |
function printInfoMessage(message: string): void { | |
console.info(message); | |
} | |
function getArgs(): string { | |
let args = ''; | |
process.argv.forEach(arg => { | |
if (arg.startsWith('--') && !arg.startsWith('--project')) { | |
args += `${arg} `; | |
} | |
}); | |
return args; | |
} | |
function createCommand(files?: any[]): string { | |
return `jest ${files || ''} --config=jest.config.js ${getArgs()}`; | |
} | |
// Handles running the passing in command | |
function runTestCommand(command: string): void { | |
spawn(command, { | |
shell: true, | |
stdio: 'inherit' | |
}); | |
} | |
function runTestGlob(project: string): void { | |
glob(`*/${project}/**/*.spec.ts`, function(err, files) { | |
if (files.length > 0) { | |
try { | |
// we do files.join because jest needs a list of files separated by spaces | |
runTestCommand(createCommand(project, files.join(' '))); | |
} catch (error) { | |
console.error(error); | |
} | |
} | |
}); | |
} | |
if (projectArg) { | |
printInfoMessage(`--project=${projectArg}`); | |
runTestGlob(projectArg); | |
} else { | |
printInfoMessage('*** Running tests for all projects ***'); | |
runTestCommand(createCommand()); // run jest on everything | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment