setFromArgv.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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) Meta Platforms, Inc. and affiliates.
  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).reduce((options, key) => {
  16. if (argv[key] === undefined || specialArgs.includes(key)) {
  17. return options;
  18. }
  19. switch (key) {
  20. case 'coverage':
  21. options.collectCoverage = argv[key];
  22. break;
  23. case 'json':
  24. options.useStderr = argv[key];
  25. break;
  26. case 'watchAll':
  27. options.watch = false;
  28. options.watchAll = argv[key];
  29. break;
  30. case 'env':
  31. options.testEnvironment = argv[key];
  32. break;
  33. case 'config':
  34. break;
  35. case 'coverageThreshold':
  36. case 'globals':
  37. case 'haste':
  38. case 'moduleNameMapper':
  39. case 'testEnvironmentOptions':
  40. case 'transform':
  41. const str = argv[key];
  42. if ((0, _utils.isJSONString)(str)) {
  43. options[key] = JSON.parse(str);
  44. }
  45. break;
  46. default:
  47. options[key] = argv[key];
  48. }
  49. return options;
  50. }, {});
  51. return {
  52. ...options,
  53. ...((0, _utils.isJSONString)(argv.config) ? JSON.parse(argv.config) : null),
  54. ...argvToOptions
  55. };
  56. }