Skip to content

Commit 9a9bc02

Browse files
authoredJun 19, 2022
fix(config): don't show diagnostics warning with diagnostics: false (#3647)
Fixes #3638
1 parent 58cdc7d commit 9a9bc02

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed
 

‎e2e/diagnostics/__tests__/diagnostics.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Thing } from '../foo'
1+
import type { Thing } from '../foo'
22

33
const thing: Thing = { a: 1 }
44

‎e2e/utils.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as path from 'path'
22

3-
import type { Config } from '@jest/types'
4-
import { ExecaReturnValue, sync as spawnSync, SyncOptions } from 'execa'
3+
import { type ExecaReturnValue, sync as spawnSync, type SyncOptions } from 'execa'
54
import * as fs from 'graceful-fs'
65

76
import { version } from '../package.json'
@@ -12,7 +11,7 @@ interface RunResult extends ExecaReturnValue {
1211
status: number
1312
error: Error
1413
}
15-
export const run = (cmd: string, cwd?: Config.Path, env?: Record<string, string>): RunResult => {
14+
export const run = (cmd: string, cwd?: string, env?: Record<string, string>): RunResult => {
1615
const args = cmd.split(/\s/).slice(1)
1716
const spawnOptions = { cwd, env, preferLocal: false, reject: false }
1817
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<string, string>
3433
return result
3534
}
3635

37-
export const runNpmInstall = (cwd: Config.Path, env?: Record<string, string>): RunResult => {
36+
export const runNpmInstall = (cwd: string, env?: Record<string, string>): RunResult => {
3837
const lockfilePath = path.resolve(cwd, 'package-lock.json')
3938
let exists = true
4039

‎src/legacy/config/config-set.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,18 @@ describe('raiseDiagnostics', () => {
539539
]
540540
`)
541541
})
542+
543+
it('should not throw when diagnostics is false', () => {
544+
const cs = createConfigSet({
545+
filterDiagnostics,
546+
logger,
547+
tsJestConfig: { diagnostics: false },
548+
})
549+
550+
logger.target.clear()
551+
expect(() => cs.raiseDiagnostics([])).not.toThrow()
552+
expect(() => cs.raiseDiagnostics([makeDiagnostic()])).not.toThrow()
553+
})
542554
})
543555

544556
describe("diagnostics don't contain source file", () => {

‎src/legacy/config/config-set.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,13 @@ export class ConfigSet {
295295
throws: diagnosticsOpt,
296296
}
297297
}
298-
this._shouldIgnoreDiagnosticsForFile = this._diagnostics.exclude.length
299-
? globsToMatcher(this._diagnostics.exclude)
300-
: () => false
298+
if (diagnosticsOpt) {
299+
this._shouldIgnoreDiagnosticsForFile = this._diagnostics.exclude.length
300+
? globsToMatcher(this._diagnostics.exclude)
301+
: () => false
302+
} else {
303+
this._shouldIgnoreDiagnosticsForFile = () => true
304+
}
301305

302306
this.logger.debug({ diagnostics: this._diagnostics }, 'normalized diagnostics config via ts-jest option')
303307

0 commit comments

Comments
 (0)
Please sign in to comment.