-
Notifications
You must be signed in to change notification settings - Fork 25.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler-cli): speed up compiler tests by caching Angular (#…
…54650) Currently the `makeProgram` utility from `ngtsc/testing` does not use the test host by default- optimizing for source file caching. Additionally, the host can be updated to attempt caching of the `.d.ts` files from `@angular/core`— whether that's fake core, or the real core- is irrelevant. We are never caching if these changes between tests, so correctness is guaranteed. This commit reduces the type check test times form 80s to just 11 seconds, faster than what it was before with `fake_core`. The ngtsc tests also run significantly faster. From 40s to 30s PR Close #54650
- Loading branch information
1 parent
8a8b682
commit 2df8584
Showing
6 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/language-service/testing/src/language_service_test_cache.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {getCachedSourceFile} from '@angular/compiler-cli/src/ngtsc/testing'; | ||
import ts from 'typescript'; | ||
|
||
interface TsProjectWithInternals { | ||
// typescript/src/server/project.ts#ConfiguredProject | ||
setCompilerHost?(host: ts.CompilerHost): void; | ||
} | ||
|
||
let patchedLanguageServiceProjectHost = false; | ||
|
||
/** | ||
* Updates `ts.server.Project` to use efficient test caching of source files | ||
* that aren't expected to be changed. E.g. the default libs. | ||
*/ | ||
export function patchLanguageServiceProjectsWithTestHost() { | ||
if (patchedLanguageServiceProjectHost) { | ||
return; | ||
} | ||
patchedLanguageServiceProjectHost = true; | ||
|
||
(ts.server.Project.prototype as TsProjectWithInternals).setCompilerHost = (host) => { | ||
const _originalHostGetSourceFile = host.getSourceFile; | ||
const _originalHostGetSourceFileByPath = host.getSourceFileByPath; | ||
|
||
host.getSourceFile = | ||
(fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => { | ||
return getCachedSourceFile(fileName, () => host.readFile(fileName)) ?? | ||
_originalHostGetSourceFile.call( | ||
host, fileName, languageVersionOrOptions, onError, shouldCreateNewSourceFile); | ||
}; | ||
|
||
if (_originalHostGetSourceFileByPath !== undefined) { | ||
host.getSourceFileByPath = | ||
(fileName, path, languageVersionOrOptions, onError, shouldCreateNewSourceFile) => { | ||
return getCachedSourceFile(fileName, () => host.readFile(fileName)) ?? | ||
_originalHostGetSourceFileByPath.call( | ||
host, fileName, path, languageVersionOrOptions, onError, | ||
shouldCreateNewSourceFile); | ||
}; | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters