Skip to content

Commit 07dbf7a

Browse files
committed
test(router): cover @app alias spread resolution
closes #654
1 parent e509952 commit 07dbf7a

4 files changed

Lines changed: 47 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Route } from "@angular/router";
2+
3+
export const appsRoutes: Route[] = [
4+
{ path: "apps", component: "AppsComponent" as any },
5+
];
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Routes } from "@angular/router";
2+
import { appsRoutes } from "@app/stage/apps/apps-routing.module";
3+
4+
export const routes: Routes = [...appsRoutes];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": "src",
4+
"paths": {
5+
"@app/*": ["app/*"]
6+
}
7+
}
8+
}

‎test/src/utils/router-parser.util.spec.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,10 @@ const routes = [
501501
__dirname,
502502
"../../../../../test/fixtures/baseurl-spread",
503503
);
504+
const appAliasFixtureRoot = path.join(
505+
__dirname,
506+
"../../../../../test/fixtures/path-alias-app-spread",
507+
);
504508
const relativeFixtureRoot = path.join(
505509
__dirname,
506510
"../../../../../test/fixtures/relative-spread-import",
@@ -639,5 +643,31 @@ export const routes: Routes = [{ path: 'root', children: [...langs.map(lang => (
639643
routerParser.scannedFiles = previousScannedFiles;
640644
}
641645
});
646+
647+
it("should resolve @app/* path aliases from tsconfig.paths in nested routes (issue #654)", () => {
648+
const previousScannedFiles = routerParser.scannedFiles;
649+
try {
650+
routerParser.scannedFiles = [];
651+
Configuration.mainData.tsconfig = path.join(
652+
appAliasFixtureRoot,
653+
"tsconfig.json",
654+
);
655+
656+
const project = new Project();
657+
const sourceFile = project.addSourceFileAtPath(
658+
path.join(
659+
appAliasFixtureRoot,
660+
"src/app/stage/stage-routing.module.ts",
661+
),
662+
);
663+
expect(() =>
664+
routerParser.cleanFileSpreads(sourceFile),
665+
).not.to.throw();
666+
expect(sourceFile.getText()).not.to.contain("...appsRoutes");
667+
expect(sourceFile.getText()).to.contain('path: "apps"');
668+
} finally {
669+
routerParser.scannedFiles = previousScannedFiles;
670+
}
671+
});
642672
});
643673
});

0 commit comments

Comments
 (0)