feat(ivy): implement listLazyRoutes() for ngtsc (#27697)
This commit uses the NgModuleRouteAnalyzer introduced previously to implement listLazyRoutes() for NgtscProgram. Currently this implementation is limited to listing routes globally and cannot list routes for a given lazy module. Testing seems to indicate that the CLI uses the global form, but this should be verified. Jira issue: FW-629 PR Close #27697
This commit is contained in:
@ -1949,6 +1949,45 @@ describe('ngtsc behavioral tests', () => {
|
||||
expect(trim(jsContents)).toContain(trim(hostBindingsFn));
|
||||
});
|
||||
});
|
||||
|
||||
it('should detect all lazy routes', () => {
|
||||
env.tsconfig();
|
||||
env.write('test.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
import {RouterModule} from '@angular/router';
|
||||
|
||||
@NgModule({
|
||||
imports: [
|
||||
RouterModule.forChild([
|
||||
{path: '', loadChildren: './lazy#LazyModule'},
|
||||
]),
|
||||
],
|
||||
})
|
||||
export class TestModule {}
|
||||
`);
|
||||
env.write('lazy.ts', `
|
||||
import {NgModule} from '@angular/core';
|
||||
import {RouterModule} from '@angular/router';
|
||||
|
||||
@NgModule({})
|
||||
export class LazyModule {}
|
||||
`);
|
||||
env.write('node_modules/@angular/router/index.d.ts', `
|
||||
import {ModuleWithProviders} from '@angular/core';
|
||||
|
||||
export declare var ROUTES;
|
||||
export declare class RouterModule {
|
||||
static forRoot(arg1: any, arg2: any): ModuleWithProviders<RouterModule>;
|
||||
static forChild(arg1: any): ModuleWithProviders<RouterModule>;
|
||||
}
|
||||
`);
|
||||
|
||||
const routes = env.driveRoutes();
|
||||
expect(routes.length).toBe(1);
|
||||
expect(routes[0].route).toEqual('./lazy#LazyModule');
|
||||
expect(routes[0].module.filePath.endsWith('/test.ts')).toBe(true);
|
||||
expect(routes[0].referencedModule.filePath.endsWith('/lazy.ts')).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
function expectTokenAtPosition<T extends ts.Node>(
|
||||
|
Reference in New Issue
Block a user