diff --git a/e2e/diagnostics/__tests__/diagnostics.spec.ts b/e2e/diagnostics/__tests__/diagnostics.spec.ts index f602e74846..b7cdef9512 100644 --- a/e2e/diagnostics/__tests__/diagnostics.spec.ts +++ b/e2e/diagnostics/__tests__/diagnostics.spec.ts @@ -1,4 +1,4 @@ -import { Thing } from '../foo' +import type { Thing } from '../foo' const thing: Thing = { a: 1 } diff --git a/e2e/utils.ts b/e2e/utils.ts index ee3e8f1075..725b59e877 100644 --- a/e2e/utils.ts +++ b/e2e/utils.ts @@ -1,7 +1,6 @@ import * as path from 'path' -import type { Config } from '@jest/types' -import { ExecaReturnValue, sync as spawnSync, SyncOptions } from 'execa' +import { type ExecaReturnValue, sync as spawnSync, type SyncOptions } from 'execa' import * as fs from 'graceful-fs' import { version } from '../package.json' @@ -12,7 +11,7 @@ interface RunResult extends ExecaReturnValue { status: number error: Error } -export const run = (cmd: string, cwd?: Config.Path, env?: Record): RunResult => { +export const run = (cmd: string, cwd?: string, env?: Record): RunResult => { const args = cmd.split(/\s/).slice(1) const spawnOptions = { cwd, env, preferLocal: false, reject: false } const result = spawnSync(cmd.split(/\s/)[0], args, spawnOptions as SyncOptions) as RunResult @@ -34,7 +33,7 @@ export const run = (cmd: string, cwd?: Config.Path, env?: Record return result } -export const runNpmInstall = (cwd: Config.Path, env?: Record): RunResult => { +export const runNpmInstall = (cwd: string, env?: Record): RunResult => { const lockfilePath = path.resolve(cwd, 'package-lock.json') let exists = true diff --git a/src/legacy/config/config-set.spec.ts b/src/legacy/config/config-set.spec.ts index 9023b45a94..db99869cc5 100644 --- a/src/legacy/config/config-set.spec.ts +++ b/src/legacy/config/config-set.spec.ts @@ -539,6 +539,18 @@ describe('raiseDiagnostics', () => { ] `) }) + + it('should not throw when diagnostics is false', () => { + const cs = createConfigSet({ + filterDiagnostics, + logger, + tsJestConfig: { diagnostics: false }, + }) + + logger.target.clear() + expect(() => cs.raiseDiagnostics([])).not.toThrow() + expect(() => cs.raiseDiagnostics([makeDiagnostic()])).not.toThrow() + }) }) describe("diagnostics don't contain source file", () => { diff --git a/src/legacy/config/config-set.ts b/src/legacy/config/config-set.ts index cc2dd7026b..dd0df18168 100644 --- a/src/legacy/config/config-set.ts +++ b/src/legacy/config/config-set.ts @@ -295,9 +295,13 @@ export class ConfigSet { throws: diagnosticsOpt, } } - this._shouldIgnoreDiagnosticsForFile = this._diagnostics.exclude.length - ? globsToMatcher(this._diagnostics.exclude) - : () => false + if (diagnosticsOpt) { + this._shouldIgnoreDiagnosticsForFile = this._diagnostics.exclude.length + ? globsToMatcher(this._diagnostics.exclude) + : () => false + } else { + this._shouldIgnoreDiagnosticsForFile = () => true + } this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option')