Class: RunTest::OptParse
- Inherits:
-
Object
- Object
- RunTest::OptParse
- Defined in:
- lib/runtest/options.rb
Class Method Summary collapse
- .default_options ⇒ Object
-
.parse(args, unit_testing = false) ⇒ Object
Return a structure describing the Options.
Class Method Details
.default_options ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/runtest/options.rb', line 3 def self. { basedir: "src/js", changed: false, commands: Config::Options.new, jest: true, mocha: true, verbose: 0 } end |
.parse(args, unit_testing = false) ⇒ Object
Return a structure describing the Options.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/runtest/options.rb', line 17 def self.parse(args, unit_testing=false) # The Options specified on the command line will be collected in *Options*. # We set default values here. opt_parse = DevTools::OptParse.new({ name: PROGRAM_NAME, version: VERSION, defaults: , testing: unit_testing }) opt_parse.(Options.commands, { diff: "git diff --name-only develop src/js | egrep \".js$\"", jest: "$(npm bin)/jest", jest_full: "npm run test:jest", mocha: "$(npm bin)/mocha --require src/js/util/test-dom.js --compilers js:babel-core/register", mocha_full: "npm run test:mocha" }) parser = opt_parse.parser parser. = "Usage: #{DevTools::PROGRAM} [OPTIONS] [PATTERN]" parser. += "\n\nWhere [PATTERN] is any full or partial filename." parser. += " All tests matching this filename pattern will be run." parser.separator "" parser.separator "[OPTIONS]" parser.separator "" parser.separator "Specific Options:" # Base directory parser.on("-b", "--basedir DIR", "Specify the base directory to search for tests (DEFAULT: '#{Options.basedir}')") do |dir| Options.basedir = dir end # Changed switch parser.on("-c", "--changed", "Run specs for any files that have recently been modified") do Options.changed = true end parser.separator "" parser.separator "Test Runners:" parser.on("-j", "--[no-]jest", "Only/Don't run Jest tests") do |jest| Options.jest = true; Options.mocha = false (Options.jest = false; Options.mocha = true) unless jest end parser.on("-m", "--[no-]mocha", "Only/Don't run Mocha tests") do |mocha| Options.jest = false; Options.mocha = true (Options.jest = true; Options.mocha = false) unless mocha end parser.separator "" parser.separator "Test Commands:" parser.on("--diff-cmd CMD", "Overwrite git diff command: '#{Options.commands.diff}'") do |cmd| Options.commands.diff = cmd end parser.on("--jest-cmd CMD", "Overwrite Jest command: '#{Options.commands.jest}'") do |cmd| Options.commands.jest = cmd end parser.on("--jest-full-cmd CMD", "Overwrite Jest full-suite command: '#{Options.commands.jest_full}'") do |cmd| Options.commands.jest_full = cmd end parser.on("--mocha-cmd CMD", "Overwrite Mocha command: '#{Options.commands.mocha}'") do |cmd| Options.commands.mocha = cmd end parser.on("--mocha-full-cmd CMD", "Overwrite Mocha command: '#{Options.commands.mocha_full}'") do |cmd| Options.commands.mocha_full = cmd end parser.separator "" parser.separator "Common Options:" parser.parse!(args) return Options end |