• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kulshekhar / ts-jest / 9804725795

05 Jul 2024 07:30AM UTC coverage: 96.474%. Remained the same
9804725795

push

github

ahnpnl
build(deps): Update dependency eslint-plugin-jsdoc to ^48.5.1

788 of 885 branches covered (89.04%)

Branch coverage included in aggregate %.

4712 of 4816 relevant lines covered (97.84%)

1248.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.21
/src/utils/backports.ts
1
import type { Config } from '@jest/types'
6✔
2
import { LogContexts, Logger } from 'bs-logger'
6✔
3

6✔
4
import { Deprecations, Helps, interpolate } from './messages'
6✔
5

6✔
6
const context = { [LogContexts.namespace]: 'backports' }
6✔
7

6✔
8
/**
6✔
9
 * @internal
6✔
10
 */
6✔
11
export const backportJestConfig = <T extends Config.InitialOptions | Config.ProjectConfig>(
6✔
12
  logger: Logger,
353✔
13
  config: T,
353✔
14
): T => {
353✔
15
  logger.debug({ ...context, config }, 'backporting config')
353✔
16

353✔
17
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
353✔
18
  const { globals = {} } = (config || {}) as any
353!
19
  const { 'ts-jest': tsJest = {} } = globals
353✔
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
353✔
21
  const mergeTsJest: any = {}
353✔
22
  let hadWarnings = false
353✔
23
  const warnConfig = (oldPath: string, newPath: string, note?: string) => {
353✔
24
    hadWarnings = true
186✔
25
    logger.warn(
186✔
26
      context,
186✔
27
      interpolate(note ? Deprecations.ConfigOptionWithNote : Deprecations.ConfigOption, {
186✔
28
        oldPath,
186✔
29
        newPath,
186✔
30
        note,
186✔
31
      }),
186✔
32
    )
186✔
33
  }
186✔
34

353✔
35
  if ('__TS_CONFIG__' in globals) {
353✔
36
    warnConfig('globals.__TS_CONFIG__', 'globals.ts-jest.tsconfig')
22✔
37
    if (typeof globals.__TS_CONFIG__ === 'object') {
22✔
38
      mergeTsJest.tsconfig = globals.__TS_CONFIG__
22✔
39
    }
22✔
40
    delete globals.__TS_CONFIG__
22✔
41
  }
22✔
42

353✔
43
  if ('__TRANSFORM_HTML__' in globals) {
353✔
44
    warnConfig('globals.__TRANSFORM_HTML__', 'globals.ts-jest.stringifyContentPathRegex')
8✔
45
    if (globals.__TRANSFORM_HTML__) {
8✔
46
      mergeTsJest.stringifyContentPathRegex = '\\.html?$'
4✔
47
    }
4✔
48
    delete globals.__TRANSFORM_HTML__
8✔
49
  }
8✔
50

353✔
51
  if ('typeCheck' in tsJest) {
353!
52
    warnConfig('globals.ts-jest.typeCheck', 'globals.ts-jest.isolatedModules')
8✔
53
    mergeTsJest.isolatedModules = !tsJest.typeCheck
8✔
54
    delete tsJest.typeCheck
8✔
55
  }
8✔
56

353✔
57
  if ('tsConfigFile' in tsJest) {
353!
58
    warnConfig('globals.ts-jest.tsConfigFile', 'globals.ts-jest.tsconfig')
4✔
59
    if (tsJest.tsConfigFile) {
4✔
60
      mergeTsJest.tsconfig = tsJest.tsConfigFile
4✔
61
    }
4✔
62
    delete tsJest.tsConfigFile
4✔
63
  }
4✔
64

353✔
65
  if ('tsConfig' in tsJest) {
353!
66
    warnConfig('globals.ts-jest.tsConfig', 'globals.ts-jest.tsconfig')
4✔
67
    if (tsJest.tsConfig) {
4✔
68
      mergeTsJest.tsconfig = tsJest.tsConfig
4✔
69
    }
4✔
70
    delete tsJest.tsConfig
4✔
71
  }
4✔
72

353✔
73
  if ('enableTsDiagnostics' in tsJest) {
353!
74
    warnConfig('globals.ts-jest.enableTsDiagnostics', 'globals.ts-jest.diagnostics')
12✔
75
    if (tsJest.enableTsDiagnostics) {
12✔
76
      mergeTsJest.diagnostics = { warnOnly: true }
8✔
77
      if (typeof tsJest.enableTsDiagnostics === 'string') mergeTsJest.diagnostics.exclude = [tsJest.enableTsDiagnostics]
8✔
78
    } else {
12✔
79
      mergeTsJest.diagnostics = false
4✔
80
    }
4✔
81
    delete tsJest.enableTsDiagnostics
12✔
82
  }
12✔
83

353✔
84
  if ('useBabelrc' in tsJest) {
353!
85
    warnConfig('globals.ts-jest.useBabelrc', 'globals.ts-jest.babelConfig', Deprecations.ConfigOptionUseBabelRcNote)
8✔
86
    if (tsJest.useBabelrc != null) {
8✔
87
      mergeTsJest.babelConfig = tsJest.useBabelrc ? true : {}
8✔
88
    }
8✔
89
    delete tsJest.useBabelrc
8✔
90
  }
8✔
91

353✔
92
  if ('skipBabel' in tsJest) {
353!
93
    warnConfig('globals.ts-jest.skipBabel', 'globals.ts-jest.babelConfig')
8✔
94
    if (tsJest.skipBabel === false && !mergeTsJest.babelConfig) {
8✔
95
      mergeTsJest.babelConfig = true
4✔
96
    }
4✔
97
    delete tsJest.skipBabel
8✔
98
  }
8✔
99

353✔
100
  // if we had some warnings we can inform the user about the CLI tool
353✔
101
  if (hadWarnings) {
353✔
102
    logger.warn(context, Helps.MigrateConfigUsingCLI)
74✔
103
  }
74✔
104

353✔
105
  return {
353✔
106
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
353✔
107
    ...(config as any),
353✔
108
    globals: {
353✔
109
      ...globals,
353✔
110
      'ts-jest': {
353✔
111
        ...mergeTsJest,
353✔
112
        ...tsJest,
353✔
113
      },
353✔
114
    },
353✔
115
  }
353✔
116
}
353✔
117

6✔
118
/**
6✔
119
 * @internal
6✔
120
 */
6✔
121
export const backportTsJestDebugEnvVar = (logger: Logger): void => {
6✔
122
  if ('TS_JEST_DEBUG' in process.env) {
6!
123
    const shouldLog = !/^\s*(?:0|f(?:alse)?|no?|disabled?|off|)\s*$/i.test(process.env.TS_JEST_DEBUG || '')
×
124
    delete process.env.TS_JEST_DEBUG
×
125
    if (shouldLog) {
×
126
      process.env.TS_JEST_LOG = 'ts-jest.log,stderr:warn'
×
127
    }
×
128
    logger.warn(
×
129
      context,
×
130
      interpolate(Deprecations.EnvVar, {
×
131
        old: 'TS_JEST_DEBUG',
×
132
        new: 'TS_JEST_LOG',
×
133
      }),
×
134
    )
×
135
  }
×
136
}
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc