test(compiler-cli): add integration test for relative rootDir (#41359)
this will make it easier to detect regressions of the relative rootDir behavior PR Close #41359
This commit is contained in:
parent
3e0fda96b8
commit
42e3a5241d
|
@ -30,6 +30,7 @@ export class NgtscTestEnvironment {
|
|||
private multiCompileHostExt: MultiCompileHostExt|null = null;
|
||||
private oldProgram: Program|null = null;
|
||||
private changedResources: Set<string>|null = null;
|
||||
private commandLineArgs = ['-p', this.basePath];
|
||||
|
||||
private constructor(
|
||||
private fs: FileSystem, readonly outDir: AbsoluteFsPath, readonly basePath: AbsoluteFsPath) {}
|
||||
|
@ -114,6 +115,10 @@ export class NgtscTestEnvironment {
|
|||
setWrapHostForTest(makeWrapHost(new ResourceLoadingCompileHost(this.fs)));
|
||||
}
|
||||
|
||||
addCommandLineArgs(...args: string[]): void {
|
||||
this.commandLineArgs.push(...args);
|
||||
}
|
||||
|
||||
flushWrittenFileTracking(): void {
|
||||
if (this.multiCompileHostExt === null) {
|
||||
throw new Error(`Not tracking written files - call enableMultipleCompilations()`);
|
||||
|
@ -214,7 +219,7 @@ export class NgtscTestEnvironment {
|
|||
};
|
||||
}
|
||||
const exitCode = main(
|
||||
['-p', this.basePath], errorSpy, undefined, customTransformers, reuseProgram,
|
||||
this.commandLineArgs, errorSpy, undefined, customTransformers, reuseProgram,
|
||||
this.changedResources);
|
||||
expect(errorSpy).not.toHaveBeenCalled();
|
||||
expect(exitCode).toBe(0);
|
||||
|
@ -236,7 +241,7 @@ export class NgtscTestEnvironment {
|
|||
}
|
||||
|
||||
const diags = mainDiagnosticsForTest(
|
||||
['-p', this.basePath], undefined, reuseProgram, this.changedResources);
|
||||
this.commandLineArgs, undefined, reuseProgram, this.changedResources);
|
||||
|
||||
|
||||
if (this.multiCompileHostExt !== null) {
|
||||
|
@ -248,7 +253,7 @@ export class NgtscTestEnvironment {
|
|||
}
|
||||
|
||||
async driveDiagnosticsAsync(): Promise<ReadonlyArray<ts.Diagnostic>> {
|
||||
const {rootNames, options} = readNgcCommandLineAndConfiguration(['-p', this.basePath]);
|
||||
const {rootNames, options} = readNgcCommandLineAndConfiguration(this.commandLineArgs);
|
||||
const host = createCompilerHost({options});
|
||||
const program = createProgram({rootNames, host, options});
|
||||
await program.loadNgStructureAsync();
|
||||
|
@ -258,14 +263,14 @@ export class NgtscTestEnvironment {
|
|||
}
|
||||
|
||||
driveRoutes(entryPoint?: string): LazyRoute[] {
|
||||
const {rootNames, options} = readNgcCommandLineAndConfiguration(['-p', this.basePath]);
|
||||
const {rootNames, options} = readNgcCommandLineAndConfiguration(this.commandLineArgs);
|
||||
const host = createCompilerHost({options});
|
||||
const program = createProgram({rootNames, host, options});
|
||||
return program.listLazyRoutes(entryPoint);
|
||||
}
|
||||
|
||||
driveIndexer(): Map<DeclarationNode, IndexedComponent> {
|
||||
const {rootNames, options} = readNgcCommandLineAndConfiguration(['-p', this.basePath]);
|
||||
const {rootNames, options} = readNgcCommandLineAndConfiguration(this.commandLineArgs);
|
||||
const host = createCompilerHost({options});
|
||||
const program = createProgram({rootNames, host, options});
|
||||
return (program as NgtscProgram).getIndexedComponents();
|
||||
|
|
|
@ -54,6 +54,25 @@ function allTests(os: string) {
|
|||
env.tsconfig();
|
||||
});
|
||||
|
||||
it('should accept relative file paths as command line argument', () => {
|
||||
env.addCommandLineArgs('--rootDir', './rootDir');
|
||||
env.write('rootDir/test.html', '<p>Hello World</p>');
|
||||
env.write('rootDir/test.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'test-cmp',
|
||||
templateUrl: 'test.html',
|
||||
})
|
||||
export class TestCmp {}
|
||||
`);
|
||||
|
||||
env.driveMain();
|
||||
|
||||
const jsContents = env.getContents('test.js');
|
||||
expect(jsContents).toContain('Hello World');
|
||||
});
|
||||
|
||||
it('should compile Injectables without errors', () => {
|
||||
env.write('test.ts', `
|
||||
import {Injectable} from '@angular/core';
|
||||
|
|
Loading…
Reference in New Issue