Created
February 3, 2019 22:48
-
-
Save NickCis/ecc2a2adcf44d6dbeeb440349ad9a852 to your computer and use it in GitHub Desktop.
This file contains 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
'use strict'; | |
const config = { | |
custom: 'command', | |
flag: false, | |
}; | |
const argv = process.argv.slice(0, 2); | |
// Naive argv parsing | |
process.argv | |
.reduce((cmd, arg) => { | |
if (cmd) { | |
config[cmd] = arg; | |
return; | |
} | |
if (arg.startsWith('--')) { | |
const sub = arg.substring('--'.length); | |
if (Object.keys(config).includes(sub)) { | |
if (typeof config[sub] === 'boolean') { | |
config[cmd] = true; | |
return; | |
} | |
return sub; | |
} | |
} | |
argv.push(arg) | |
}); | |
// Store configuration on env | |
process.env.__CONFIGURATION = JSON.stringify(config); | |
// Setting real ARGV | |
process.argv = argv; | |
// Calling jest runner | |
require('jest-cli/bin/jest'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment