diff --git a/e2e/__cases__/ts-jest-checks/index.spec.ts b/e2e/__cases__/ts-jest-checks/index.spec.ts deleted file mode 100644 index afda5cec8a..0000000000 --- a/e2e/__cases__/ts-jest-checks/index.spec.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { readFileSync } from 'fs' -import { ConfigSet } from 'ts-jest/dist/config/config-set' - -it('should have digest and versions', () => { - const cs = new ConfigSet(Object.create(null)) - expect(cs.tsJestDigest).toHaveLength(40) - expect(cs.tsJestDigest).toBe(readFileSync(require.resolve('ts-jest/.ts-jest-digest'), 'utf8')) -}) diff --git a/e2e/__tests__/ts-jest-checks.test.ts b/e2e/__tests__/ts-jest-checks.test.ts deleted file mode 100644 index 99a0554378..0000000000 --- a/e2e/__tests__/ts-jest-checks.test.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { allValidPackageSets } from '../__helpers__/templates' -import { configureTestCase } from '../__helpers__/test-case' - -describe('ts-jest internal checks test', () => { - const testCase = configureTestCase('ts-jest-checks') - - testCase.runWithTemplates(allValidPackageSets, 0, (runTest, { testLabel }) => { - it(testLabel, () => { - const result = runTest() - expect(result.status).toBe(0) - }) - }) -}) diff --git a/src/__helpers__/fakers.ts b/src/__helpers__/fakers.ts index ae6796cdcf..941d4369e1 100644 --- a/src/__helpers__/fakers.ts +++ b/src/__helpers__/fakers.ts @@ -4,7 +4,7 @@ import { resolve } from 'path' import { createCompilerInstance } from '../compiler/instance' import { ConfigSet } from '../config/config-set' -import type { BabelConfig, TsCompiler, TsJestConfig, TsJestGlobalOptions } from '../types' +import type { BabelConfig, TsCompiler, TsJestGlobalOptions } from '../types' import type { ImportReasons } from '../utils/messages' export function filePath(relPath: string): string { @@ -13,18 +13,8 @@ export function filePath(relPath: string): string { export const rootDir = filePath('') -export function tsJestConfig(options?: Partial): TsJestConfig { - return { - isolatedModules: false, - compiler: 'typescript', - transformers: options?.transformers ?? Object.create(null), - babelConfig: undefined, - tsConfig: undefined, - stringifyContentPathRegex: undefined, - diagnostics: { ignoreCodes: [], pretty: false, throws: true }, - ...options, - } -} +const defaultTestRegex = ['(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.[jt]sx?$'] +const defaultTestMatch = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'] function getJestConfig( options?: Partial, @@ -68,7 +58,15 @@ export function createConfigSet({ resolve?: ((path: string) => string) | null [key: string]: any } = {}): ConfigSet { - const cs = new ConfigSet(getJestConfig(jestConfig, tsJestConfig), logger) + const jestCfg = getJestConfig(jestConfig, tsJestConfig) + const cs = new ConfigSet( + { + ...jestCfg, + testMatch: jestConfig?.testMatch ? [...jestConfig.testMatch, ...defaultTestMatch] : defaultTestMatch, + testRegex: jestConfig?.testRegex ? [...jestConfig.testRegex, ...defaultTestRegex] : defaultTestRegex, + }, + logger, + ) if (resolve) { cs.resolvePath = resolve } @@ -94,12 +92,10 @@ export function makeCompiler({ ...(tsJestConfig.diagnostics as any), pretty: false, } - const defaultTestRegex = ['(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.[jt]sx?$'] - const defaultTestMatch = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)'] jestConfig = { ...jestConfig, testMatch: jestConfig?.testMatch ? [...jestConfig.testMatch, ...defaultTestMatch] : defaultTestMatch, - testRegex: jestConfig?.testRegex ? [...defaultTestRegex, ...jestConfig.testRegex] : defaultTestRegex, + testRegex: jestConfig?.testRegex ? [...jestConfig.testRegex, ...defaultTestRegex] : defaultTestRegex, } const cs = createConfigSet({ jestConfig, tsJestConfig, parentConfig, resolve: null }) diff --git a/src/compiler/__snapshots__/transpiler.spec.ts.snap b/src/compiler/__snapshots__/transpiler.spec.ts.snap index 34340c79bf..2dc07032c1 100644 --- a/src/compiler/__snapshots__/transpiler.spec.ts.snap +++ b/src/compiler/__snapshots__/transpiler.spec.ts.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`Transpiler diagnostics should report diagnostics related to codes with pathRegex config is undefined 1`] = `"foo.ts(2,23): error TS1005: '=>' expected."`; +exports[`Transpiler diagnostics should report diagnostics related to codes with exclude config matches file name 1`] = `"foo.ts(2,23): error TS1005: '=>' expected."`; -exports[`Transpiler diagnostics should report diagnostics related to codes with pathRegex config matches file name 1`] = `"foo.ts(2,23): error TS1005: '=>' expected."`; +exports[`Transpiler diagnostics should report diagnostics related to codes with pathRegex config is undefined 1`] = `"foo.ts(2,23): error TS1005: '=>' expected."`; exports[`Transpiler jsx option should compile tsx file for jsx preserve 1`] = ` ===[ FILE: foo.tsx ]============================================================ diff --git a/src/compiler/language-service.spec.ts b/src/compiler/language-service.spec.ts index bf42165889..2d7d940687 100644 --- a/src/compiler/language-service.spec.ts +++ b/src/compiler/language-service.spec.ts @@ -259,7 +259,7 @@ describe('Language service', () => { const compiler = makeCompiler({ tsJestConfig: { ...baseTsJestConfig, - diagnostics: { pathRegex: 'foo.spec.ts' }, + diagnostics: { exclude: ['foo.spec.ts'] }, }, }) diff --git a/src/compiler/transpiler.spec.ts b/src/compiler/transpiler.spec.ts index 2883cbd226..8a8e822ae8 100644 --- a/src/compiler/transpiler.spec.ts +++ b/src/compiler/transpiler.spec.ts @@ -120,9 +120,9 @@ const t: string = f(5) ).toThrowErrorMatchingSnapshot() }) - it('should report diagnostics related to codes with pathRegex config matches file name', () => { + it('should report diagnostics related to codes with exclude config matches file name', () => { const compiler = makeCompiler({ - tsJestConfig: { ...baseTsJestConfig, tsconfig: false, diagnostics: { pathRegex: 'foo.ts' } }, + tsJestConfig: { ...baseTsJestConfig, tsconfig: false, diagnostics: { exclude: ['foo.ts'] } }, }) expect(() => @@ -136,9 +136,9 @@ const t: string = f(5) ).toThrowErrorMatchingSnapshot() }) - it('should not report diagnostics related to codes with pathRegex config does not match file name', () => { + it('should not report diagnostics related to codes with exclude config does not match file name', () => { const compiler = makeCompiler({ - tsJestConfig: { ...baseTsJestConfig, tsconfig: false, diagnostics: { pathRegex: 'bar.ts' } }, + tsJestConfig: { ...baseTsJestConfig, tsconfig: false, diagnostics: { exclude: ['bar.ts'] } }, }) expect(() => diff --git a/src/config/config-set.spec.ts b/src/config/config-set.spec.ts index 95b0b50dd1..9e73850299 100644 --- a/src/config/config-set.spec.ts +++ b/src/config/config-set.spec.ts @@ -499,13 +499,20 @@ describe('isTestFile', () => { describe('shouldStringifyContent', () => { it('should return correct value is defined', () => { - const cs = createConfigSet({ tsJestConfig: { tsconfig: false, stringifyContentPathRegex: '\\.str$' } as any }) - expect(cs.shouldStringifyContent('/foo/bar.ts')).toBe(false) - expect(cs.shouldStringifyContent('/foo/bar.str')).toBe(true) + const cs1 = createConfigSet({ tsJestConfig: { tsconfig: false, stringifyContentPathRegex: '\\.str$' } as any }) + + expect(cs1.shouldStringifyContent('/foo/bar.ts')).toBe(false) + expect(cs1.shouldStringifyContent('/foo/bar.str')).toBe(true) + + const cs2 = createConfigSet({ tsJestConfig: { tsconfig: false, stringifyContentPathRegex: /\.str$/ } as any }) + + expect(cs2.shouldStringifyContent('/foo/bar.ts')).toBe(false) + expect(cs2.shouldStringifyContent('/foo/bar.str')).toBe(true) }) it('should return correct value when stringifyContentPathRegex is undefined', () => { const cs = createConfigSet({ tsJestConfig: { tsconfig: false } as any }) + expect(cs.shouldStringifyContent('/foo/bar.ts')).toBe(false) }) }) // shouldStringifyContent @@ -554,8 +561,19 @@ describe('raiseDiagnostics', () => { code = 9999, category = ts.DiagnosticCategory.Warning, }: Partial = {}): ts.Diagnostic => ({ messageText, code, category } as any) - it('should throw when diagnostics contains file path and pathRegex config matches file path', () => { - const cs = createConfigSet({ + + it('should throw when diagnostics contains file path and exclude config matches file path', () => { + let cs = createConfigSet({ + logger, + tsJestConfig: { diagnostics: { exclude: ['src/__mocks__/index.ts'], pretty: false } }, + }) + logger.target.clear() + + expect(() => + cs.raiseDiagnostics([makeDiagnostic()], 'src/__mocks__/index.ts', logger), + ).toThrowErrorMatchingInlineSnapshot(`"warning TS9999: foo"`) + + cs = createConfigSet({ logger, tsJestConfig: { diagnostics: { pathRegex: 'src/__mocks__/index.ts', pretty: false } }, }) @@ -566,8 +584,16 @@ describe('raiseDiagnostics', () => { ).toThrowErrorMatchingInlineSnapshot(`"warning TS9999: foo"`) }) - it("should not throw when diagnostics contains file path and pathRegex config doesn't match file path", () => { - const cs = createConfigSet({ + it("should not throw when diagnostics contains file path and exclude config doesn't match file path", () => { + let cs = createConfigSet({ + logger, + tsJestConfig: { diagnostics: { warnOnly: true, exclude: ['/bar/'], pretty: false } }, + }) + logger.target.clear() + + expect(() => cs.raiseDiagnostics([makeDiagnostic()], 'src/__mocks__/index.ts', logger)).not.toThrow() + + cs = createConfigSet({ logger, tsJestConfig: { diagnostics: { warnOnly: true, pathRegex: '/bar/', pretty: false } }, }) @@ -591,38 +617,106 @@ describe('raiseDiagnostics', () => { file = program.getSourceFiles().find((sourceFile) => sourceFile.fileName === 'src/__mocks__/index.ts'), }: Partial = {}): ts.Diagnostic => ({ messageText, code, category, file } as any) - it("should not throw when pathRegex config doesn't match source file path", () => { + it("should not throw when exclude config doesn't match source file path", () => { const cs = createConfigSet({ logger, - tsJestConfig: { diagnostics: { pathRegex: '/foo/', pretty: false, ignoreCodes: [1111] } }, + tsJestConfig: { diagnostics: { exclude: ['/foo/'], pretty: false, ignoreCodes: [1111] } }, }) logger.target.clear() expect(() => cs.raiseDiagnostics([makeDiagnostic()])).not.toThrow() + + const cs1 = createConfigSet({ + logger, + tsJestConfig: { diagnostics: { pathRegex: '/foo/', pretty: false, ignoreCodes: [1111] } }, + }) + logger.target.clear() + + expect(() => cs1.raiseDiagnostics([makeDiagnostic()])).not.toThrow() }) - it("should throw when pathRegex config doesn't match source file path", () => { + it("should throw when exclude config doesn't match source file path", () => { const cs = createConfigSet({ logger, - tsJestConfig: { diagnostics: { pathRegex: 'src/__mocks__/index.ts', pretty: false } }, + tsJestConfig: { diagnostics: { exclude: ['src/__mocks__/index.ts'], pretty: false } }, }) logger.target.clear() expect(() => cs.raiseDiagnostics([makeDiagnostic()])).toThrowErrorMatchingInlineSnapshot( `"Debug Failure. False expression: position cannot precede the beginning of the file"`, ) + + const cs1 = createConfigSet({ + logger, + tsJestConfig: { diagnostics: { pathRegex: 'src/__mocks__/index.ts', pretty: false } }, + }) + logger.target.clear() + + expect(() => cs1.raiseDiagnostics([makeDiagnostic()])).toThrowErrorMatchingInlineSnapshot( + `"Debug Failure. False expression: position cannot precede the beginning of the file"`, + ) }) }) }) // raiseDiagnostics describe('shouldReportDiagnostics', () => { - it('should return correct value', () => { - let cs = createConfigSet({ tsJestConfig: { tsconfig: false, diagnostics: { pathRegex: '/foo/' } } as any }) + it('should return correct value for ts/tsx files', () => { + let cs = createConfigSet({ + tsJestConfig: { + tsconfig: false, + diagnostics: { exclude: ['**/foo/*.ts', '**/foo/*.tsx'] }, + } as any, + }) + + expect(cs.shouldReportDiagnostics('/foo/index.ts')).toBe(true) + expect(cs.shouldReportDiagnostics('/bar/index.tsx')).toBe(false) + + cs = createConfigSet({ + tsJestConfig: { + tsconfig: false, + diagnostics: { pathRegex: '/foo/' }, + } as any, + }) + expect(cs.shouldReportDiagnostics('/foo/index.ts')).toBe(true) - expect(cs.shouldReportDiagnostics('/bar/index.ts')).toBe(false) + expect(cs.shouldReportDiagnostics('/bar/index.tsx')).toBe(false) + cs = createConfigSet({ tsJestConfig: { tsconfig: false } as any }) + expect(cs.shouldReportDiagnostics('/foo/index.ts')).toBe(true) - expect(cs.shouldReportDiagnostics('/bar/index.ts')).toBe(true) + expect(cs.shouldReportDiagnostics('/bar/index.tsx')).toBe(true) + }) + + test('should return correct value for js/jsx files with checkJs compiler option', () => { + let cs = createConfigSet({ + tsJestConfig: { + tsconfig: { checkJs: false }, + diagnostics: { exclude: ['foo/*'] }, + }, + }) + + expect(cs.shouldReportDiagnostics('/foo/index.js')).toBe(false) + expect(cs.shouldReportDiagnostics('/foo/index.jsx')).toBe(false) + + cs = createConfigSet({ + tsJestConfig: { + tsconfig: { checkJs: false }, + diagnostics: { pathRegex: '/bar/' }, + }, + }) + + expect(cs.shouldReportDiagnostics('/foo/index.js')).toBe(false) + expect(cs.shouldReportDiagnostics('/foo/index.jsx')).toBe(false) + + cs = createConfigSet({ + tsJestConfig: { + tsconfig: { checkJs: true }, + diagnostics: { exclude: ['**/foo/*.js', '**/foo/*.jsx'] }, + }, + }) + + expect(cs.shouldReportDiagnostics('/foo/index.js')).toBe(true) + expect(cs.shouldReportDiagnostics('/foo/index.jsx')).toBe(true) }) }) // shouldReportDiagnostics @@ -979,7 +1073,7 @@ describe('diagnostics', () => { { diagnostics: { ignoreCodes: '10, 25', - pathRegex: '\\.test\\.ts', + exclude: ['\\.test\\.ts'], pretty: false, }, }, @@ -987,7 +1081,7 @@ describe('diagnostics', () => { diagnostics: { ignoreCodes: ['10', 25], pretty: false, - pathRegex: RegExp('\\.test\\.ts'), + exclude: ['\\.test\\.ts'], }, }, { diagnostics: { warnOnly: true } }, diff --git a/src/config/config-set.ts b/src/config/config-set.ts index ae736bdc89..52a16386ff 100644 --- a/src/config/config-set.ts +++ b/src/config/config-set.ts @@ -139,6 +139,18 @@ export class ConfigSet { * @internal */ private _stringifyContentRegExp: RegExp | undefined + /** + * @internal + */ + private readonly _matchablePatterns: (string | RegExp)[] + /** + * @internal + */ + private readonly _matchTestFilePath: (filePath: string) => boolean + /** + * @internal + */ + private _shouldGetDiagnosticsForFile!: ((filePath: string) => boolean) | RegExp protected _overriddenCompilerOptions: Partial = { // we handle sourcemaps this way and not another sourceMap: true, @@ -160,18 +172,7 @@ export class ConfigSet { tsBuildInfoFile: undefined, } - constructor( - /** - * @internal - */ - private readonly jestConfig: Config.ProjectConfig, - /** - * Mainly for testing logging - * - * @internal - */ - private readonly parentLogger?: Logger, - ) { + constructor(private readonly jestConfig: Config.ProjectConfig, private readonly parentLogger?: Logger) { this.logger = this.parentLogger ? this.parentLogger.child({ [LogContexts.namespace]: 'config' }) : rootLogger.child({ namespace: 'config' }) @@ -189,6 +190,20 @@ export class ConfigSet { this._backportJestCfg() this._setupTsJestCfg(options) this._resolveTsCacheDir() + this._matchablePatterns = [...this._jestCfg.testMatch, ...this._jestCfg.testRegex].filter( + (pattern) => + /** + * jest config testRegex doesn't always deliver the correct RegExp object + * See https://github.com/facebook/jest/issues/9778 + */ + pattern instanceof RegExp || typeof pattern === 'string', + ) + if (!this._matchablePatterns.length) { + this._matchablePatterns.push(...DEFAULT_JEST_TEST_MATCH) + } + this._matchTestFilePath = globsToMatcher( + this._matchablePatterns.filter((pattern: any) => typeof pattern === 'string') as string[], + ) } /** @@ -259,17 +274,33 @@ export class ConfigSet { } this._diagnostics = { pretty: diagnosticsOpt.pretty ?? true, + exclude: diagnosticsOpt.exclude ?? [], ignoreCodes: toDiagnosticCodeList(ignoreList), - pathRegex: normalizeRegex(diagnosticsOpt.pathRegex), throws: !diagnosticsOpt.warnOnly, } + if (diagnosticsOpt.pathRegex) { + this.logger.warn(Deprecations.PathRegex) + + this._diagnostics = { + ...this._diagnostics, + pathRegex: normalizeRegex(diagnosticsOpt.pathRegex), + } + } } else { this._diagnostics = { ignoreCodes: diagnosticsOpt ? toDiagnosticCodeList(ignoreList) : [], + exclude: [], pretty: true, throws: diagnosticsOpt, } } + if (this._diagnostics.pathRegex && !this._diagnostics.exclude.length) { + this._shouldGetDiagnosticsForFile = new RegExp(this._diagnostics.pathRegex) + } else { + this._shouldGetDiagnosticsForFile = this._diagnostics.exclude.length + ? globsToMatcher(this._diagnostics.exclude) + : () => true + } this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option') @@ -536,24 +567,10 @@ export class ConfigSet { return {} } - @Memoize() - get isTestFile(): (fileName: string) => boolean { - const matchablePatterns = [...this._jestCfg.testMatch, ...this._jestCfg.testRegex].filter( - (pattern) => - /** - * jest config testRegex doesn't always deliver the correct RegExp object - * See https://github.com/facebook/jest/issues/9778 - */ - pattern instanceof RegExp || typeof pattern === 'string', + isTestFile(fileName: string): boolean { + return this._matchablePatterns.some((pattern) => + typeof pattern === 'string' ? this._matchTestFilePath(fileName) : pattern.test(fileName), ) - if (!matchablePatterns.length) { - matchablePatterns.push(...DEFAULT_JEST_TEST_MATCH) - } - const stringPatterns = matchablePatterns.filter((pattern: any) => typeof pattern === 'string') as string[] - const isMatch = globsToMatcher(stringPatterns) - - return (fileName: string) => - matchablePatterns.some((pattern) => (typeof pattern === 'string' ? isMatch(fileName) : pattern.test(fileName))) } shouldStringifyContent(filePath: string): boolean { @@ -585,14 +602,9 @@ export class ConfigSet { } shouldReportDiagnostics(filePath: string): boolean { - const { pathRegex } = this._diagnostics - if (pathRegex) { - const regex = new RegExp(pathRegex) - - return regex.test(filePath) - } else { - return true - } + return this._shouldGetDiagnosticsForFile instanceof RegExp + ? this._shouldGetDiagnosticsForFile.test(filePath) + : this._shouldGetDiagnosticsForFile(filePath) } /** diff --git a/src/ts-jest-transformer.spec.ts b/src/ts-jest-transformer.spec.ts index b8ba3bdf48..774caea003 100644 --- a/src/ts-jest-transformer.spec.ts +++ b/src/ts-jest-transformer.spec.ts @@ -15,7 +15,7 @@ beforeEach(() => { describe('TsJestTransformer', () => { describe('configFor', () => { it('should return the same config-set for same values with jest config string is not in configSetsIndex', () => { - const obj1 = { cwd: '/foo/.', rootDir: '/bar//dummy/..', globals: {} } + const obj1 = { cwd: '/foo/.', rootDir: '/bar//dummy/..', globals: {}, testMatch: [], testRegex: [] } const cs3 = new TsJestTransformer().configsFor(obj1 as any) expect(cs3.cwd).toBe(`${sep}foo`) @@ -23,7 +23,7 @@ describe('TsJestTransformer', () => { }) it('should return the same config-set for same values with jest config string in configSetsIndex', () => { - const obj1 = { cwd: '/foo/.', rootDir: '/bar//dummy/..', globals: {} } + const obj1 = { cwd: '/foo/.', rootDir: '/bar//dummy/..', globals: {}, testMatch: [], testRegex: [] } const obj2 = { ...obj1 } const cs1 = new TsJestTransformer().configsFor(obj1 as any) const cs2 = new TsJestTransformer().configsFor(obj2 as any) @@ -41,7 +41,7 @@ describe('TsJestTransformer', () => { fileContent: 'export default "foo"', fileName: 'foo.ts', jestConfigStr: '{"foo": "bar"}', - options: { config: { foo: 'bar' } as any, instrument: false, rootDir: '/foo' }, + options: { config: { foo: 'bar', testMatch: [], testRegex: [] } as any, instrument: false, rootDir: '/foo' }, } const keys = [ tr.getCacheKey(input.fileContent, input.fileName, input.jestConfigStr, input.options), @@ -75,6 +75,8 @@ describe('TsJestTransformer', () => { stringifyContentPathRegex: '\\.html$', }, }, + testMatch: [], + testRegex: [], } as any tr.getCacheKey(fileContent, filePath, JSON.stringify(jestCfg), { config: jestCfg } as any) @@ -86,7 +88,10 @@ describe('TsJestTransformer', () => { it('should process type definition input', () => { const fileContent = 'type Foo = number' const filePath = 'foo.d.ts' - const jestCfg = Object.create(null) + const jestCfg = { + testMatch: [], + testRegex: [], + } as any tr.getCacheKey(fileContent, filePath, JSON.stringify(jestCfg), { config: jestCfg } as any) const result = tr.process(fileContent, filePath, jestCfg) @@ -100,6 +105,8 @@ describe('TsJestTransformer', () => { globals: { 'ts-jest': { tsconfig: { allowJs: false } }, }, + testMatch: [], + testRegex: [], } as any tr.getCacheKey(fileContent, filePath, JSON.stringify(jestCfg), { config: jestCfg } as any) logTarget.clear() @@ -118,7 +125,10 @@ describe('TsJestTransformer', () => { it.each(['foo.ts', 'foo.tsx'])('should process ts/tsx file', (filePath) => { const fileContent = 'const foo = 1' const output = 'var foo = 1' - const jestCfg = Object.create(null) + const jestCfg = { + testMatch: [], + testRegex: [], + } as any tr.getCacheKey(fileContent, filePath, JSON.stringify(jestCfg), { config: jestCfg } as any) jest.spyOn(ConfigSet.prototype, 'tsCompiler', 'get').mockImplementationOnce(() => ({ compile: () => output, @@ -138,6 +148,8 @@ describe('TsJestTransformer', () => { globals: { 'ts-jest': { tsconfig: { allowJs: true } }, }, + testMatch: [], + testRegex: [], } as any tr.getCacheKey(fileContent, filePath, JSON.stringify(jestCfg), { config: jestCfg } as any) logTarget.clear() @@ -159,6 +171,8 @@ describe('TsJestTransformer', () => { globals: { 'ts-jest': { tsconfig: { allowJs: true } }, }, + testMatch: [], + testRegex: [], } as any tr.getCacheKey(fileContent, filePath, JSON.stringify(jestCfg), { config: jestCfg } as any) logTarget.clear() @@ -178,6 +192,8 @@ describe('TsJestTransformer', () => { globals: { 'ts-jest': { babelConfig: true }, }, + testMatch: [], + testRegex: [], } as any tr.getCacheKey(fileContent, filePath, JSON.stringify(jestCfg), { config: jestCfg } as any) logTarget.clear() diff --git a/src/types.ts b/src/types.ts index 1e930234ec..5abc0d0639 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,5 @@ import type { Transformer } from '@jest/transform' +import type { Config } from '@jest/types' import type * as _babel from 'babel__core' import type * as _ts from 'typescript' @@ -117,8 +118,14 @@ export interface TsJestGlobalOptions { /** * If specified, diagnostics of source files which path does **not** match * will be ignored + * + * @deprecated */ pathRegex?: RegExp | string + /** + * If specified, diagnostics of source files which path **matches** will be ignored + */ + exclude?: Config.Glob[] /** * Logs TypeScript errors to stderr instead of throwing exceptions * @@ -160,6 +167,7 @@ export interface TsJestDiagnosticsCfg { pretty: boolean ignoreCodes: number[] pathRegex?: string | undefined + exclude: Config.Glob[] throws: boolean warnOnly?: boolean } diff --git a/src/utils/messages.ts b/src/utils/messages.ts index a699df89d4..9338b912af 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -40,6 +40,7 @@ export const enum Deprecations { AstTransformerArrayConfig = 'The configuration for astTransformers as string[] is deprecated and will be removed in ts-jest 27. Please define your custom AST transformers in a form of an object. More information you can check online documentation https://kulshekhar.github.io/ts-jest/user/config/astTransformers', TsConfig = 'The option `tsConfig` is deprecated and will be removed in ts-jest 27, use `tsconfig` instead', PackageJson = 'The option `packageJson` is deprecated and will be removed in ts-jest 27. This option is not used by internal `ts-jest`', + PathRegex = 'The option `pathRegex` is deprecated and will be removed in ts-jest 27, use `exclude` instead', } /**