Skip to content

Instantly share code, notes, and snippets.

@NickCis
Created February 3, 2019 22:48
Show Gist options
  • Save NickCis/ecc2a2adcf44d6dbeeb440349ad9a852 to your computer and use it in GitHub Desktop.
Save NickCis/ecc2a2adcf44d6dbeeb440349ad9a852 to your computer and use it in GitHub Desktop.
'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