UNPKG

1.97 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', {
4 value: true
5});
6exports.default = void 0;
7
8function _jestConfig() {
9 const data = require('jest-config');
10
11 _jestConfig = function () {
12 return data;
13 };
14
15 return data;
16}
17
18/**
19 * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
20 *
21 * This source code is licensed under the MIT license found in the
22 * LICENSE file in the root directory of this source tree.
23 */
24const stringifyOption = (option, map, linePrefix = '') => {
25 const optionDescription = ` // ${_jestConfig().descriptions[option]}`;
26 const stringifiedObject = `${option}: ${JSON.stringify(
27 map[option],
28 null,
29 2
30 )}`;
31 return (
32 optionDescription +
33 '\n' +
34 stringifiedObject
35 .split('\n')
36 .map(line => ' ' + linePrefix + line)
37 .join('\n') +
38 ',\n'
39 );
40};
41
42const generateConfigFile = (results, generateEsm = false) => {
43 const {coverage, clearMocks, environment} = results;
44 const overrides = {};
45
46 if (coverage) {
47 Object.assign(overrides, {
48 coverageDirectory: 'coverage'
49 });
50 }
51
52 if (environment === 'node') {
53 Object.assign(overrides, {
54 testEnvironment: 'node'
55 });
56 }
57
58 if (clearMocks) {
59 Object.assign(overrides, {
60 clearMocks: true
61 });
62 }
63
64 const overrideKeys = Object.keys(overrides);
65 const properties = [];
66
67 for (const option in _jestConfig().descriptions) {
68 const opt = option;
69
70 if (overrideKeys.includes(opt)) {
71 properties.push(stringifyOption(opt, overrides));
72 } else {
73 properties.push(stringifyOption(opt, _jestConfig().defaults, '// '));
74 }
75 }
76
77 return (
78 '// For a detailed explanation regarding each configuration property, visit:\n' +
79 '// https://jestjs.io/docs/en/configuration.html\n\n' +
80 (generateEsm ? 'export default {\n' : 'module.exports = {\n') +
81 properties.join('\n') +
82 '};\n'
83 );
84};
85
86var _default = generateConfigFile;
87exports.default = _default;