test(ivy): driveDiagnostics() works incrementally (#33862)

PR Close #33862
This commit is contained in:
Alex Rickabaugh 2019-11-12 13:38:23 -08:00
parent 9e45203679
commit cf9aa4fd14
2 changed files with 40 additions and 4 deletions

View File

@ -56,14 +56,33 @@ export function main(
} }
export function mainDiagnosticsForTest( export function mainDiagnosticsForTest(
args: string[], config?: NgcParsedConfiguration): ReadonlyArray<ts.Diagnostic|api.Diagnostic> { args: string[], config?: NgcParsedConfiguration,
programReuse?: {program: api.Program | undefined},
modifiedResourceFiles?: Set<string>| null): ReadonlyArray<ts.Diagnostic|api.Diagnostic> {
let {project, rootNames, options, errors: configErrors, watch, emitFlags} = let {project, rootNames, options, errors: configErrors, watch, emitFlags} =
config || readNgcCommandLineAndConfiguration(args); config || readNgcCommandLineAndConfiguration(args);
if (configErrors.length) { if (configErrors.length) {
return configErrors; return configErrors;
} }
const {diagnostics: compileDiags} = performCompilation(
{rootNames, options, emitFlags, emitCallback: createEmitCallback(options)}); let oldProgram: api.Program|undefined;
if (programReuse !== undefined) {
oldProgram = programReuse.program;
}
const {diagnostics: compileDiags, program} = performCompilation({
rootNames,
options,
emitFlags,
oldProgram,
modifiedResourceFiles,
emitCallback: createEmitCallback(options),
});
if (programReuse !== undefined) {
programReuse.program = program;
}
return compileDiags; return compileDiags;
} }

View File

@ -54,6 +54,7 @@ export class NgtscTestEnvironment {
"experimentalDecorators": true, "experimentalDecorators": true,
"skipLibCheck": true, "skipLibCheck": true,
"noImplicitAny": true, "noImplicitAny": true,
"noEmitOnError": true,
"strictNullChecks": true, "strictNullChecks": true,
"outDir": "built", "outDir": "built",
"baseUrl": ".", "baseUrl": ".",
@ -199,7 +200,23 @@ export class NgtscTestEnvironment {
*/ */
driveDiagnostics(): ReadonlyArray<ts.Diagnostic> { driveDiagnostics(): ReadonlyArray<ts.Diagnostic> {
// ngtsc only produces ts.Diagnostic messages. // ngtsc only produces ts.Diagnostic messages.
return mainDiagnosticsForTest(['-p', this.basePath]) as ts.Diagnostic[]; let reuseProgram: {program: Program | undefined}|undefined = undefined;
if (this.multiCompileHostExt !== null) {
reuseProgram = {
program: this.oldProgram || undefined,
};
}
const diags = mainDiagnosticsForTest(
['-p', this.basePath], undefined, reuseProgram, this.changedResources);
if (this.multiCompileHostExt !== null) {
this.oldProgram = reuseProgram !.program !;
}
// In ngtsc, only `ts.Diagnostic`s are produced.
return diags as ReadonlyArray<ts.Diagnostic>;
} }
async driveDiagnosticsAsync(): Promise<ReadonlyArray<ts.Diagnostic>> { async driveDiagnosticsAsync(): Promise<ReadonlyArray<ts.Diagnostic>> {