setFromArgv.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 'moduleNameMapper':
  37. case 'transform':
  38. case 'haste':
  39. const str = argv[key];
  40. if ((0, _utils.isJSONString)(str)) {
  41. options[key] = JSON.parse(str);
  42. }
  43. break;
  44. default:
  45. options[key] = argv[key];
  46. }
  47. return options;
  48. }, {});
  49. return {
  50. ...options,
  51. ...((0, _utils.isJSONString)(argv.config) ? JSON.parse(argv.config) : null),
  52. ...argvToOptions
  53. };
  54. }