diff --git a/src/__mocks__/tsconfig-src.json b/src/__mocks__/tsconfig-mocks.json similarity index 100% rename from src/__mocks__/tsconfig-src.json rename to src/__mocks__/tsconfig-mocks.json diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index 821ee61c96..dc72b77b64 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -51,7 +51,7 @@ describe('parsedTsConfig', () => { }) it('should fallback to ES2015 as default target and CommonJS as default module when no target or module defined in tsconfig', () => { - const compilerOptions = get({ tsconfig: 'tsconfig.spec.json' }).options + const compilerOptions = get({ tsconfig: 'src/__mocks__/tsconfig-mocks.json' }).options expect(compilerOptions.target).toBe(ts.ScriptTarget.ES2015) expect(compilerOptions.module).toBe(ts.ModuleKind.CommonJS) diff --git a/src/utils/__snapshots__/backports.spec.ts.snap b/src/utils/__snapshots__/backports.spec.ts.snap index 46276af0ff..b681d85848 100644 --- a/src/utils/__snapshots__/backports.spec.ts.snap +++ b/src/utils/__snapshots__/backports.spec.ts.snap @@ -233,6 +233,35 @@ Array [ ] `; +exports[`backportJestConfig with "globals.ts-jest.tsConfig" set to 'tsconfig.build.json' should have changed the config correctly: before 1`] = ` +Object { + "globals": Object { + "ts-jest": Object { + "tsConfig": "tsconfig.build.json", + }, + }, +} +`; + +exports[`backportJestConfig with "globals.ts-jest.tsConfig" set to 'tsconfig.build.json' should have changed the config correctly: migrated 1`] = ` +Object { + "globals": Object { + "ts-jest": Object { + "tsconfig": "tsconfig.build.json", + }, + }, +} +`; + +exports[`backportJestConfig with "globals.ts-jest.tsConfig" set to 'tsconfig.build.json' should warn the user 1`] = ` +Array [ + "[level:40] \\"[jest-config].globals.ts-jest.tsConfig\\" 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.tsConfigFile" set to 'tsconfig.build.json' should have changed the config correctly: before 1`] = ` Object { "globals": Object { diff --git a/src/utils/backports.spec.ts b/src/utils/backports.spec.ts index 675ba482e0..1dfe486116 100644 --- a/src/utils/backports.spec.ts +++ b/src/utils/backports.spec.ts @@ -1,7 +1,7 @@ import { inspect } from 'util' import { testing } from 'bs-logger' -import set = require('lodash/set') +import set from 'lodash/set' import { backportJestConfig } from './backports' @@ -13,20 +13,23 @@ beforeEach(() => { }) describe('backportJestConfig', () => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const makeTestsFor = (oldPath: string, _: string, values: any[]) => { + const makeTestsFor = (oldPath: string, values: unknown[]) => { values.forEach((val) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any let original: any + beforeEach(() => { original = {} set(original, oldPath, val) }) + describe(`with "${oldPath}" set to ${inspect(val)}`, () => { it('should warn the user', () => { backportJestConfig(logger, original) + expect(logTarget.lines.warn).toMatchSnapshot() }) // should warn the user + it('should have changed the config correctly', () => { expect(original).toMatchSnapshot('before') expect(backportJestConfig(logger, original)).toMatchSnapshot('migrated') @@ -35,17 +38,19 @@ describe('backportJestConfig', () => { }) // for } // makeTestsFor - makeTestsFor('globals.__TS_CONFIG__', 'globals.ts-jest.tsConfig', [{ foo: 'bar' }]) + makeTestsFor('globals.__TS_CONFIG__', [{ foo: 'bar' }]) + + makeTestsFor('globals.__TRANSFORM_HTML__', [true, false]) - makeTestsFor('globals.__TRANSFORM_HTML__', 'globals.ts-jest.stringifyContentPathRegex', [true, false]) + makeTestsFor('globals.ts-jest.tsConfigFile', ['tsconfig.build.json']) - makeTestsFor('globals.ts-jest.tsConfigFile', 'globals.ts-jest.tsConfig', ['tsconfig.build.json']) + makeTestsFor('globals.ts-jest.tsConfig', ['tsconfig.build.json']) - makeTestsFor('globals.ts-jest.enableTsDiagnostics', 'globals.ts-jest.diagnostics', [true, false, '\\.spec\\.ts$']) + makeTestsFor('globals.ts-jest.enableTsDiagnostics', [true, false, '\\.spec\\.ts$']) - makeTestsFor('globals.ts-jest.useBabelrc', 'globals.ts-jest.babelConfig', [true, false]) + makeTestsFor('globals.ts-jest.useBabelrc', [true, false]) - makeTestsFor('globals.ts-jest.typeCheck', 'globals.ts-jest.isolatedModules', [true, false]) + makeTestsFor('globals.ts-jest.typeCheck', [true, false]) - makeTestsFor('globals.ts-jest.skipBabel', 'globals.ts-jest.babelConfig', [true, false]) + makeTestsFor('globals.ts-jest.skipBabel', [true, false]) }) diff --git a/src/utils/backports.ts b/src/utils/backports.ts index 2b0085fa40..3887c42616 100644 --- a/src/utils/backports.ts +++ b/src/utils/backports.ts @@ -62,6 +62,14 @@ export const backportJestConfig =