Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit c2b8011

Browse files
committed
test(deep-linking): convert paths to use paths api so tests run on windows
1 parent 0999f23 commit c2b8011

File tree

1 file changed

+38
-38
lines changed

1 file changed

+38
-38
lines changed

src/deep-linking/util.spec.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as tsUtils from '../util/typescript-utils';
1212
describe('util', () => {
1313
describe('filterTypescriptFilesForDeepLinks', () => {
1414
it('should return a list of files that are in the directory specified for deeplinking', () => {
15-
const pagesDir = join('Users', 'noone', 'myApp', 'src', 'pages');
15+
const pagesDir = join(process.cwd(), 'myApp', 'src', 'pages');
1616

1717
const knownFileContent = 'Some string';
1818
const pageOneTs = join(pagesDir, 'page-one', 'page-one.ts');
@@ -96,7 +96,7 @@ export class HomePage {
9696
9797
`;
9898

99-
const knownPath = '/some/fake/path';
99+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
100100

101101
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
102102

@@ -154,7 +154,7 @@ export class HomePage {
154154
155155
`;
156156

157-
const knownPath = '/some/fake/path';
157+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
158158

159159
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
160160

@@ -211,7 +211,7 @@ export class HomePage {
211211
212212
`;
213213

214-
const knownPath = '/some/fake/path';
214+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
215215

216216
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
217217

@@ -267,7 +267,7 @@ export class HomePage {
267267
268268
`;
269269

270-
const knownPath = '/some/fake/path';
270+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
271271

272272
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
273273

@@ -322,7 +322,7 @@ export class HomePage {
322322
323323
`;
324324

325-
const knownPath = '/some/fake/path';
325+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
326326

327327
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
328328

@@ -376,7 +376,7 @@ export class HomePage {
376376
377377
`;
378378

379-
const knownPath = '/some/fake/path';
379+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
380380

381381
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
382382

@@ -434,7 +434,7 @@ export class HomePage {
434434
435435
`;
436436

437-
const knownPath = '/some/fake/path';
437+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
438438

439439
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
440440
const knownErrorMsg = 'Should never get here';
@@ -487,7 +487,7 @@ export class HomePage {
487487
488488
`;
489489

490-
const knownPath = '/some/fake/path';
490+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
491491

492492
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
493493
const result = util.getDeepLinkDecoratorContentForSourceFile(sourceFile);
@@ -530,7 +530,7 @@ export function removeDecorators(fileName: string, source: string): string {
530530
531531
`;
532532

533-
const knownPath = '/some/fake/path';
533+
const knownPath = join(process.cwd(), 'some', 'fake', 'path');
534534

535535
const sourceFile = tsUtils.getTypescriptSourceFile(knownPath, knownContent);
536536
const result = util.getDeepLinkDecoratorContentForSourceFile(sourceFile);
@@ -540,7 +540,7 @@ export function removeDecorators(fileName: string, source: string): string {
540540

541541
describe('getNgModuleDataFromCorrespondingPage', () => {
542542
it('should call the file cache with the path to an ngmodule', () => {
543-
const basePath = join('Some', 'Fake', 'Path');
543+
const basePath = join(process.cwd(), 'some', 'fake', 'path');
544544
const pagePath = join(basePath, 'my-page', 'my-page.ts');
545545
const ngModulePath = join(basePath, 'my-page', 'my-page.module.ts');
546546

@@ -552,7 +552,7 @@ export function removeDecorators(fileName: string, source: string): string {
552552
});
553553

554554
describe('getRelativePathToPageNgModuleFromAppNgModule', () => {
555-
const prefix = join('Users', 'noone', 'myApp', 'src');
555+
const prefix = join(process.cwd(), 'myApp', 'src');
556556
const appNgModulePath = join(prefix, 'app', 'app.module.ts');
557557
const pageNgModulePath = join(prefix, 'pages', 'page-one', 'page-one.module.ts');
558558
const result = util.getRelativePathToPageNgModuleFromAppNgModule(appNgModulePath, pageNgModulePath);
@@ -561,7 +561,7 @@ export function removeDecorators(fileName: string, source: string): string {
561561

562562
describe('getNgModuleDataFromPage', () => {
563563
it('should throw when NgModule is not in cache and create default ngModule flag is off', () => {
564-
const prefix = join('Users', 'noone', 'myApp', 'src');
564+
const prefix = join(process.cwd(), 'myApp', 'src');
565565
const appNgModulePath = join(prefix, 'app', 'app.module.ts');
566566
const pagePath = join(prefix, 'pages', 'page-one', 'page-one.ts');
567567
const knownClassName = 'PageOne';
@@ -594,7 +594,7 @@ import { HomePage } from './home';
594594
})
595595
export class HomePageModule {}
596596
`;
597-
const prefix = join('Users', 'noone', 'myApp', 'src');
597+
const prefix = join(process.cwd(), 'myApp', 'src');
598598
const appNgModulePath = join(prefix, 'app', 'app.module.ts');
599599
const pageNgModulePath = join(prefix, 'pages', 'page-one', 'page-one.module.ts');
600600
const pagePath = join(prefix, 'pages', 'page-one', 'page-one.ts');
@@ -627,7 +627,7 @@ import { HomePage } from './home';
627627
})
628628
export class HomePageModule {}
629629
`;
630-
const prefix = join('Users', 'noone', 'myApp', 'src');
630+
const prefix = join(process.cwd(), 'myApp', 'src');
631631
const appNgModulePath = join(prefix, 'app', 'app.module.ts');
632632
const pageNgModulePath = join(prefix, 'pages', 'page-one', 'page-one.module.ts');
633633
const pagePath = join(prefix, 'pages', 'page-one', 'page-one.ts');
@@ -802,7 +802,7 @@ export class PageThreeModule {
802802
803803
`;
804804

805-
const prefix = join('Users', 'noone', 'myApp', 'src');
805+
const prefix = join(process.cwd(), 'myApp', 'src');
806806
const appNgModulePath = join(prefix, 'app', 'app.module.ts');
807807
const pageOneNgModulePath = join(prefix, 'pages', 'page-one', 'page-one.module.ts');
808808
const pageOnePath = join(prefix, 'pages', 'page-one', 'page-one.ts');
@@ -988,7 +988,7 @@ export class PageThreeModule {
988988
989989
`;
990990

991-
const srcDir = join('Users', 'noone', 'myApp', 'src');
991+
const srcDir = join(process.cwd(), 'myApp', 'src');
992992
const appNgModulePath = join(srcDir, 'app', 'app.module.ts');
993993
const pageOneNgModulePath = join(srcDir, 'pages', 'page-one', 'page-one.module.ts');
994994
const pageOnePath = join(srcDir, 'pages', 'page-one', 'page-one.ts');
@@ -1181,7 +1181,7 @@ export class PageThreeModule {
11811181
11821182
`;
11831183

1184-
const srcDir = join('/Users', 'noone', 'myApp', 'src');
1184+
const srcDir = join(process.cwd(), 'myApp', 'src');
11851185
const appNgModulePath = join(srcDir, 'app', 'app.module.ts');
11861186
const pageOneNgModulePath = join(srcDir, 'pages', 'page-one', 'page-one.module.ts');
11871187
const pageOnePath = join(srcDir, 'pages', 'page-one', 'page-one.ts');
@@ -1215,15 +1215,15 @@ export class PageThreeModule {
12151215
expect(results[0].segment).toEqual(null);
12161216
expect(results[0].priority).toEqual('low');
12171217
expect(results[0].defaultHistory.length).toEqual(0);
1218-
expect(results[0].absolutePath).toEqual('/Users/noone/myApp/src/pages/page-one/page-one.module.ts');
1218+
expect(results[0].absolutePath).toEqual(join(srcDir, 'pages', 'page-one', 'page-one.module.ts'));
12191219
expect(results[0].userlandModulePath).toEqual('../pages/page-one/page-one.module');
12201220
expect(results[0].className).toEqual('PageOneModule');
12211221

12221222
expect(results[1].name).toEqual('PageTwo');
12231223
expect(results[1].segment).toEqual(null);
12241224
expect(results[1].priority).toEqual('low');
12251225
expect(results[1].defaultHistory.length).toEqual(0);
1226-
expect(results[1].absolutePath).toEqual('/Users/noone/myApp/src/pages/page-two/page-two.module.ts');
1226+
expect(results[1].absolutePath).toEqual(join(srcDir, 'pages', 'page-two', 'page-two.module.ts'));
12271227
expect(results[1].userlandModulePath).toEqual('../pages/page-two/page-two.module');
12281228
expect(results[1].className).toEqual('PageTwoModule');
12291229

@@ -1233,7 +1233,7 @@ export class PageThreeModule {
12331233
expect(results[2].defaultHistory.length).toEqual(2);
12341234
expect(results[2].defaultHistory[0]).toEqual('page-one');
12351235
expect(results[2].defaultHistory[1]).toEqual('page-two');
1236-
expect(results[2].absolutePath).toEqual('/Users/noone/myApp/src/pages/settings-page/fake-dir/settings-page.module.ts');
1236+
expect(results[2].absolutePath).toEqual(join(srcDir, 'pages', 'settings-page', 'fake-dir', 'settings-page.module.ts'));
12371237
expect(results[2].userlandModulePath).toEqual('../pages/settings-page/fake-dir/settings-page.module');
12381238
expect(results[2].className).toEqual('PageThreeModule');
12391239
});
@@ -1399,7 +1399,7 @@ export class PageThreeModule {
13991399
14001400
`;
14011401

1402-
const srcDir = join('/Users', 'noone', 'myApp', 'src');
1402+
const srcDir = join(process.cwd(), 'myApp', 'src');
14031403
const appNgModulePath = join(srcDir, 'app', 'app.module.ts');
14041404
const pageOneNgModulePath = join(srcDir, 'pages', 'page-one', 'page-one.not-module.ts');
14051405
const pageOnePath = join(srcDir, 'pages', 'page-one', 'page-one.ts');
@@ -1499,7 +1499,7 @@ import { HomePageModule } from '../pages/home/home.module';
14991499
export class AppModule {}
15001500
`;
15011501

1502-
const knownPath = '/idk/yo/some/path';
1502+
const knownPath = join(process.cwd(), 'idk', 'some', 'fake', 'path');
15031503

15041504
const result = util.hasExistingDeepLinkConfig(knownPath, knownContent);
15051505
expect(result).toEqual(false);
@@ -1529,7 +1529,7 @@ import { HomePageModule } from '../pages/home/home.module';
15291529
export class AppModule {}
15301530
`;
15311531

1532-
const knownPath = '/idk/yo/some/path';
1532+
const knownPath = join(process.cwd(), 'idk', 'some', 'fake', 'path');
15331533

15341534
const result = util.hasExistingDeepLinkConfig(knownPath, knownContent);
15351535
expect(result).toEqual(false);
@@ -1544,7 +1544,7 @@ export class AppModule {}
15441544
defaultHistory: [],
15451545
priority: 'low',
15461546
rawString: 'irrelevant for this test',
1547-
absolutePath: '/Users/noone/test/taco',
1547+
absolutePath: join(process.cwd(), 'myApp', 'pages', 'home-page', 'home-page.module.ts'),
15481548
userlandModulePath: '../pages/home-page/home-page.module',
15491549
className: 'HomePageModule'
15501550
};
@@ -1560,7 +1560,7 @@ export class AppModule {}
15601560
defaultHistory: ['page-two', 'page-three', 'page-four'],
15611561
priority: 'low',
15621562
rawString: 'irrelevant for this test',
1563-
absolutePath: '/Users/noone/test/taco',
1563+
absolutePath: join(process.cwd(), 'myApp', 'pages', 'home-page', 'home-page.module.ts'),
15641564
userlandModulePath: '../pages/home-page/home-page.module',
15651565
className: 'HomePageModule'
15661566
};
@@ -1579,7 +1579,7 @@ export class AppModule {}
15791579
defaultHistory: ['page-two', 'page-three', 'page-four'],
15801580
priority: 'low',
15811581
rawString: 'irrelevant for this test',
1582-
absolutePath: '/Users/noone/test/taco',
1582+
absolutePath: join(process.cwd(), 'myApp', 'pages', 'home-page', 'home-page.module.ts'),
15831583
userlandModulePath: '../pages/home-page/home-page.module',
15841584
className: 'HomePageModule'
15851585
});
@@ -1589,7 +1589,7 @@ export class AppModule {}
15891589
defaultHistory: [],
15901590
priority: 'low',
15911591
rawString: 'irrelevant for this test',
1592-
absolutePath: '/Users/noone/test/taco',
1592+
absolutePath: join(process.cwd(), 'myApp', 'pages', 'home-page', 'home-page.module.ts'),
15931593
userlandModulePath: '../pages/page-two/page-two.module',
15941594
className: 'PageTwoModule'
15951595
});
@@ -1599,7 +1599,7 @@ export class AppModule {}
15991599
defaultHistory: [],
16001600
priority: 'low',
16011601
rawString: 'irrelevant for this test',
1602-
absolutePath: '/Users/noone/test/taco',
1602+
absolutePath: join(process.cwd(), 'myApp', 'pages', 'home-page', 'home-page.module.ts'),
16031603
userlandModulePath: '../pages/settings-page/setting-page.module',
16041604
className: 'SettingsPageModule'
16051605
});
@@ -1676,7 +1676,7 @@ import { HomePageModule } from '../pages/home/home.module';
16761676
export class AppModule {}
16771677
`;
16781678

1679-
const knownPath = '/idk/yo/some/path/app.module.ts';
1679+
const knownPath = join('some', 'fake', 'path');
16801680

16811681
const result = util.getUpdatedAppNgModuleContentWithDeepLinkConfig(knownPath, knownContent, knownStringToInject);
16821682
expect(result).toEqual(expectedResult);
@@ -1746,7 +1746,7 @@ import { HomePageModule } from '../pages/home/home.module';
17461746
export class AppModule {}
17471747
`;
17481748

1749-
const knownPath = '/idk/yo/some/path/app.module.ts';
1749+
const knownPath = join('some', 'fake', 'path');
17501750

17511751
const result = util.getUpdatedAppNgModuleContentWithDeepLinkConfig(knownPath, knownContent, knownStringToInject);
17521752
expect(result).toEqual(expectedResult);
@@ -1816,7 +1816,7 @@ import { HomePageModule } from '../pages/home/home.module';
18161816
export class AppModule {}
18171817
`;
18181818

1819-
const knownPath = '/idk/yo/some/path/app.module.ts';
1819+
const knownPath = join('some', 'fake', 'path');
18201820

18211821
const result = util.getUpdatedAppNgModuleContentWithDeepLinkConfig(knownPath, knownContent, knownStringToInject);
18221822
expect(result).toEqual(expectedResult);
@@ -1886,7 +1886,7 @@ import { HomePageModule } from '../pages/home/home.module';
18861886
export class AppModule {}
18871887
`;
18881888

1889-
const knownPath = '/idk/yo/some/path/app.module.ts';
1889+
const knownPath = join('some', 'fake', 'path');
18901890

18911891
const result = util.getUpdatedAppNgModuleContentWithDeepLinkConfig(knownPath, knownContent, knownStringToInject);
18921892
expect(result).toEqual(expectedResult);
@@ -2345,7 +2345,7 @@ import { PageOne } from './page-one';
23452345
export class PageOneModule {}
23462346
23472347
`;
2348-
const knownFilePath = '/someFakePath/myApp/src/pages/page-one/page-one.ts';
2348+
const knownFilePath = join(process.cwd(), 'myApp', 'src', 'pages', 'page-one', 'page-one.ts');
23492349
const knownClassName = 'PageOne';
23502350
const fileContent = util.generateDefaultDeepLinkNgModuleContent(knownFilePath, knownClassName);
23512351
expect(fileContent).toEqual(knownFileContent);
@@ -2367,7 +2367,7 @@ export class PageOneModule {}
23672367
]
23682368
}
23692369
`;
2370-
const knownAppNgModulePath = '/some/fake/path/myApp/src/app.module.ts';
2370+
const knownAppNgModulePath = join(process.cwd(), 'myApp', 'src', 'app.module.ts');
23712371
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(knownAppNgModulePath);
23722372
spyOn(fileCache, 'get').and.callThrough();
23732373

@@ -2419,7 +2419,7 @@ import { HomePageModule } from '../pages/home/home.module';
24192419
export class AppModule {}
24202420
`;
24212421

2422-
const knownAppNgModulePath = '/some/fake/path/myApp/src/app.module.ts';
2422+
const knownAppNgModulePath = join(process.cwd(), 'myApp', 'src', 'app.module.ts');
24232423
fileCache.set(knownAppNgModulePath, { path: knownAppNgModulePath, content: ngModuleContent});
24242424
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(knownAppNgModulePath);
24252425
spyOn(fileCache, 'get').and.callThrough();
@@ -2482,7 +2482,7 @@ import { HomePageModule } from '../pages/home/home.module';
24822482
export class AppModule {}
24832483
`;
24842484

2485-
const knownAppNgModulePath = '/some/fake/path/myApp/src/app.module.ts';
2485+
const knownAppNgModulePath = join(process.cwd(), 'myApp', 'src', 'app.module.ts');
24862486
fileCache.set(knownAppNgModulePath, { path: knownAppNgModulePath, content: ngModuleContent});
24872487
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(knownAppNgModulePath);
24882488
spyOn(fileCache, 'get').and.callThrough();
@@ -2953,7 +2953,7 @@ class AppModuleInjector extends import0.ɵNgModuleInjector<import1.AppModule> {
29532953
export const AppModuleNgFactory:import0.NgModuleFactory<import1.AppModule> = new import0.NgModuleFactory<any>(AppModuleInjector,import1.AppModule);
29542954
`;
29552955

2956-
const knownAppNgModulePath = '/some/fake/path/myApp/src/app.module.ts';
2956+
const knownAppNgModulePath = join(process.cwd(), 'myApp', 'src', 'app.module.ts');
29572957
const knownAppNgModuleFactoryPath = helpers.changeExtension(knownAppNgModulePath, '.ngfactory.ts');
29582958
fileCache.set(knownAppNgModulePath, { path: knownAppNgModulePath, content: ngModuleContent});
29592959
fileCache.set(knownAppNgModuleFactoryPath, { path: knownAppNgModuleFactoryPath, content: knownNgFactoryContent});

0 commit comments

Comments
 (0)