Skip to content

Commit

Permalink
fix(config): don't show diagnostics warning with diagnostics: false (
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnpnl authored Jun 19, 2022
1 parent 58cdc7d commit 9a9bc02
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
2 changes: 1 addition & 1 deletion e2e/diagnostics/__tests__/diagnostics.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Thing } from '../foo'
import type { Thing } from '../foo'

const thing: Thing = { a: 1 }

Expand Down
7 changes: 3 additions & 4 deletions e2e/utils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -12,7 +11,7 @@ interface RunResult extends ExecaReturnValue {
status: number
error: Error
}
export const run = (cmd: string, cwd?: Config.Path, env?: Record<string, string>): RunResult => {
export const run = (cmd: string, cwd?: string, env?: Record<string, string>): 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
Expand All @@ -34,7 +33,7 @@ export const run = (cmd: string, cwd?: Config.Path, env?: Record<string, string>
return result
}

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

Expand Down
12 changes: 12 additions & 0 deletions src/legacy/config/config-set.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
10 changes: 7 additions & 3 deletions src/legacy/config/config-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 9a9bc02

Please sign in to comment.