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

kulshekhar / ts-jest / 12924273039

23 Jan 2025 07:25AM UTC coverage: 95.265%. Remained the same
12924273039

push

github

ahnpnl
build(deps): Update dependency @types/node to v20.17.15

774 of 871 branches covered (88.86%)

Branch coverage included in aggregate %.

4759 of 4937 relevant lines covered (96.39%)

1419.15 hits per line

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

86.63
/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,
346✔
13
  config: T,
346✔
14
): T => {
346✔
15
  logger.debug({ ...context, config }, 'backporting config')
346✔
16

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

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

346✔
43
  if ('__TRANSFORM_HTML__' in globals) {
346✔
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

346✔
51
  if ('typeCheck' in tsJest) {
346!
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

346✔
57
  if ('tsConfigFile' in tsJest) {
346!
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

346✔
65
  if ('tsConfig' in tsJest) {
346!
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

346✔
73
  if ('enableTsDiagnostics' in tsJest) {
346!
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

346✔
84
  if ('useBabelrc' in tsJest) {
346!
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

346✔
92
  if ('skipBabel' in tsJest) {
346!
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

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

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