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

Commit 808b153

Browse files
committed
test(generators): make generators platform independent
make generators platform independent
1 parent e156e5f commit 808b153

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/generators/util.spec.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ describe('util', () => {
1111
describe('hydrateRequest', () => {
1212
it('should take a component request and return a hydrated component request', () => {
1313
// arrange
14-
const componentsDir = '/Users/noone/project/src/components';
14+
const baseDir = join(process.cwd(), 'someDir', 'project');
15+
const componentsDir = join(baseDir, 'src', 'components');
1516
const context = {
1617
componentsDir: componentsDir
1718
};
@@ -22,14 +23,14 @@ describe('util', () => {
2223
includeNgModule: true
2324
};
2425

25-
const templateDir = '/Users/noone/project/node_modules/ionic-angular/templates';
26+
const templateDir = join(baseDir, 'node_modules', 'ionic-angular', 'templates');
2627
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(templateDir);
2728

2829
// act
2930
const hydratedRequest = util.hydrateRequest(context, request);
3031

3132
// assert
32-
expect(hydratedRequest).toEqual({'className': 'SettingsViewComponent', 'dirToRead': '/Users/noone/project/node_modules/ionic-angular/templates/component', 'dirToWrite': '/Users/noone/project/src/components/settings-view', 'fileName': 'settings-view', 'includeNgModule': true, 'includeSpec': true, 'name': 'settings view', 'type': 'component'});
33+
expect(hydratedRequest).toEqual({'className': 'SettingsViewComponent', 'dirToRead': join(templateDir, 'component'), 'dirToWrite': join(componentsDir, 'settings-view'), 'fileName': 'settings-view', 'includeNgModule': true, 'includeSpec': true, 'name': 'settings view', 'type': 'component'});
3334
expect(hydratedRequest.type).toEqual(Constants.COMPONENT);
3435
expect(hydratedRequest.name).toEqual(request.name);
3536
expect(hydratedRequest.includeNgModule).toBeTruthy();
@@ -42,7 +43,8 @@ describe('util', () => {
4243

4344
it('should take a page request and return a hydrated page request', () => {
4445
// arrange
45-
const pagesDir = '/Users/noone/project/src/pages';
46+
const baseDir = join(process.cwd(), 'someDir', 'project');
47+
const pagesDir = join(baseDir, 'src', 'pages');
4648
const context = {
4749
pagesDir: pagesDir
4850
};
@@ -53,14 +55,14 @@ describe('util', () => {
5355
includeNgModule: true
5456
};
5557

56-
const templateDir = '/Users/noone/project/node_modules/ionic-angular/templates';
58+
const templateDir = join(baseDir, 'node_modules', 'ionic-angular', 'templates');
5759
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue(templateDir);
5860

5961
// act
6062
const hydratedRequest = util.hydrateRequest(context, request);
6163

6264
// assert
63-
expect(hydratedRequest).toEqual({'className': 'SettingsViewPage', 'dirToRead': '/Users/noone/project/node_modules/ionic-angular/templates/page', 'dirToWrite': '/Users/noone/project/src/pages/settings-view', 'fileName': 'settings-view', 'includeNgModule': true, 'includeSpec': true, 'name': 'settings view', 'type': 'page'});
65+
expect(hydratedRequest).toEqual({'className': 'SettingsViewPage', 'dirToRead': join(templateDir, 'page'), 'dirToWrite': join(pagesDir, 'settings-view'), 'fileName': 'settings-view', 'includeNgModule': true, 'includeSpec': true, 'name': 'settings view', 'type': 'page'});
6466
expect(hydratedRequest.type).toEqual(Constants.PAGE);
6567
expect(hydratedRequest.name).toEqual(request.name);
6668
expect(hydratedRequest.includeNgModule).toBeTruthy();
@@ -371,11 +373,11 @@ $TAB_CONTENT
371373

372374
describe('getNgModules', () => {
373375
let context: any;
374-
const componentsDir = '/path/to/components';
375-
const directivesDir = '/path/to/directives';
376-
const pagesDir = '/path/to/pages';
377-
const pipesDir = '/path/to/pipes';
378-
const providersDir = '/path/to/providers';
376+
const componentsDir = join(process.cwd(), 'path', 'to', 'components');
377+
const directivesDir = join(process.cwd(), 'path', 'to', 'directives');
378+
const pagesDir = join(process.cwd(), 'path', 'to', 'pages');
379+
const pipesDir = join(process.cwd(), 'path', 'to', 'pipes');
380+
const providersDir = join(process.cwd(), 'path', 'to', 'providers');
379381

380382
beforeEach(() => {
381383
context = { componentsDir, directivesDir, pagesDir, pipesDir, providersDir };
@@ -391,14 +393,14 @@ $TAB_CONTENT
391393
const globAllSpy = spyOn(globUtils, globUtils.globAll.name);
392394
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue('.module.ts');
393395
util.getNgModules(context, ['component']);
394-
expect(globAllSpy).toHaveBeenCalledWith(['/path/to/components/**/*.module.ts']);
396+
expect(globAllSpy).toHaveBeenCalledWith([join(componentsDir, '**', '*.module.ts')]);
395397
});
396398

397399
it('should return a list of glob results for pages and components', () => {
398400
const globAllSpy = spyOn(globUtils, globUtils.globAll.name);
399401
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue('.module.ts');
400402
util.getNgModules(context, ['page', 'component']);
401-
expect(globAllSpy).toHaveBeenCalledWith(['/path/to/pages/**/*.module.ts', '/path/to/components/**/*.module.ts']);
403+
expect(globAllSpy).toHaveBeenCalledWith([join(pagesDir, '**', '*.module.ts'), join(componentsDir, '**', '*.module.ts')]);
402404
});
403405
});
404406

@@ -441,8 +443,9 @@ $TAB_CONTENT
441443
}).catch((err: Error) => {
442444
expect(err.message).toEqual(knownErrorMsg);
443445
});
446+
*/
444447
});
445-
*/
448+
446449
});
447450

448451
describe('nonPageFileManipulation', () => {

0 commit comments

Comments
 (0)