From a7e4db3344e41643a1b73c8309011cbf09ea4c44 Mon Sep 17 00:00:00 2001 From: JoostK Date: Thu, 3 Dec 2020 20:43:53 +0100 Subject: [PATCH] test(compiler-cli): improve compliance test performance (#39956) The newly built compliance test runner was not using the shared source file cache that was added in b627f7f02e714f68a2f6ab0724597ad6107db3ce, which offers a significant performance boost to the compliance test targets. PR Close #39956 --- .../compiler-cli/src/ngtsc/testing/index.ts | 1 + .../src/ngtsc/testing/src/compiler_host.ts | 25 +++++++++++++++++++ .../compliance/test_helpers/compile_test.ts | 6 ++--- packages/compiler-cli/test/ngtsc/env.ts | 14 ++--------- 4 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 packages/compiler-cli/src/ngtsc/testing/src/compiler_host.ts diff --git a/packages/compiler-cli/src/ngtsc/testing/index.ts b/packages/compiler-cli/src/ngtsc/testing/index.ts index fac534ec1d..fdb53352de 100644 --- a/packages/compiler-cli/src/ngtsc/testing/index.ts +++ b/packages/compiler-cli/src/ngtsc/testing/index.ts @@ -7,5 +7,6 @@ */ export * from './src/utils'; export * from './src/cached_source_files'; +export * from './src/compiler_host'; export * from './src/mock_file_loading'; export * from './src/runfile_helpers'; diff --git a/packages/compiler-cli/src/ngtsc/testing/src/compiler_host.ts b/packages/compiler-cli/src/ngtsc/testing/src/compiler_host.ts new file mode 100644 index 0000000000..83ca99ee1b --- /dev/null +++ b/packages/compiler-cli/src/ngtsc/testing/src/compiler_host.ts @@ -0,0 +1,25 @@ +/** + * @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 * as ts from 'typescript'; +import {NgtscCompilerHost} from '../../file_system'; +import {getCachedSourceFile} from './cached_source_files'; + +/** + * A compiler host intended to improve test performance by caching default library source files for + * reuse across tests. + */ +export class NgtscTestCompilerHost extends NgtscCompilerHost { + getSourceFile(fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile|undefined { + const cachedSf = getCachedSourceFile(fileName, () => this.readFile(fileName)); + if (cachedSf !== null) { + return cachedSf; + } + return super.getSourceFile(fileName, languageVersion); + } +} diff --git a/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts b/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts index 2716dbcf99..e8a04a4156 100644 --- a/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts +++ b/packages/compiler-cli/test/compliance/test_helpers/compile_test.ts @@ -7,9 +7,9 @@ */ import * as ts from 'typescript'; -import {AbsoluteFsPath, FileSystem, NgtscCompilerHost} from '../../../src/ngtsc/file_system'; +import {AbsoluteFsPath, FileSystem} from '../../../src/ngtsc/file_system'; import {initMockFileSystem} from '../../../src/ngtsc/file_system/testing'; -import {loadStandardTestFiles, loadTestDirectory} from '../../../src/ngtsc/testing'; +import {loadStandardTestFiles, loadTestDirectory, NgtscTestCompilerHost} from '../../../src/ngtsc/testing'; import {Diagnostics, performCompilation} from '../../../src/perform_compile'; import {CompilerOptions} from '../../../src/transformers/api'; @@ -52,7 +52,7 @@ export function compileTest( const outDir = getBuildOutputDirectory(fs); const options = getOptions(rootDir, outDir, compilerOptions, angularCompilerOptions); const rootNames = files.map(f => fs.resolve(f)); - const host = new NgtscCompilerHost(fs, options); + const host = new NgtscTestCompilerHost(fs, options); const {diagnostics, emitResult} = performCompilation({rootNames, host, options}); const emittedFiles = emitResult ? emitResult.emittedFiles!.map(p => fs.resolve(rootDir, p)) : []; const errors = parseDiagnostics(diagnostics); diff --git a/packages/compiler-cli/test/ngtsc/env.ts b/packages/compiler-cli/test/ngtsc/env.ts index a57eefb0f8..0c910065af 100644 --- a/packages/compiler-cli/test/ngtsc/env.ts +++ b/packages/compiler-cli/test/ngtsc/env.ts @@ -12,13 +12,13 @@ import * as ts from 'typescript'; import {createCompilerHost, createProgram} from '../../index'; import {main, mainDiagnosticsForTest, readNgcCommandLineAndConfiguration} from '../../src/main'; -import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, NgtscCompilerHost, relativeFrom} from '../../src/ngtsc/file_system'; +import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem, relativeFrom} from '../../src/ngtsc/file_system'; import {Folder, MockFileSystem} from '../../src/ngtsc/file_system/testing'; import {IndexedComponent} from '../../src/ngtsc/indexer'; import {NgtscProgram} from '../../src/ngtsc/program'; import {DeclarationNode} from '../../src/ngtsc/reflection'; import {LazyRoute} from '../../src/ngtsc/routing'; -import {getCachedSourceFile} from '../../src/ngtsc/testing'; +import {NgtscTestCompilerHost} from '../../src/ngtsc/testing'; import {setWrapHostForTest} from '../../src/transformers/compiler_host'; @@ -268,16 +268,6 @@ export class NgtscTestEnvironment { } } -class NgtscTestCompilerHost extends NgtscCompilerHost { - getSourceFile(fileName: string, languageVersion: ts.ScriptTarget): ts.SourceFile|undefined { - const cachedSf = getCachedSourceFile(fileName, () => this.readFile(fileName)); - if (cachedSf !== null) { - return cachedSf; - } - return super.getSourceFile(fileName, languageVersion); - } -} - class AugmentedCompilerHost extends NgtscTestCompilerHost { delegate!: ts.CompilerHost; }