test(compiler-cli): fix the incremental ngc tests so that they run under bazel (#25275)
PR Close #25275
This commit is contained in:
parent
5653fada32
commit
ab32ac6bb7
@ -393,6 +393,9 @@ export class TsCompilerAotCompilerTypeCheckHostAdapter implements ts.CompilerHos
|
|||||||
getSourceFile(
|
getSourceFile(
|
||||||
fileName: string, languageVersion: ts.ScriptTarget,
|
fileName: string, languageVersion: ts.ScriptTarget,
|
||||||
onError?: ((message: string) => void)|undefined): ts.SourceFile {
|
onError?: ((message: string) => void)|undefined): ts.SourceFile {
|
||||||
|
if (fileName.endsWith('@angular/core/src/di/injection_token.d.ts')) {
|
||||||
|
debugger;
|
||||||
|
}
|
||||||
// Note: Don't exit early in this method to make sure
|
// Note: Don't exit early in this method to make sure
|
||||||
// we always have up to date references on the file!
|
// we always have up to date references on the file!
|
||||||
let genFileNames: string[] = [];
|
let genFileNames: string[] = [];
|
||||||
|
@ -59,7 +59,7 @@ describe('ng program', () => {
|
|||||||
|
|
||||||
function compile(
|
function compile(
|
||||||
oldProgram?: ng.Program, overrideOptions?: ng.CompilerOptions, rootNames?: string[],
|
oldProgram?: ng.Program, overrideOptions?: ng.CompilerOptions, rootNames?: string[],
|
||||||
host?: CompilerHost): {program: ng.Program, emitResult: ts.EmitResult} {
|
host?: CompilerHost): {program: ng.Program, emitResult: ts.EmitResult, host: ng.CompilerHost} {
|
||||||
const options = testSupport.createCompilerOptions(overrideOptions);
|
const options = testSupport.createCompilerOptions(overrideOptions);
|
||||||
if (!rootNames) {
|
if (!rootNames) {
|
||||||
rootNames = [path.resolve(testSupport.basePath, 'src/index.ts')];
|
rootNames = [path.resolve(testSupport.basePath, 'src/index.ts')];
|
||||||
@ -75,7 +75,30 @@ describe('ng program', () => {
|
|||||||
});
|
});
|
||||||
expectNoDiagnosticsInProgram(options, program);
|
expectNoDiagnosticsInProgram(options, program);
|
||||||
const emitResult = program.emit();
|
const emitResult = program.emit();
|
||||||
return {emitResult, program};
|
return {emitResult, program, host};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createWatchModeHost(): ng.CompilerHost {
|
||||||
|
const options = testSupport.createCompilerOptions();
|
||||||
|
const host = ng.createCompilerHost({options});
|
||||||
|
|
||||||
|
const originalGetSourceFile = host.getSourceFile;
|
||||||
|
const cache = new Map<string, ts.SourceFile>();
|
||||||
|
host.getSourceFile = function(fileName: string): ts.SourceFile {
|
||||||
|
if (fileName.endsWith('@angular/core/src/di/injection_token.d.ts')) {
|
||||||
|
debugger;
|
||||||
|
}
|
||||||
|
const sf = originalGetSourceFile.call(host, fileName) as ts.SourceFile;
|
||||||
|
if (sf && cache.has(sf.fileName)) {
|
||||||
|
const oldSf = cache.get(sf.fileName)!;
|
||||||
|
if (oldSf.getFullText() === sf.getFullText()) {
|
||||||
|
return oldSf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sf && cache.set(sf.fileName, sf);
|
||||||
|
return sf;
|
||||||
|
};
|
||||||
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveFiles(rootNames: string[]) {
|
function resolveFiles(rootNames: string[]) {
|
||||||
@ -267,18 +290,21 @@ describe('ng program', () => {
|
|||||||
.toBe(false);
|
.toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!isInBazel()) {
|
describe('reuse tests', () => {
|
||||||
it('should reuse the old ts program completely if nothing changed', () => {
|
it('should reuse the old ts program completely if nothing changed', () => {
|
||||||
testSupport.writeFiles({'src/index.ts': createModuleAndCompSource('main')});
|
testSupport.writeFiles({'src/index.ts': createModuleAndCompSource('main')});
|
||||||
|
const host = createWatchModeHost();
|
||||||
// Note: the second compile drops factories for library files,
|
// Note: the second compile drops factories for library files,
|
||||||
// and therefore changes the structure again
|
// and therefore changes the structure again
|
||||||
const p1 = compile().program;
|
const p1 = compile(undefined, undefined, undefined, host).program;
|
||||||
const p2 = compile(p1).program;
|
const p2 = compile(p1, undefined, undefined, host).program;
|
||||||
compile(p2);
|
debugger;
|
||||||
|
compile(p2, undefined, undefined, host);
|
||||||
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.Completely);
|
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.Completely);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reuse the old ts program completely if a template or a ts file changed', () => {
|
it('should reuse the old ts program completely if a template or a ts file changed', () => {
|
||||||
|
const host = createWatchModeHost();
|
||||||
testSupport.writeFiles({
|
testSupport.writeFiles({
|
||||||
'src/main.ts': createModuleAndCompSource('main', 'main.html'),
|
'src/main.ts': createModuleAndCompSource('main', 'main.html'),
|
||||||
'src/main.html': `Some template`,
|
'src/main.html': `Some template`,
|
||||||
@ -290,17 +316,18 @@ describe('ng program', () => {
|
|||||||
});
|
});
|
||||||
// Note: the second compile drops factories for library files,
|
// Note: the second compile drops factories for library files,
|
||||||
// and therefore changes the structure again
|
// and therefore changes the structure again
|
||||||
const p1 = compile().program;
|
const p1 = compile(undefined, undefined, undefined, host).program;
|
||||||
const p2 = compile(p1).program;
|
const p2 = compile(p1, undefined, undefined, host).program;
|
||||||
testSupport.writeFiles({
|
testSupport.writeFiles({
|
||||||
'src/main.html': `Another template`,
|
'src/main.html': `Another template`,
|
||||||
'src/util.ts': `export const x = 2`,
|
'src/util.ts': `export const x = 2`,
|
||||||
});
|
});
|
||||||
compile(p2);
|
compile(p2, undefined, undefined, host);
|
||||||
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.Completely);
|
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.Completely);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not reuse the old ts program if an import changed', () => {
|
it('should not reuse the old ts program if an import changed', () => {
|
||||||
|
const host = createWatchModeHost();
|
||||||
testSupport.writeFiles({
|
testSupport.writeFiles({
|
||||||
'src/main.ts': createModuleAndCompSource('main'),
|
'src/main.ts': createModuleAndCompSource('main'),
|
||||||
'src/util.ts': `export const x = 1`,
|
'src/util.ts': `export const x = 1`,
|
||||||
@ -311,14 +338,14 @@ describe('ng program', () => {
|
|||||||
});
|
});
|
||||||
// Note: the second compile drops factories for library files,
|
// Note: the second compile drops factories for library files,
|
||||||
// and therefore changes the structure again
|
// and therefore changes the structure again
|
||||||
const p1 = compile().program;
|
const p1 = compile(undefined, undefined, undefined, host).program;
|
||||||
const p2 = compile(p1).program;
|
const p2 = compile(p1, undefined, undefined, host).program;
|
||||||
testSupport.writeFiles(
|
testSupport.writeFiles(
|
||||||
{'src/util.ts': `import {Injectable} from '@angular/core'; export const x = 1;`});
|
{'src/util.ts': `import {Injectable} from '@angular/core'; export const x = 1;`});
|
||||||
compile(p2);
|
compile(p2, undefined, undefined, host);
|
||||||
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.SafeModules);
|
expect(tsStructureIsReused(p2.getTsProgram())).toBe(StructureIsReused.SafeModules);
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user