setFromArgv.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = setFromArgv;
  6. var _utils = require('./utils');
  7. /**
  8. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  9. *
  10. * This source code is licensed under the MIT license found in the
  11. * LICENSE file in the root directory of this source tree.
  12. */
  13. const specialArgs = ['_', '$0', 'h', 'help', 'config'];
  14. function setFromArgv(options, argv) {
  15. const argvToOptions = Object.keys(argv)
  16. .filter(key => argv[key] !== undefined && specialArgs.indexOf(key) === -1)
  17. .reduce((options, key) => {
  18. switch (key) {
  19. case 'coverage':
  20. options.collectCoverage = argv[key];
  21. break;
  22. case 'json':
  23. options.useStderr = argv[key];
  24. break;
  25. case 'watchAll':
  26. options.watch = false;
  27. options.watchAll = argv[key];
  28. break;
  29. case 'env':
  30. options.testEnvironment = argv[key];
  31. break;
  32. case 'config':
  33. break;
  34. case 'coverageThreshold':
  35. case 'globals':
  36. case 'haste':
  37. case 'moduleNameMapper':
  38. case 'testEnvironmentOptions':
  39. case 'transform':
  40. const str = argv[key];
  41. if ((0, _utils.isJSONString)(str)) {
  42. options[key] = JSON.parse(str);
  43. }
  44. break;
  45. default:
  46. options[key] = argv[key];
  47. }
  48. return options;
  49. }, {});
  50. return {
  51. ...options,
  52. ...((0, _utils.isJSONString)(argv.config) ? JSON.parse(argv.config) : null),
  53. ...argvToOptions
  54. };
  55. }