process-args.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /* global describe, it */
  2. require('chai').should()
  3. const processArgs = require('../lib/process-args')
  4. describe('process-args', function () {
  5. describe('hideInstrumenterArgs', function () {
  6. it('removes dashed options that proceed bin', function () {
  7. process.argv = ['/Users/benjamincoe/bin/iojs',
  8. '/Users/benjamincoe/bin/nyc.js',
  9. '--reporter',
  10. 'lcov',
  11. 'node',
  12. 'test/nyc-tap.js'
  13. ]
  14. var yargv = require('yargs/yargs')(process.argv.slice(2)).argv
  15. var munged = processArgs.hideInstrumenterArgs(yargv)
  16. munged.should.eql(['node', 'test/nyc-tap.js'])
  17. })
  18. it('parses extra args directly after -- as Node execArgv', function () {
  19. process.argv = ['/Users/benjamincoe/bin/iojs',
  20. '/Users/benjamincoe/bin/nyc.js',
  21. '--',
  22. '--expose-gc',
  23. 'index.js'
  24. ]
  25. var yargv = require('yargs/yargs')(process.argv.slice(2)).argv
  26. var munged = processArgs.hideInstrumenterArgs(yargv)
  27. munged.should.eql([process.execPath, '--expose-gc', 'index.js'])
  28. })
  29. })
  30. describe('hideInstrumenteeArgs', function () {
  31. it('ignores arguments after the instrumented bin', function () {
  32. process.argv = ['/Users/benjamincoe/bin/iojs',
  33. '/Users/benjamincoe/bin/nyc.js',
  34. '--reporter',
  35. 'lcov',
  36. 'node',
  37. 'test/nyc-tap.js',
  38. '--arg',
  39. '--'
  40. ]
  41. var munged = processArgs.hideInstrumenteeArgs()
  42. munged.should.eql(['--reporter', 'lcov', 'node'])
  43. })
  44. it('does not ignore arguments if command is recognized', function () {
  45. process.argv = ['/Users/benjamincoe/bin/iojs',
  46. '/Users/benjamincoe/bin/nyc.js',
  47. 'report',
  48. '--reporter',
  49. 'lcov'
  50. ]
  51. var munged = processArgs.hideInstrumenteeArgs()
  52. munged.should.eql(['report', '--reporter', 'lcov'])
  53. })
  54. it('does not ignore arguments if no command is provided', function () {
  55. process.argv = ['/Users/benjamincoe/bin/iojs',
  56. '/Users/benjamincoe/bin/nyc.js',
  57. '--version'
  58. ]
  59. var munged = processArgs.hideInstrumenteeArgs()
  60. munged.should.eql(['--version'])
  61. })
  62. })
  63. })