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

kulshekhar / ts-jest / 4897835899

pending completion
4897835899

push

github

GitHub
build(deps): Update dependency @commitlint/config-angular to ^17.6.3 (#4123)

937 of 1054 branches covered (88.9%)

Branch coverage included in aggregate %.

4055 of 4154 relevant lines covered (97.62%)

518.45 hits per line

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

95.35
/src/__helpers__/fakers.ts
1
import { resolve } from 'path'
3✔
2

3✔
3
import type { Config } from '@jest/types'
3✔
4
import type { Logger } from 'bs-logger'
3✔
5

3✔
6
import { TsCompiler } from '../legacy/compiler'
3✔
7
import { ConfigSet } from '../legacy/config/config-set'
3✔
8
import type { StringMap, TsJestGlobalOptions } from '../types'
3✔
9
import type { ImportReasons } from '../utils/messages'
3✔
10

3✔
11
export function filePath(relPath: string): string {
13✔
12
  return resolve(__dirname, '..', '..', relPath)
13✔
13
}
13✔
14

3✔
15
export const rootDir = filePath('')
3✔
16

3✔
17
const defaultTestRegex = ['(/__tests__/.*|(\\\\.|/)(test|spec))\\\\.[jt]sx?$']
3✔
18
const defaultTestMatch = ['**/__tests__/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[jt]s?(x)']
3✔
19

3✔
20
function getJestConfig<T extends Config.ProjectConfig>(
279✔
21
  options?: Partial<Config.InitialOptions | Config.ProjectConfig>,
279✔
22
  tsJestOptions?: TsJestGlobalOptions,
279✔
23
): T {
279✔
24
  const res = {
279✔
25
    globals: {},
279✔
26
    ...options,
279✔
27
  } as any // eslint-disable-line @typescript-eslint/no-explicit-any
279✔
28
  if (tsJestOptions) {
279✔
29
    res.globals['ts-jest'] = tsJestOptions
175✔
30
  }
175✔
31

279✔
32
  return res
279✔
33
}
279✔
34

3✔
35
export function importReason(text = '[[BECAUSE]]'): ImportReasons {
15✔
36
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
15✔
37
  return text as any
15✔
38
}
15✔
39

3✔
40
export const defaultResolve = (path: string): string => `resolved:${path}`
3✔
41

3✔
42
export function createConfigSet({
279✔
43
  jestConfig,
279✔
44
  tsJestConfig,
279✔
45
  logger, // don't change this key name, otherwise mock logging won't work
279✔
46
  resolve = defaultResolve,
279✔
47
  ...others
279✔
48
}: {
279✔
49
  jestConfig?: Partial<Config.ProjectConfig>
279✔
50
  tsJestConfig?: TsJestGlobalOptions
279✔
51
  logger?: Logger
279✔
52
  resolve?: ((path: string) => string) | null
279✔
53
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
279✔
54
  [key: string]: any
279✔
55
} = {}): ConfigSet {
279✔
56
  const jestCfg = getJestConfig(jestConfig, tsJestConfig)
279✔
57
  const cs = new ConfigSet(
279✔
58
    {
279✔
59
      ...jestCfg,
279✔
60
      testMatch: jestConfig?.testMatch ? [...jestConfig.testMatch, ...defaultTestMatch] : defaultTestMatch,
279✔
61
      testRegex: jestConfig?.testRegex ? [...jestConfig.testRegex, ...defaultTestRegex] : defaultTestRegex,
279✔
62
      extensionsToTreatAsEsm: jestCfg.extensionsToTreatAsEsm ?? [],
279✔
63
    },
279✔
64
    logger,
279✔
65
  )
279✔
66
  if (resolve) {
279✔
67
    cs.resolvePath = resolve
160✔
68
  }
160✔
69
  Object.keys(others).forEach((key) => {
276✔
70
    Object.defineProperty(cs, key, { value: others[key] })
56✔
71
  })
276✔
72

276✔
73
  return cs
276✔
74
}
276✔
75

3✔
76
// not really unit-testing here, but it's hard to mock all those values :-D
3✔
77
export function makeCompiler(
64✔
78
  {
64✔
79
    jestConfig,
64✔
80
    tsJestConfig,
64✔
81
    parentConfig,
64✔
82
  }: {
64✔
83
    jestConfig?: Partial<Config.ProjectConfig>
64✔
84
    tsJestConfig?: TsJestGlobalOptions
64✔
85
    parentConfig?: TsJestGlobalOptions
64✔
86
  } = {},
64✔
87
  jestCacheFS: StringMap = new Map<string, string>(),
64✔
88
): TsCompiler {
64✔
89
  tsJestConfig = { ...tsJestConfig }
64✔
90
  tsJestConfig.diagnostics = {
64✔
91
    // eslint-disable-next-line @typescript-eslint/no-explicit-any
64✔
92
    ...(tsJestConfig.diagnostics as any),
64✔
93
    pretty: false,
64✔
94
  }
64✔
95
  jestConfig = {
64✔
96
    ...jestConfig,
64✔
97
    extensionsToTreatAsEsm: jestConfig?.extensionsToTreatAsEsm ?? [],
64!
98
    testMatch: jestConfig?.testMatch ? [...jestConfig.testMatch, ...defaultTestMatch] : defaultTestMatch,
64!
99
    testRegex: jestConfig?.testRegex ? [...jestConfig.testRegex, ...defaultTestRegex] : defaultTestRegex,
64!
100
  }
64✔
101
  const cs = createConfigSet({ jestConfig, tsJestConfig, parentConfig, resolve: null })
64✔
102

64✔
103
  return new TsCompiler(cs, jestCacheFS)
64✔
104
}
64✔
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