Created
February 3, 2019 20:51
-
-
Save NickCis/453532071e52714d19a1acb3d7ca6cc2 to your computer and use it in GitHub Desktop.
Jest custom command line arguments
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) | |
}); | |
// 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