Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(config): don't show diagnostics warning with diagnostics: false #3647

Merged
merged 1 commit into from Jun 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/diagnostics/__tests__/diagnostics.spec.ts
@@ -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
@@ -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
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
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