diff --git a/cli.js b/cli.js new file mode 100755 index 0000000000..d292428e45 --- /dev/null +++ b/cli.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +require('./dist/cli') diff --git a/package-lock.json b/package-lock.json index ff4eada904..3a865d6b09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -386,6 +386,12 @@ "integrity": "sha512-41qEJgBH/TWgo5NFSvBCJ1qkoi3Q6ONSF2avrHq1LVEZfYpdHmj0y9SuTK+u9ZhG1sYQKBL1AWXKyLWP4RaUoQ==", "dev": true }, + "@types/yargs": { + "version": "11.1.1", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-11.1.1.tgz", + "integrity": "sha512-Awgju4dqD8kHXX3jc/B/LaryJC7MsyNfnbN62lIbFzTi0GewH64zrkh4bxo/YTgVEK6r9V3GNecxMhXTJw0+jA==", + "dev": true + }, "JSONStream": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/JSONStream/-/JSONStream-1.3.4.tgz", @@ -8891,6 +8897,12 @@ "yargs-parser": "^9.0.2" }, "dependencies": { + "camelcase": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", + "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", + "dev": true + }, "cliui": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/cliui/-/cliui-4.1.0.tgz", @@ -8901,14 +8913,22 @@ "strip-ansi": "^4.0.0", "wrap-ansi": "^2.0.0" } + }, + "yargs-parser": { + "version": "9.0.2", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz", + "integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=", + "dev": true, + "requires": { + "camelcase": "^4.1.0" + } } } }, "yargs-parser": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-9.0.2.tgz", - "integrity": "sha1-nM9qQ0YP5O1Aqbto9I1DuKaMwHc=", - "dev": true, + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-10.1.0.tgz", + "integrity": "sha512-VCIyR1wJoEBZUqk5PA+oOBF6ypbwh5aNB3I50guxAL/quggdfs4TtNHQrSazFA3fYZ+tEqfs0zIGlv0c/rgjbQ==", "requires": { "camelcase": "^4.1.0" }, @@ -8916,8 +8936,7 @@ "camelcase": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-4.1.0.tgz", - "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=", - "dev": true + "integrity": "sha1-1UVjW+HjPFQmScaRc+Xeas+uNN0=" } } } diff --git a/package.json b/package.json index 1c4c4d9590..6fe3b20ea8 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "23.10.0-beta.2", "main": "dist/index.js", "types": "dist/index.d.ts", + "bin": "cli.js", "description": "A preprocessor with sourcemap support to help use Typescript with Jest", "scripts": { "prebuild": "node scripts/clean-dist.js", @@ -63,7 +64,8 @@ "make-error": "^1.3.5", "mkdirp": "^0.5.1", "semver": "^5.5.1", - "tslib": "^1.9.3" + "tslib": "^1.9.3", + "yargs-parser": "^10.1.0" }, "peerDependencies": { "babel-jest": ">=22 <24", @@ -86,6 +88,7 @@ "@types/mkdirp": "^0.5.2", "@types/node": "^10.9.4", "@types/semver": "^5.5.0", + "@types/yargs": "^11.1.1", "conventional-changelog-cli": "^2.0.5", "cross-spawn": "^6.0.5", "doctoc": "^1.3.1", diff --git a/src/cli/config/migrate.ts b/src/cli/config/migrate.ts new file mode 100644 index 0000000000..e512db79ab --- /dev/null +++ b/src/cli/config/migrate.ts @@ -0,0 +1,167 @@ +import { Logger } from 'bs-logger' +import stringifyJson from 'fast-json-stable-stringify' +import { existsSync } from 'fs' +import { stringify as stringifyJson5 } from 'json5' +import { basename, join } from 'path' +import { Arguments } from 'yargs' + +import { CliCommand } from '..' +import { createJestPreset } from '../../config/create-jest-preset' +import { backportJestConfig } from '../../util/backports' + +export const run: CliCommand = async (args: Arguments, logger: Logger) => { + const file = args._[0] + const filePath = join(process.cwd(), file) + if (!existsSync(filePath)) { + throw new Error(`Configuration file ${file} does not exists.`) + } + const name = basename(file) + const isPackage = name === 'package.json' + if (!/\.(js|json)$/.test(name)) { + throw new TypeError(`Configuration file ${file} must be a JavaScript or JSON file.`) + } + let actualConfig: jest.InitialOptions = require(filePath) + if (isPackage) { + actualConfig = (actualConfig as any).jest + } + if (!actualConfig) actualConfig = {} + + // migrate + // first we backport our options + const migratedConfig = backportJestConfig(logger, actualConfig) + // then we check if we can use `preset` + if (!migratedConfig.preset && args.jestPreset) { + migratedConfig.preset = 'ts-jest' + } else if (!args.jestPreset && migratedConfig.preset === 'ts-jest') { + delete migratedConfig.preset + } + const usesPreset = migratedConfig.preset === 'ts-jest' + const presets = createJestPreset({ allowJs: args.allowJs }) + + // check the extensions + if (migratedConfig.moduleFileExtensions && migratedConfig.moduleFileExtensions.length && usesPreset) { + const presetValue = dedupSort(presets.moduleFileExtensions).join('::') + const migratedValue = dedupSort(migratedConfig.moduleFileExtensions).join('::') + if (presetValue === migratedValue) { + delete migratedConfig.moduleFileExtensions + } + } + // check the testMatch + if (migratedConfig.testMatch && migratedConfig.testMatch.length && usesPreset) { + const presetValue = dedupSort(presets.testMatch).join('::') + const migratedValue = dedupSort(migratedConfig.testMatch).join('::') + if (presetValue === migratedValue) { + delete migratedConfig.testMatch + } + } + + // migrate the transform + if (migratedConfig.transform) { + Object.keys(migratedConfig.transform).forEach(key => { + const val = (migratedConfig.transform as any)[key] + if (typeof val === 'string' && /\/?ts-jest(?:\/preprocessor\.js)?$/.test(val)) { + // tslint:disable-next-line:semicolon + ;(migratedConfig.transform as any)[key] = 'ts-jest' + } + }) + } + // check if it's the same as the preset's one + if ( + usesPreset && + migratedConfig.transform && + stringifyJson(migratedConfig.transform) === stringifyJson(presets.transform) + ) { + delete migratedConfig.transform + } + + // cleanup + cleanupConfig(actualConfig) + cleanupConfig(migratedConfig) + const before = stringifyJson(actualConfig) + const after = stringifyJson(migratedConfig) + if (after === before) { + process.stderr.write(` +No migration needed for given Jest configuration + `) + return + } + + const stringify = /\.json$/.test(file) ? JSON.stringify : stringifyJson5 + const footNotes: string[] = [] + + // if we are using preset, inform the user that he might be able to remove some section(s) + // we couldn't check for equality + // if (usesPreset && migratedConfig.testMatch) { + // footNotes.push(` + // I couldn't check if your "testMatch" value is the same as mine which is: ${stringify( + // presets.testMatch, + // undefined, + // ' ', + // )} + // If it is the case, you can safely remove the "testMatch" from what I've migrated. + // `) + // } + if (usesPreset && migratedConfig.transform) { + footNotes.push(` +I couldn't check if your "transform" value is the same as mine which is: ${stringify( + presets.transform, + undefined, + ' ', + )} +If it is the case, you can safely remove the "transform" from what I've migrated. +`) + } + + // output new config + process.stderr.write(` +Migrated Jest configuration: +`) + process.stdout.write(`${stringify(migratedConfig, undefined, ' ')}\n`) + process.stderr.write(` +${footNotes.join('\n')} +`) +} + +function cleanupConfig(config: jest.InitialOptions): void { + if (config.globals) { + if ((config as any).globals['ts-jest'] && Object.keys((config as any).globals['ts-jest']).length === 0) { + delete (config as any).globals['ts-jest'] + } + if (Object.keys(config.globals).length === 0) { + delete config.globals + } + } + if (config.transform && Object.keys(config.transform).length === 0) { + delete config.transform + } + if (config.moduleFileExtensions) { + config.moduleFileExtensions = dedupSort(config.moduleFileExtensions) + if (config.moduleFileExtensions.length === 0) delete config.moduleFileExtensions + } + if (config.testMatch) { + config.testMatch = dedupSort(config.testMatch) + if (config.testMatch.length === 0) delete config.testMatch + } +} + +function dedupSort(arr: any[]) { + return arr + .filter((s, i, a) => a.findIndex(e => s.toString() === e.toString()) === i) + .sort((a, b) => (a.toString() > b.toString() ? 1 : a.toString() < b.toString() ? -1 : 0)) +} + +export const help: CliCommand = async () => { + process.stdout.write(` +Usage: + ts-jest config:migrate [options] + +Arguments: + Can be a js or json Jest config file. If it is a + package.json file, the configuration will be read from + the "jest" property. + +Options: + --allow-js TSJest will be used to process JS files as well + --no-jest-preset Disable the use of Jest presets +`) +} diff --git a/src/cli/help.ts b/src/cli/help.ts new file mode 100644 index 0000000000..af892ce3ab --- /dev/null +++ b/src/cli/help.ts @@ -0,0 +1,17 @@ +import { Arguments } from 'yargs' + +export const run = async (_: Arguments) => { + process.stdout.write(` +Usage: + ts-jest command [options] [...args] + +Commands: + help [command] Show this help, or help about a command + config:migrate Migrates a given Jest configuration + +Example: + ts-jest help config:migrate +`) +} + +export { run as help } diff --git a/src/cli/index.ts b/src/cli/index.ts new file mode 100644 index 0000000000..6c51aec9b8 --- /dev/null +++ b/src/cli/index.ts @@ -0,0 +1,41 @@ +import { LogContexts, Logger } from 'bs-logger' +import { Arguments } from 'yargs' +import yargsParser from 'yargs-parser' + +import { rootLogger } from '../util/logger' + +const VALID_COMMANDS = ['help', 'config:migrate'] + +// tslint:disable-next-line:prefer-const +let [, , ...args] = process.argv + +const logger = rootLogger.child({ [LogContexts.namespace]: 'cli', [LogContexts.application]: 'ts-jest' }) + +const parsedArgv = yargsParser(args, { + boolean: ['dryRun', 'jestPreset', 'allowJs', 'diff'], + count: ['verbose'], + alias: { verbose: ['v'] }, + default: { dryRun: false, jestPreset: true, allowJs: false, verbose: 0, diff: false }, +}) +let command = parsedArgv._.shift() as string +const isHelp = command === 'help' +if (isHelp) command = parsedArgv._.shift() as string + +if (!VALID_COMMANDS.includes(command)) command = 'help' + +export type CliCommand = (argv: Arguments, logger: Logger) => Promise + +// tslint:disable-next-line:no-var-requires +const { run, help }: { run: CliCommand; help: CliCommand } = require(`./${command.replace(/:/g, '/')}`) + +const cmd = isHelp && command !== 'help' ? help : run + +cmd(parsedArgv, logger).then( + () => { + process.exit(0) + }, + (err: Error) => { + logger.fatal(err.message) + process.exit(1) + }, +) diff --git a/src/config/create-jest-preset.ts b/src/config/create-jest-preset.ts index d6358192a9..07a2976ab0 100644 --- a/src/config/create-jest-preset.ts +++ b/src/config/create-jest-preset.ts @@ -12,17 +12,21 @@ const defaults = jestConfig.defaults || { moduleFileExtensions: ['js', 'json', 'jsx', 'node'], } -// TODO: find out if tsconfig that we'll use contains `allowJs` -// and change the transform so that it also uses ts-jest for js files - -export function createJestPreset({ allowJs = false }: CreateJestPresetOptions = {}) { +export function createJestPreset( + { allowJs = false }: CreateJestPresetOptions = {}, + from: jest.InitialOptions = defaults, +) { logger.debug({ allowJs }, 'creating jest presets', allowJs ? 'handling' : 'not handling', 'JavaScript files') return { transform: { - ...defaults.transform, + ...from.transform, [allowJs ? '^.+\\.[tj]sx?$' : '^.+\\.tsx?$']: 'ts-jest', }, - testMatch: [...defaults.testMatch, '**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)'], - moduleFileExtensions: [...defaults.moduleFileExtensions, 'ts', 'tsx'], + testMatch: dedup([...from.testMatch, '**/__tests__/**/*.ts?(x)', '**/?(*.)+(spec|test).ts?(x)']), + moduleFileExtensions: dedup([...from.moduleFileExtensions, 'ts', 'tsx']), } } + +function dedup(array: string[]): string[] { + return array.filter((e, i, a) => a.indexOf(e) === i) +} diff --git a/src/shims.d.ts b/src/shims.d.ts index ae225ba32d..18c2afafe0 100644 --- a/src/shims.d.ts +++ b/src/shims.d.ts @@ -17,3 +17,8 @@ declare module 'jest-config' { } declare module 'babel-core/lib/transformation/file' + +declare module 'yargs-parser' { + import yargs from 'yargs' + export = yargs.parse +} diff --git a/src/util/__snapshots__/backports.spec.ts.snap b/src/util/__snapshots__/backports.spec.ts.snap index 4a8a35d43a..6e9ad00a2c 100644 --- a/src/util/__snapshots__/backports.spec.ts.snap +++ b/src/util/__snapshots__/backports.spec.ts.snap @@ -17,8 +17,12 @@ Object { `; exports[`backportJestConfig with "globals.__TRANSFORM_HTML__" set to false should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.__TRANSFORM_HTML__\\" is deprecated, use \\"[jest-config].globals.ts-jest.stringifyContentPathRegex\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.__TRANSFORM_HTML__\\" is deprecated, use \\"[jest-config].globals.ts-jest.stringifyContentPathRegex\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.__TRANSFORM_HTML__" set to true should have changed the config correctly: before 1`] = ` @@ -40,8 +44,12 @@ Object { `; exports[`backportJestConfig with "globals.__TRANSFORM_HTML__" set to true should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.__TRANSFORM_HTML__\\" is deprecated, use \\"[jest-config].globals.ts-jest.stringifyContentPathRegex\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.__TRANSFORM_HTML__\\" is deprecated, use \\"[jest-config].globals.ts-jest.stringifyContentPathRegex\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.__TS_CONFIG__" set to { foo: 'bar' } should have changed the config correctly: before 1`] = ` @@ -67,8 +75,12 @@ Object { `; exports[`backportJestConfig with "globals.__TS_CONFIG__" set to { foo: 'bar' } should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.__TS_CONFIG__\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsConfig\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.__TS_CONFIG__\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsConfig\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to '\\\\.spec\\\\.ts$' should have changed the config correctly: before 1`] = ` @@ -94,8 +106,12 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to '\\\\.spec\\\\.ts$' should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to false should have changed the config correctly: before 1`] = ` @@ -119,8 +135,12 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to false should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to true should have changed the config correctly: before 1`] = ` @@ -144,8 +164,12 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.enableTsDiagnostics" set to true should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.enableTsDiagnostics\\" is deprecated, use \\"[jest-config].globals.ts-jest.diagnostics\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to false should have changed the config correctly: before 1`] = ` @@ -169,8 +193,12 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to false should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.skipBabel\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.skipBabel\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to true should have changed the config correctly: before 1`] = ` @@ -192,8 +220,12 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.skipBabel" set to true should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.skipBabel\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.skipBabel\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.tsConfigFile" set to 'tsconfig.build.json' should have changed the config correctly: before 1`] = ` @@ -217,8 +249,12 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.tsConfigFile" set to 'tsconfig.build.json' should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.tsConfigFile\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsConfig\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.tsConfigFile\\" is deprecated, use \\"[jest-config].globals.ts-jest.tsConfig\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.typeCheck" set to false should have changed the config correctly: before 1`] = ` @@ -242,8 +278,12 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.typeCheck" set to false should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.typeCheck\\" is deprecated, use \\"[jest-config].globals.ts-jest.isolatedModules\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.typeCheck\\" is deprecated, use \\"[jest-config].globals.ts-jest.isolatedModules\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.typeCheck" set to true should have changed the config correctly: before 1`] = ` @@ -267,8 +307,12 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.typeCheck" set to true should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.typeCheck\\" is deprecated, use \\"[jest-config].globals.ts-jest.isolatedModules\\" instead. -" +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.typeCheck\\" is deprecated, use \\"[jest-config].globals.ts-jest.isolatedModules\\" instead. +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.useBabelrc" set to false should have changed the config correctly: before 1`] = ` @@ -292,9 +336,13 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.useBabelrc" set to false should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.useBabelrc\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead. +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.useBabelrc\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead. ↳ See \`babel-jest\` related issue: https://github.com/facebook/jest/issues/3845 -" +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; exports[`backportJestConfig with "globals.ts-jest.useBabelrc" set to true should have changed the config correctly: before 1`] = ` @@ -318,7 +366,11 @@ Object { `; exports[`backportJestConfig with "globals.ts-jest.useBabelrc" set to true should wran the user 1`] = ` -"[level:40] \\"[jest-config].globals.ts-jest.useBabelrc\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead. +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.useBabelrc\\" is deprecated, use \\"[jest-config].globals.ts-jest.babelConfig\\" instead. ↳ See \`babel-jest\` related issue: https://github.com/facebook/jest/issues/3845 -" +", + "[level:40] Your Jest configuration is outdated. Use the CLI to help migrating it: ts-jest config:migrate . +", +] `; diff --git a/src/util/backports.spec.ts b/src/util/backports.spec.ts index 6ca920b790..9327a9b4eb 100644 --- a/src/util/backports.spec.ts +++ b/src/util/backports.spec.ts @@ -22,7 +22,7 @@ describe('backportJestConfig', () => { describe(`with "${oldPath}" set to ${inspect(val)}`, () => { it(`should wran the user`, () => { backportJestConfig(logger, original) - expect(logTarget.lines.warn.last).toMatchSnapshot() + expect(logTarget.lines.warn).toMatchSnapshot() }) // should warn the user it(`should have changed the config correctly`, () => { expect(original).toMatchSnapshot('before') diff --git a/src/util/backports.ts b/src/util/backports.ts index 0ecc6a9048..7e114aa1d2 100644 --- a/src/util/backports.ts +++ b/src/util/backports.ts @@ -1,6 +1,6 @@ import { LogContexts, Logger } from 'bs-logger' -import { Deprecateds, interpolate } from './messages' +import { Deprecateds, Helps, interpolate } from './messages' const context = { [LogContexts.namespace]: 'backports' } @@ -13,7 +13,9 @@ export const backportJestConfig = { + hadWarnings = true logger.warn( context, interpolate(note ? Deprecateds.ConfigOptionWithNote : Deprecateds.ConfigOption, { @@ -89,6 +91,11 @@ export const backportJestConfig =