ts-jest 23.10.1 → 23.10.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/.gitattributes +2 -0
  2. package/.ts-jest-digest +1 -0
  3. package/CHANGELOG.md +56 -0
  4. package/README.md +2 -2
  5. package/dist/cli/config/init.d.ts +1 -0
  6. package/dist/cli/config/init.js +31 -16
  7. package/dist/cli/config/migrate.d.ts +1 -0
  8. package/dist/cli/config/migrate.js +78 -18
  9. package/dist/cli/help.d.ts +1 -0
  10. package/dist/cli/helpers/presets.d.ts +1 -0
  11. package/dist/cli/helpers/presets.js +39 -0
  12. package/dist/cli/index.d.ts +1 -0
  13. package/dist/cli/index.js +14 -1
  14. package/dist/compiler.d.ts +1 -0
  15. package/dist/config/config-set.d.ts +35 -0
  16. package/dist/config/config-set.js +103 -39
  17. package/dist/config/create-jest-preset.d.ts +10 -0
  18. package/dist/config/create-jest-preset.js +6 -12
  19. package/dist/config/jest-config-resolver.d.ts +2 -0
  20. package/dist/config/jest-config-resolver.js +43 -0
  21. package/dist/config/paths-to-module-name-mapper.d.ts +5 -0
  22. package/dist/index.d.ts +16 -0
  23. package/dist/index.js +21 -12
  24. package/dist/transformers/hoist-jest.d.ts +1 -0
  25. package/dist/transformers/index.d.ts +1 -0
  26. package/dist/ts-jest-transformer.d.ts +17 -0
  27. package/dist/types.d.ts +101 -0
  28. package/dist/util/backports.d.ts +1 -0
  29. package/dist/util/exported.d.ts +3 -0
  30. package/dist/util/exported.js +8 -0
  31. package/dist/util/get-package-version.d.ts +1 -0
  32. package/dist/util/hacks.d.ts +1 -0
  33. package/dist/util/importer.d.ts +1 -0
  34. package/dist/util/importer.js +65 -9
  35. package/dist/util/json.d.ts +1 -0
  36. package/dist/util/jsonable-value.d.ts +1 -0
  37. package/dist/util/logger.d.ts +1 -0
  38. package/dist/util/logger.js +3 -4
  39. package/dist/util/memoize.d.ts +1 -0
  40. package/dist/util/messages.d.ts +1 -0
  41. package/dist/util/messages.js +4 -0
  42. package/dist/util/normalize-slashes.d.ts +1 -0
  43. package/dist/util/sha1.d.ts +1 -0
  44. package/dist/util/testing.d.ts +35 -0
  45. package/dist/util/testing.js +7 -0
  46. package/dist/util/ts-error.d.ts +1 -0
  47. package/dist/util/version-checkers.d.ts +1 -0
  48. package/jest-preset.js +1 -4
  49. package/package.json +37 -34
  50. package/presets/create.js +1 -0
  51. package/presets/default/jest-preset.js +1 -0
  52. package/presets/index.d.ts +5 -0
  53. package/presets/index.js +13 -0
  54. package/presets/js-with-babel/jest-preset.js +1 -0
  55. package/presets/js-with-ts/jest-preset.js +1 -0
  56. package/utils/index.d.ts +1 -0
  57. package/utils/index.js +1 -0
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ package-lock.json -diff -merge
2
+ package-lock.json linguist-generated=true
@@ -0,0 +1 @@
1
+ 3fe12324700b93d3377a5957ccfc2f339524ce17
package/CHANGELOG.md CHANGED
@@ -1,3 +1,59 @@
1
+ <a name="23.10.5"></a>
2
+ ## [23.10.5](https://github.com/kulshekhar/ts-jest/compare/v23.10.4...v23.10.5) (2018-11-22)
3
+
4
+
5
+
6
+ <a name="23.10.4"></a>
7
+ ## [23.10.4](https://github.com/kulshekhar/ts-jest/compare/v23.10.3...v23.10.4) (2018-10-06)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * **cache:** adds project's dep versions to cache key ([6cacbea](https://github.com/kulshekhar/ts-jest/commit/6cacbea)), closes [#785](https://github.com/kulshekhar/ts-jest/issues/785)
13
+ * **cli:** change options to better reflect the new presets ([68abcfb](https://github.com/kulshekhar/ts-jest/commit/68abcfb))
14
+ * **helpers:** deprecate import from ts-jest, now ts-jest/utils ([33ff29f](https://github.com/kulshekhar/ts-jest/commit/33ff29f)), closes [#782](https://github.com/kulshekhar/ts-jest/issues/782)
15
+ * **typings:** typo in presets definition file ([53767ab](https://github.com/kulshekhar/ts-jest/commit/53767ab))
16
+ * **typings:** wrong import in preset typings + test ([94dc4e7](https://github.com/kulshekhar/ts-jest/commit/94dc4e7))
17
+
18
+
19
+
20
+ <a name="23.10.3"></a>
21
+ ## [23.10.3](https://github.com/kulshekhar/ts-jest/compare/v23.10.2...v23.10.3) (2018-09-30)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * **compiler:** do not force module kind if piping babel ([acebc8c](https://github.com/kulshekhar/ts-jest/commit/acebc8c)), closes [#767](https://github.com/kulshekhar/ts-jest/issues/767)
27
+
28
+
29
+ ### Features
30
+
31
+ * **helpers:** adds a mocked test helper for mock typings ([f976135](https://github.com/kulshekhar/ts-jest/commit/f976135)), closes [#576](https://github.com/kulshekhar/ts-jest/issues/576)
32
+
33
+
34
+
35
+ <a name="23.10.2"></a>
36
+ ## [23.10.2](https://github.com/kulshekhar/ts-jest/compare/v23.10.1...v23.10.2) (2018-09-26)
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * **cache:** resolved tsconfig in cache key + pkg digest ([e891608](https://github.com/kulshekhar/ts-jest/commit/e891608)), closes [#749](https://github.com/kulshekhar/ts-jest/issues/749)
42
+ * **cli:** resets testMatch if using testRegex option ([31ad0aa](https://github.com/kulshekhar/ts-jest/commit/31ad0aa)), closes [#756](https://github.com/kulshekhar/ts-jest/issues/756)
43
+ * **diagnostics:** throws only for category warning and error ([bb28849](https://github.com/kulshekhar/ts-jest/commit/bb28849)), closes [#748](https://github.com/kulshekhar/ts-jest/issues/748)
44
+ * **import:** wrong error message when a module exists but fails ([e0d6c57](https://github.com/kulshekhar/ts-jest/commit/e0d6c57))
45
+ * **preset:** createJestPreset fails with base and no array ([3c325e8](https://github.com/kulshekhar/ts-jest/commit/3c325e8))
46
+
47
+
48
+ ### Features
49
+
50
+ * **cli:** CLI 'config:migrate' now detects best preset ([febd8d3](https://github.com/kulshekhar/ts-jest/commit/febd8d3))
51
+ * **preset:** adds 2 presets along the default one ([9f3d759](https://github.com/kulshekhar/ts-jest/commit/9f3d759))
52
+ * **preset:** adds presets typings and export all presets ([f55d895](https://github.com/kulshekhar/ts-jest/commit/f55d895))
53
+ * **typings:** emit declaration files, filtering out internals ([4f10f7e](https://github.com/kulshekhar/ts-jest/commit/4f10f7e)), closes [#745](https://github.com/kulshekhar/ts-jest/issues/745)
54
+
55
+
56
+
1
57
  <a name="23.10.1"></a>
2
58
  ## [23.10.1](https://github.com/kulshekhar/ts-jest/compare/v23.10.0...v23.10.1) (2018-09-20)
3
59
 
package/README.md CHANGED
@@ -30,7 +30,7 @@ These instructions will get you setup to use `ts-jest` in your project. For more
30
30
  | | using npm | using yarn |
31
31
  |---:|---|---|
32
32
  | **Prerequisites** | `npm i -D jest typescript` | `yarn add --dev jest typescript` |
33
- | **Installing** | `npm i -D ts-jest` | `yarn add --dev ts-jest` |
33
+ | **Installing** | `npm i -D ts-jest @types/jest` | `yarn add --dev ts-jest @types/jest` |
34
34
  | **Creating config** | `node_modules/.bin/ts-jest config:init` | `yarn ts-jest config:init` |
35
35
  | **Running tests** | `npm t` or `node_modules/.bin/jest` | `yarn test` or `yarn jest` |
36
36
 
@@ -46,7 +46,7 @@ Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduc
46
46
 
47
47
  ## Versioning
48
48
 
49
- We **DOT NOT** use [SemVer](http://semver.org/) for versioning. Tho you can think about SemVer when reading our version, except our major number follow the one of Jest. For the versions available, see the [tags on this repository](https://github.com/kulshekhar/ts-jest/tags).
49
+ We **DO NOT** use [SemVer](http://semver.org/) for versioning. Tho you can think about SemVer when reading our version, except our major number follow the one of Jest. For the versions available, see the [tags on this repository](https://github.com/kulshekhar/ts-jest/tags).
50
50
 
51
51
  ## Authors/maintainers
52
52
 
@@ -0,0 +1 @@
1
+ export {};
@@ -50,10 +50,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
50
50
  var fs_1 = require("fs");
51
51
  var json5_1 = require("json5");
52
52
  var path_1 = require("path");
53
- var create_jest_preset_1 = require("../../config/create-jest-preset");
53
+ var presets_1 = require("../helpers/presets");
54
54
  exports.run = function (args) { return __awaiter(_this, void 0, void 0, function () {
55
- var file, filePath, name, isPackage, exists, pkgFile, hasPackage, _a, allowJs, _b, jestPreset, askedTsconfig, _c, babel, force, jsdom, tsconfig, hasPresetVar, pkgJson, body, base, tsJestConf, content;
56
- return __generator(this, function (_d) {
55
+ var file, filePath, name, isPackage, exists, pkgFile, hasPackage, _a, jestPreset, askedTsconfig, force, jsdom, tsconfig, pkgJson, jsFilesProcessor, shouldPostProcessWithBabel, preset, body, base, tsJestConf, content;
56
+ return __generator(this, function (_b) {
57
57
  file = args._[0] || 'jest.config.js';
58
58
  filePath = path_1.join(process.cwd(), file);
59
59
  name = path_1.basename(file);
@@ -61,10 +61,25 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
61
61
  exists = fs_1.existsSync(filePath);
62
62
  pkgFile = isPackage ? filePath : path_1.join(process.cwd(), 'package.json');
63
63
  hasPackage = isPackage || fs_1.existsSync(pkgFile);
64
- _a = args.allowJs, allowJs = _a === void 0 ? false : _a, _b = args.jestPreset, jestPreset = _b === void 0 ? true : _b, askedTsconfig = args.tsconfig, _c = args.babel, babel = _c === void 0 ? false : _c, force = args.force, jsdom = args.jsdom;
64
+ _a = args.jestPreset, jestPreset = _a === void 0 ? true : _a, askedTsconfig = args.tsconfig, force = args.force, jsdom = args.jsdom;
65
65
  tsconfig = askedTsconfig === 'tsconfig.json' ? undefined : askedTsconfig;
66
- hasPresetVar = allowJs || !jestPreset;
67
66
  pkgJson = hasPackage ? JSON.parse(fs_1.readFileSync(pkgFile, 'utf8')) : {};
67
+ jsFilesProcessor = args.js, shouldPostProcessWithBabel = args.babel;
68
+ if (jsFilesProcessor == null) {
69
+ jsFilesProcessor = shouldPostProcessWithBabel ? 'babel' : undefined;
70
+ }
71
+ else if (shouldPostProcessWithBabel == null) {
72
+ shouldPostProcessWithBabel = jsFilesProcessor === 'babel';
73
+ }
74
+ if (jsFilesProcessor === 'babel') {
75
+ preset = presets_1.jsWIthBabel;
76
+ }
77
+ else if (jsFilesProcessor === 'ts') {
78
+ preset = presets_1.jsWithTs;
79
+ }
80
+ else {
81
+ preset = presets_1.defaults;
82
+ }
68
83
  if (isPackage && !exists) {
69
84
  throw new Error("File " + file + " does not exists.");
70
85
  }
@@ -84,39 +99,39 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
84
99
  }
85
100
  }
86
101
  if (isPackage) {
87
- base = hasPresetVar ? create_jest_preset_1.createJestPreset({ allowJs: allowJs }) : { preset: 'ts-jest' };
102
+ base = jestPreset ? { preset: preset.name } : __assign({}, preset.value);
88
103
  if (!jsdom)
89
104
  base.testEnvironment = 'node';
90
- if (tsconfig || babel) {
105
+ if (tsconfig || shouldPostProcessWithBabel) {
91
106
  tsJestConf = {};
92
107
  base.globals = { 'ts-jest': tsJestConf };
93
108
  if (tsconfig)
94
109
  tsJestConf.tsconfig = tsconfig;
95
- if (babel)
110
+ if (shouldPostProcessWithBabel)
96
111
  tsJestConf.babelConfig = true;
97
112
  }
98
113
  body = JSON.stringify(__assign({}, pkgJson, { jest: base }), undefined, ' ');
99
114
  }
100
115
  else {
101
116
  content = [];
102
- if (hasPresetVar) {
103
- content.push("const tsJest = require('ts-jest').createJestPreset({ allowJs: " + allowJs + " });", '');
117
+ if (!jestPreset) {
118
+ content.push(preset.jsImport('tsjPreset') + ";", '');
104
119
  }
105
120
  content.push('module.exports = {');
106
- if (hasPresetVar) {
107
- content.push(" ...tsJest,");
121
+ if (jestPreset) {
122
+ content.push(" preset: '" + preset.name + "',");
108
123
  }
109
124
  else {
110
- content.push(" preset: 'ts-jest',");
125
+ content.push(" ...tsjPreset,");
111
126
  }
112
127
  if (!jsdom)
113
128
  content.push(" testEnvironment: 'node',");
114
- if (tsconfig || babel) {
129
+ if (tsconfig || shouldPostProcessWithBabel) {
115
130
  content.push(" globals: {");
116
131
  content.push(" 'ts-jest': {");
117
132
  if (tsconfig)
118
133
  content.push(" tsconfig: " + json5_1.stringify(tsconfig) + ",");
119
- if (babel)
134
+ if (shouldPostProcessWithBabel)
120
135
  content.push(" babelConfig: true,");
121
136
  content.push(" },");
122
137
  content.push(" },");
@@ -131,7 +146,7 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
131
146
  }); };
132
147
  exports.help = function () { return __awaiter(_this, void 0, void 0, function () {
133
148
  return __generator(this, function (_a) {
134
- process.stdout.write("\nUsage:\n ts-jest config:init [options] [<config-file>]\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n Default: jest.config.js\n\nOptions:\n --force Discard any existing Jest config\n --allow-js ts-jest will be used to process JS files as well\n --no-jest-preset Disable the use of Jest presets\n --tsconfig <file> Path to the tsconfig.json file\n --babel Call BabelJest after ts-jest\n --jsdom Use jsdom as test environment instead of node\n");
149
+ process.stdout.write("\nUsage:\n ts-jest config:init [options] [<config-file>]\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n Default: jest.config.js\n\nOptions:\n --force Discard any existing Jest config\n --js ts|babel Process .js files with ts-jest if 'ts' or with\n babel-jest if 'babel'\n --no-jest-preset Disable the use of Jest presets\n --tsconfig <file> Path to the tsconfig.json file\n --babel Pipe babel-jest after ts-jest\n --jsdom Use jsdom as test environment instead of node\n");
135
150
  return [2];
136
151
  });
137
152
  }); };
@@ -0,0 +1 @@
1
+ export {};
@@ -34,6 +34,26 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
+ var __read = (this && this.__read) || function (o, n) {
38
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
39
+ if (!m) return o;
40
+ var i = m.call(o), r, ar = [], e;
41
+ try {
42
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
43
+ }
44
+ catch (error) { e = { error: error }; }
45
+ finally {
46
+ try {
47
+ if (r && !r.done && (m = i["return"])) m.call(i);
48
+ }
49
+ finally { if (e) throw e.error; }
50
+ }
51
+ return ar;
52
+ };
53
+ var __spread = (this && this.__spread) || function () {
54
+ for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
55
+ return ar;
56
+ };
37
57
  var __importDefault = (this && this.__importDefault) || function (mod) {
38
58
  return (mod && mod.__esModule) ? mod : { "default": mod };
39
59
  };
@@ -44,14 +64,15 @@ var fast_json_stable_stringify_1 = __importDefault(require("fast-json-stable-str
44
64
  var fs_1 = require("fs");
45
65
  var json5_1 = require("json5");
46
66
  var path_1 = require("path");
47
- var create_jest_preset_1 = require("../../config/create-jest-preset");
48
67
  var backports_1 = require("../../util/backports");
68
+ var presets_1 = require("../helpers/presets");
49
69
  exports.run = function (args) { return __awaiter(_this, void 0, void 0, function () {
50
- var nullLogger, file, filePath, name, isPackage, actualConfig, migratedConfig, usesPreset, presets, presetValue, migratedValue, presetValue, migratedValue, before, after, stringify, footNotes;
70
+ var nullLogger, file, filePath, footNotes, name, isPackage, actualConfig, migratedConfig, presetName, preset, jsTransformers, jsWithTs, jsWithBabel, presetValue, migratedValue, presetValue, migratedValue, before, after, stringify, prefix;
51
71
  return __generator(this, function (_a) {
52
72
  nullLogger = bs_logger_1.createLogger({ targets: [] });
53
73
  file = args._[0];
54
74
  filePath = path_1.resolve(process.cwd(), file);
75
+ footNotes = [];
55
76
  if (!fs_1.existsSync(filePath)) {
56
77
  throw new Error("Configuration file " + file + " does not exists.");
57
78
  }
@@ -68,22 +89,59 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
68
89
  actualConfig = {};
69
90
  migratedConfig = backports_1.backportJestConfig(nullLogger, actualConfig);
70
91
  if (!migratedConfig.preset && args.jestPreset) {
71
- migratedConfig.preset = 'ts-jest';
92
+ if (args.js) {
93
+ presetName = args.js === 'babel' ? presets_1.JestPresetNames.jsWIthBabel : presets_1.JestPresetNames.jsWithTs;
94
+ }
95
+ else {
96
+ jsTransformers = Object.keys(migratedConfig.transform || {}).reduce(function (list, pattern) {
97
+ if (RegExp(pattern.replace(/^<rootDir>\/?/, '/dummy-project/')).test('/dummy-project/src/foo.js')) {
98
+ var transformer = migratedConfig.transform[pattern];
99
+ if (/\bbabel-jest\b/.test(transformer))
100
+ transformer = 'babel-jest';
101
+ else if (/\ts-jest\b/.test(transformer))
102
+ transformer = 'ts-jest';
103
+ return __spread(list, [transformer]);
104
+ }
105
+ return list;
106
+ }, []);
107
+ jsWithTs = jsTransformers.includes('ts-jest');
108
+ jsWithBabel = jsTransformers.includes('babel-jest');
109
+ if (jsWithBabel && !jsWithTs) {
110
+ presetName = presets_1.JestPresetNames.jsWIthBabel;
111
+ }
112
+ else if (jsWithTs && !jsWithBabel) {
113
+ presetName = presets_1.JestPresetNames.jsWithTs;
114
+ }
115
+ else {
116
+ presetName = presets_1.JestPresetNames.default;
117
+ }
118
+ }
119
+ presetName = presetName || presets_1.JestPresetNames.default;
120
+ preset = presets_1.allPresets[presetName];
121
+ footNotes.push("Detected preset '" + preset.label + "' as the best matching preset for your configuration.\nVisit https://kulshekhar.github.io/ts-jest/user/config/#jest-preset for more information about presets.\n");
72
122
  }
73
- else if (!args.jestPreset && migratedConfig.preset === 'ts-jest') {
74
- delete migratedConfig.preset;
123
+ else if (migratedConfig.preset && migratedConfig.preset.startsWith('ts-jest')) {
124
+ if (args.jestPreset === false) {
125
+ delete migratedConfig.preset;
126
+ }
127
+ else {
128
+ preset = presets_1.allPresets[migratedConfig.preset] || presets_1.defaults;
129
+ }
75
130
  }
76
- usesPreset = migratedConfig.preset === 'ts-jest';
77
- presets = create_jest_preset_1.createJestPreset({ allowJs: args.allowJs });
78
- if (migratedConfig.moduleFileExtensions && migratedConfig.moduleFileExtensions.length && usesPreset) {
79
- presetValue = dedupSort(presets.moduleFileExtensions).join('::');
131
+ if (preset)
132
+ migratedConfig.preset = preset.name;
133
+ if (migratedConfig.moduleFileExtensions && migratedConfig.moduleFileExtensions.length && preset) {
134
+ presetValue = dedupSort(preset.value.moduleFileExtensions).join('::');
80
135
  migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::');
81
136
  if (presetValue === migratedValue) {
82
137
  delete migratedConfig.moduleFileExtensions;
83
138
  }
84
139
  }
85
- if (migratedConfig.testMatch && migratedConfig.testMatch.length && usesPreset) {
86
- presetValue = dedupSort(presets.testMatch).join('::');
140
+ if (migratedConfig.testRegex && preset) {
141
+ migratedConfig.testMatch = null;
142
+ }
143
+ else if (migratedConfig.testMatch && migratedConfig.testMatch.length && preset) {
144
+ presetValue = dedupSort(preset.value.testMatch).join('::');
87
145
  migratedValue = dedupSort(migratedConfig.testMatch).join('::');
88
146
  if (presetValue === migratedValue) {
89
147
  delete migratedConfig.testMatch;
@@ -98,9 +156,9 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
98
156
  }
99
157
  });
100
158
  }
101
- if (usesPreset &&
159
+ if (preset &&
102
160
  migratedConfig.transform &&
103
- fast_json_stable_stringify_1.default(migratedConfig.transform) === fast_json_stable_stringify_1.default(presets.transform)) {
161
+ fast_json_stable_stringify_1.default(migratedConfig.transform) === fast_json_stable_stringify_1.default(preset.value.transform)) {
104
162
  delete migratedConfig.transform;
105
163
  }
106
164
  cleanupConfig(actualConfig);
@@ -112,12 +170,12 @@ exports.run = function (args) { return __awaiter(_this, void 0, void 0, function
112
170
  return [2];
113
171
  }
114
172
  stringify = /\.json$/.test(file) ? JSON.stringify : json5_1.stringify;
115
- footNotes = [];
116
- if (usesPreset && migratedConfig.transform) {
117
- footNotes.push("\nI couldn't check if your \"transform\" value is the same as mine which is: " + stringify(presets.transform, undefined, ' ') + "\nIf it is the case, you can safely remove the \"transform\" from what I've migrated.\n");
173
+ prefix = /\.json$/.test(file) ? '"jest": ' : 'module.exports = ';
174
+ if (preset && migratedConfig.transform) {
175
+ footNotes.push("\nI couldn't check if your \"transform\" value is the same as mine which is: " + stringify(preset.value.transform, undefined, ' ') + "\nIf it is the case, you can safely remove the \"transform\" from what I've migrated.\n");
118
176
  }
119
177
  process.stderr.write("\nMigrated Jest configuration:\n");
120
- process.stdout.write(stringify(migratedConfig, undefined, ' ') + "\n");
178
+ process.stdout.write("" + prefix + stringify(migratedConfig, undefined, ' ') + "\n");
121
179
  if (footNotes.length) {
122
180
  process.stderr.write("\n" + footNotes.join('\n') + "\n");
123
181
  }
@@ -146,6 +204,8 @@ function cleanupConfig(config) {
146
204
  if (config.testMatch.length === 0)
147
205
  delete config.testMatch;
148
206
  }
207
+ if (config.preset === presets_1.JestPresetNames.default)
208
+ config.preset = presets_1.defaults.name;
149
209
  }
150
210
  function dedupSort(arr) {
151
211
  return arr
@@ -154,7 +214,7 @@ function dedupSort(arr) {
154
214
  }
155
215
  exports.help = function () { return __awaiter(_this, void 0, void 0, function () {
156
216
  return __generator(this, function (_a) {
157
- process.stdout.write("\nUsage:\n ts-jest config:migrate [options] <config-file>\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n\nOptions:\n --allow-js ts-jest will be used to process JS files as well\n --no-jest-preset Disable the use of Jest presets\n");
217
+ process.stdout.write("\nUsage:\n ts-jest config:migrate [options] <config-file>\n\nArguments:\n <config-file> Can be a js or json Jest config file. If it is a\n package.json file, the configuration will be read from\n the \"jest\" property.\n\nOptions:\n --js ts|babel Process .js files with ts-jest if 'ts' or with\n babel-jest if 'babel'\n --no-jest-preset Disable the use of Jest presets\n");
158
218
  return [2];
159
219
  });
160
220
  }); };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var JestPresetNames;
4
+ (function (JestPresetNames) {
5
+ JestPresetNames["default"] = "ts-jest/presets/default";
6
+ JestPresetNames["jsWithTs"] = "ts-jest/presets/js-with-ts";
7
+ JestPresetNames["jsWIthBabel"] = "ts-jest/presets/js-with-babel";
8
+ })(JestPresetNames = exports.JestPresetNames || (exports.JestPresetNames = {}));
9
+ var definePreset = function (fullName) { return ({
10
+ fullName: fullName,
11
+ get name() {
12
+ return this.isDefault ? 'ts-jest' : fullName;
13
+ },
14
+ get label() {
15
+ return fullName.split('/').pop();
16
+ },
17
+ get jsVarName() {
18
+ return this.isDefault
19
+ ? 'defaults'
20
+ : fullName
21
+ .split('/')
22
+ .pop()
23
+ .replace(/\-([a-z])/g, function (_, l) { return l.toUpperCase(); });
24
+ },
25
+ get value() {
26
+ return require("../../../" + fullName.replace(/^ts-jest\//, '') + "/jest-preset");
27
+ },
28
+ jsImport: function (varName) {
29
+ if (varName === void 0) { varName = 'tsjPreset'; }
30
+ return "const { " + this.jsVarName + ": " + varName + " } = require('ts-jest/presets')";
31
+ },
32
+ get isDefault() {
33
+ return fullName === JestPresetNames.default;
34
+ },
35
+ }); };
36
+ exports.allPresets = {};
37
+ exports.defaults = (exports.allPresets[JestPresetNames.default] = definePreset(JestPresetNames.default));
38
+ exports.jsWithTs = (exports.allPresets[JestPresetNames.jsWithTs] = definePreset(JestPresetNames.jsWithTs));
39
+ exports.jsWIthBabel = (exports.allPresets[JestPresetNames.jsWIthBabel] = definePreset(JestPresetNames.jsWIthBabel));
@@ -0,0 +1 @@
1
+ export {};
package/dist/cli/index.js CHANGED
@@ -50,11 +50,24 @@ function cli(args) {
50
50
  return __generator(this, function (_b) {
51
51
  parsedArgv = yargs_parser_1.default(args, {
52
52
  boolean: ['dry-run', 'jest-preset', 'allow-js', 'diff', 'babel', 'force', 'jsdom'],
53
- string: ['tsconfig'],
53
+ string: ['tsconfig', 'js'],
54
54
  count: ['verbose'],
55
55
  alias: { verbose: ['v'] },
56
56
  default: { jestPreset: true, verbose: 0 },
57
+ coerce: {
58
+ js: function (val) {
59
+ var res = val.trim().toLowerCase();
60
+ if (!['babel', 'ts'].includes(res))
61
+ throw new Error("The 'js' option must be 'babel' or 'ts', given: '" + val + "'.");
62
+ return res;
63
+ },
64
+ },
57
65
  });
66
+ if (parsedArgv.allowJs != null) {
67
+ if (parsedArgv.js)
68
+ throw new Error("The 'allowJs' and 'js' options cannot be set together.");
69
+ parsedArgv.js = parsedArgv.allowJs ? 'ts' : undefined;
70
+ }
58
71
  command = parsedArgv._.shift();
59
72
  isHelp = command === 'help';
60
73
  if (isHelp)
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ /// <reference types="jest" />
2
+ import { Logger } from 'bs-logger';
3
+ import { CompilerOptions, CustomTransformers, ParsedCommandLine } from 'typescript';
4
+ import { AstTransformerDesc, BabelConfig, BabelJestTransformer, TTypeScript, TsCompiler, TsJestConfig, TsJestGlobalOptions, TsJestHooksMap } from '../types';
5
+ export declare class ConfigSet {
6
+ readonly parentOptions?: TsJestGlobalOptions | undefined;
7
+ readonly projectPackageJson: Record<string, any>;
8
+ readonly projectDependencies: Record<string, string>;
9
+ readonly jest: jest.ProjectConfig;
10
+ readonly tsJest: TsJestConfig;
11
+ readonly typescript: ParsedCommandLine;
12
+ readonly tsconfig: any;
13
+ readonly versions: Record<string, string>;
14
+ readonly babel: BabelConfig | undefined;
15
+ readonly compilerModule: TTypeScript;
16
+ readonly babelJestTransformer: BabelJestTransformer | undefined;
17
+ readonly tsCompiler: TsCompiler;
18
+ readonly astTransformers: AstTransformerDesc[];
19
+ readonly tsCustomTransformers: CustomTransformers;
20
+ readonly hooks: TsJestHooksMap;
21
+ readonly shouldReportDiagnostic: (filePath: string) => boolean;
22
+ readonly shouldStringifyContent: (filePath: string) => boolean;
23
+ readonly tsCacheDir: string | undefined;
24
+ readonly overriddenCompilerOptions: Partial<CompilerOptions>;
25
+ readonly rootDir: string;
26
+ readonly cwd: string;
27
+ readonly tsJestDigest: string;
28
+ readonly cacheKey: string;
29
+ readonly logger: Logger;
30
+ constructor(jestConfig: jest.ProjectConfig, parentOptions?: TsJestGlobalOptions | undefined, parentLogger?: Logger);
31
+ resolvePath(inputPath: string, { throwIfMissing, nodeResolve }?: {
32
+ throwIfMissing?: boolean;
33
+ nodeResolve?: boolean;
34
+ }): string;
35
+ }