updateGlobalConfig.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = updateGlobalConfig;
  6. function _jestRegexUtil() {
  7. const data = require('jest-regex-util');
  8. _jestRegexUtil = function () {
  9. return data;
  10. };
  11. return data;
  12. }
  13. /**
  14. * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  15. *
  16. * This source code is licensed under the MIT license found in the
  17. * LICENSE file in the root directory of this source tree.
  18. */
  19. function updateGlobalConfig(globalConfig, options = {}) {
  20. const newConfig = {...globalConfig};
  21. if (options.mode === 'watch') {
  22. newConfig.watch = true;
  23. newConfig.watchAll = false;
  24. } else if (options.mode === 'watchAll') {
  25. newConfig.watch = false;
  26. newConfig.watchAll = true;
  27. }
  28. if (options.testNamePattern !== undefined) {
  29. newConfig.testNamePattern = options.testNamePattern || '';
  30. }
  31. if (options.testPathPattern !== undefined) {
  32. newConfig.testPathPattern =
  33. (0, _jestRegexUtil().replacePathSepForRegex)(options.testPathPattern) ||
  34. '';
  35. }
  36. newConfig.onlyChanged =
  37. !newConfig.watchAll &&
  38. !newConfig.testNamePattern &&
  39. !newConfig.testPathPattern;
  40. if (typeof options.bail === 'boolean') {
  41. newConfig.bail = options.bail ? 1 : 0;
  42. } else if (options.bail !== undefined) {
  43. newConfig.bail = options.bail;
  44. }
  45. if (options.changedSince !== undefined) {
  46. newConfig.changedSince = options.changedSince;
  47. }
  48. if (options.collectCoverage !== undefined) {
  49. newConfig.collectCoverage = options.collectCoverage || false;
  50. }
  51. if (options.collectCoverageFrom !== undefined) {
  52. newConfig.collectCoverageFrom = options.collectCoverageFrom;
  53. }
  54. if (options.collectCoverageOnlyFrom !== undefined) {
  55. newConfig.collectCoverageOnlyFrom = options.collectCoverageOnlyFrom;
  56. }
  57. if (options.coverageDirectory !== undefined) {
  58. newConfig.coverageDirectory = options.coverageDirectory;
  59. }
  60. if (options.coverageReporters !== undefined) {
  61. newConfig.coverageReporters = options.coverageReporters;
  62. }
  63. if (options.findRelatedTests !== undefined) {
  64. newConfig.findRelatedTests = options.findRelatedTests;
  65. }
  66. if (options.nonFlagArgs !== undefined) {
  67. newConfig.nonFlagArgs = options.nonFlagArgs;
  68. }
  69. if (options.noSCM) {
  70. newConfig.noSCM = true;
  71. }
  72. if (options.notify !== undefined) {
  73. newConfig.notify = options.notify || false;
  74. }
  75. if (options.notifyMode !== undefined) {
  76. newConfig.notifyMode = options.notifyMode;
  77. }
  78. if (options.onlyFailures !== undefined) {
  79. newConfig.onlyFailures = options.onlyFailures || false;
  80. }
  81. if (options.passWithNoTests !== undefined) {
  82. newConfig.passWithNoTests = true;
  83. }
  84. if (options.reporters !== undefined) {
  85. newConfig.reporters = options.reporters;
  86. }
  87. if (options.updateSnapshot !== undefined) {
  88. newConfig.updateSnapshot = options.updateSnapshot;
  89. }
  90. if (options.verbose !== undefined) {
  91. newConfig.verbose = options.verbose || false;
  92. }
  93. return Object.freeze(newConfig);
  94. }