Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logger.debug({ fileName }, `updateMemoryCache()`)
if (memoryCache.contents[fileName] !== code) {
memoryCache.contents[fileName] = code
memoryCache.versions[fileName] = (memoryCache.versions[fileName] || 0) + 1
}
}
// Create the compiler host for type checking.
const serviceHostDebugCtx = {
[LogContexts.logLevel]: LogLevels.debug,
namespace: 'ts:serviceHost',
call: null,
}
const serviceHostTraceCtx = {
...serviceHostDebugCtx,
[LogContexts.logLevel]: LogLevels.trace,
}
const serviceHost = {
getScriptFileNames: () => Object.keys(memoryCache.versions),
getScriptVersion: (fileName: string) => {
const normalizedFileName = normalize(fileName)
const version = memoryCache.versions[normalizedFileName]
// We need to return `undefined` and not a string here because TypeScript will use
// `getScriptVersion` and compare against their own version - which can be `undefined`.
// If we don't return `undefined` it results in `undefined === "undefined"` and run
// `createProgram` again (which is very slow). Using a `string` assertion here to avoid
// TypeScript errors from the function signature (expects `(x: string) => string`).
return version === undefined ? ((undefined as any) as string) : String(version)
},
getScriptSnapshot(fileName: string) {
const buildOptions = () => ({
context: {
[LogContexts.package]: 'ts-jest',
[LogContexts.logLevel]: LogLevels.trace,
version: require('../../package.json').version,
},
targets: process.env.TS_JEST_LOG || undefined,
})