Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// Use full language services when the fast option is disabled.
if (!configs.tsJest.isolatedModules) {
// Set the file contents into cache.
const updateMemoryCache = (code: string, fileName: string) => {
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`.
it('should use the cache', () => {
const compiled1 = compiler.compile(source, __filename)
expect(logTarget.filteredLines(LogLevels.debug, Infinity)).toMatchInlineSnapshot(`
Array [
"[level:20] readThrough(): cache miss
",
"[level:20] getOutput(): compiling using language service
",
"[level:20] updateMemoryCache()
",
"[level:20] visitSourceFileNode(): hoisting
",
"[level:20] getOutput(): computing diagnostics
",
"[level:20] readThrough(): writing caches
",
]
`)
return (ctx: TransformationContext): Transformer => {
return logger.wrap(
{ [LogContexts.logLevel]: LogLevels.debug, call: null },
'visitSourceFileNode(): hoisting',
(sf: SourceFile) => ts.visitNode(sf, createVisitor(ctx, sf)),
)
}
}