From 2937d9dd6a8b5e31bf77c26856087652d2044eed Mon Sep 17 00:00:00 2001 From: Burak Tasci Date: Thu, 31 Aug 2017 04:02:19 +0300 Subject: [PATCH] refactor(core): refactor public API * refactor(core): refactor public API * build(npm): update scripts * build(gulp): update tasks * refactor: update test config * refactor: update tsconfig --- config/gulp-tasks.js | 27 +++-- config/webpack.test.js | 4 +- package.json | 10 +- packages/@ngx-meta/core/config/karma.conf.js | 28 ++--- packages/@ngx-meta/core/index.ts | 9 +- packages/@ngx-meta/core/src/meta.guard.ts | 2 +- packages/@ngx-meta/core/src/meta.helper.ts | 2 +- packages/@ngx-meta/core/src/meta.loader.ts | 14 +-- packages/@ngx-meta/core/src/meta.service.ts | 112 +++++++++--------- .../core/src/models/meta-definition.ts | 1 + packages/@ngx-meta/core/src/util.ts | 10 +- packages/@ngx-meta/core/tests/index.spec.ts | 12 +- .../@ngx-meta/core/tests/meta.loader.spec.ts | 6 +- .../@ngx-meta/core/tests/meta.service.spec.ts | 63 ---------- packages/@ngx-meta/core/tests/tsconfig.json | 25 ++++ packages/@ngx-meta/core/tsconfig.json | 11 +- 16 files changed, 153 insertions(+), 183 deletions(-) create mode 100644 packages/@ngx-meta/core/tests/tsconfig.json diff --git a/config/gulp-tasks.js b/config/gulp-tasks.js index a8b3ce7..3b673b0 100644 --- a/config/gulp-tasks.js +++ b/config/gulp-tasks.js @@ -49,10 +49,15 @@ const clean = { for (const item of Object.keys(packages[group])) $.rimraf(`./packages/${group}/${item}/src/**/*.metadata.json`, done); }, - 'tests/*.d.ts': done => { + 'testing/*.js': done => { for (const group of Object.keys(packages)) for (const item of Object.keys(packages[group])) - $.rimraf(`./packages/${group}/${item}/tests/**/*.d.ts`, done); + $.rimraf(`./packages/${group}/${item}/testing/**/*.js`, done); + }, + 'testing/*.d.ts': done => { + for (const group of Object.keys(packages)) + for (const item of Object.keys(packages[group])) + $.rimraf(`./packages/${group}/${item}/testing/**/*.d.ts`, done); } }; @@ -63,6 +68,8 @@ clean['index.metadata.json'].displayName = 'clean:./index.metadata.json'; clean['src/*.js'].displayName = 'clean:./src/*.js'; clean['src/*.d.ts'].displayName = 'clean:./src/*.js'; clean['src/*.metadata.json'].displayName = 'clean:./src/*.js'; +clean['testing/*.js'].displayName = 'clean:./testing/*.js'; +clean['testing/*.d.ts'].displayName = 'clean:./testing/*.d.ts'; const ts = { compile: done => { @@ -100,6 +107,8 @@ const ts = { './**/index.ts', './**/src/**/*.ts', '!./**/src/**/*.d.ts', + './**/testing/**/*.ts', + '!./**/testing/**/*.d.ts', './**/tests/**/*.ts', '!./**/tests/**/*.d.ts', '!./**/node_modules/**/*' @@ -179,13 +188,16 @@ const tests = { configFile: $$.root(`./packages/${group}/${item}/config/karma.conf.js`), webpack: webpack(group, item, settings), coverageIstanbulReporter: { - reports: ['html', 'text-summary'], + reports: [ + 'html', + 'json', + 'lcovonly', + 'text-summary' + ], dir: `./coverage/${group}/${item}`, fixWebpackSourcePaths: true, 'report-config': { - html: { - subdir: 'html' - } + html: {subdir: 'html'} } } }, () => d()).start(); @@ -225,7 +237,8 @@ gulp.task('clean', clean['src/*.js'], clean['src/*.d.ts'], clean['src/*.metadata.json'], - clean['tests/*.d.ts'] + clean['testing/*.js'], + clean['testing/*.d.ts'] )); gulp.task('make', diff --git a/config/webpack.test.js b/config/webpack.test.js index 865f269..9bb0ed4 100644 --- a/config/webpack.test.js +++ b/config/webpack.test.js @@ -38,11 +38,11 @@ module.exports = (group, item, settings) => { sourceMap: false, inlineSourceMap: true, compilerOptions: { - // Remove TypeScript helpers to be injected + // remove TypeScript helpers to be injected // below by DefinePlugin removeComments: true }, - configFileName: helpers.root(`packages/${group}/${item}/tsconfig.json`) + configFileName: helpers.root(`packages/${group}/${item}/tests/tsconfig.json`) } } ], diff --git a/package.json b/package.json index 09dd433..dd2d8c9 100644 --- a/package.json +++ b/package.json @@ -17,10 +17,10 @@ }, "homepage": "https://github.com/fulls1z3/ngx-meta/tree/v0.2.x/#readme", "scripts": { - "clean": "gulp clean", - "lint": "gulp tslint", - "make": "gulp make", - "test": "gulp test" + "clean": "gulp clean --color", + "lint": "gulp tslint --color", + "make": "gulp make --color", + "test": "gulp test --color" }, "devDependencies": { "@angular/common": "~2.4.0", @@ -42,7 +42,7 @@ "tslint-loader": "^3.5.3", "awesome-typescript-loader": "^3.2.3", "jasmine-core": "^2.8.0", - "karma": "^1.7.0", + "karma": "^1.7.1", "karma-jasmine": "^1.1.0", "karma-coverage": "^1.1.1", "karma-mocha-reporter": "^2.2.4", diff --git a/packages/@ngx-meta/core/config/karma.conf.js b/packages/@ngx-meta/core/config/karma.conf.js index 888d095..a5ffa3c 100644 --- a/packages/@ngx-meta/core/config/karma.conf.js +++ b/packages/@ngx-meta/core/config/karma.conf.js @@ -3,9 +3,7 @@ module.exports = function(config) { basePath: '', frameworks: ['jasmine'], exclude: [], - client: { - captureConsole: false - }, + client: {captureConsole: false}, files: [ { pattern: './spec-bundle.js', @@ -13,25 +11,27 @@ module.exports = function(config) { } ], preprocessors: { - './spec-bundle.js': ['coverage', 'webpack', 'sourcemap'] + './spec-bundle.js': [ + 'coverage', + 'webpack', + 'sourcemap' + ] }, webpackMiddleware: { noInfo: true, - stats: { - chunks: false - } - }, - reporters: ['mocha', 'coverage', 'coverage-istanbul'], - coverageReporter: { - type: 'in-memory' + stats: {chunks: false} }, + reporters: [ + 'mocha', + 'coverage', + 'coverage-istanbul' + ], + coverageReporter: {type: 'in-memory'}, port: 9876, colors: true, logLevel: config.LOG_WARN, autoWatch: false, - browsers: [ - 'Chrome' - ], + browsers: ['Chrome'], customLaunchers: { ChromeTravisCi: { base: 'Chrome', diff --git a/packages/@ngx-meta/core/index.ts b/packages/@ngx-meta/core/index.ts index 6d16a65..8a57289 100644 --- a/packages/@ngx-meta/core/index.ts +++ b/packages/@ngx-meta/core/index.ts @@ -18,15 +18,12 @@ export function metaFactory(): MetaLoader { return new MetaStaticLoader(); } -/** - * Do not specify providers for modules that might be imported by a lazy loaded module. - */ @NgModule() export class MetaModule { static forRoot(configuredProvider: any = { - provide: MetaLoader, - useFactory: (metaFactory) - }): ModuleWithProviders { + provide: MetaLoader, + useFactory: (metaFactory) + }): ModuleWithProviders { return { ngModule: MetaModule, providers: [ diff --git a/packages/@ngx-meta/core/src/meta.guard.ts b/packages/@ngx-meta/core/src/meta.guard.ts index 3a354c8..ac8aaca 100644 --- a/packages/@ngx-meta/core/src/meta.guard.ts +++ b/packages/@ngx-meta/core/src/meta.guard.ts @@ -13,7 +13,7 @@ export class MetaGuard implements CanActivate, CanActivateChild { canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { const url = state.url; - const metaSettings = (!!route && !!route.data && !!route.data['meta']) + const metaSettings = (route && route.data && route.data['meta']) ? route.data['meta'] : undefined; this.meta.update(url, metaSettings); diff --git a/packages/@ngx-meta/core/src/meta.helper.ts b/packages/@ngx-meta/core/src/meta.helper.ts index 6164af4..d47cd13 100644 --- a/packages/@ngx-meta/core/src/meta.helper.ts +++ b/packages/@ngx-meta/core/src/meta.helper.ts @@ -70,7 +70,7 @@ export class MetaHelper { } removeElement(element: any): void { - if (!!element) + if (element) this.dom.remove(element); } diff --git a/packages/@ngx-meta/core/src/meta.loader.ts b/packages/@ngx-meta/core/src/meta.loader.ts index 99f4421..b577191 100644 --- a/packages/@ngx-meta/core/src/meta.loader.ts +++ b/packages/@ngx-meta/core/src/meta.loader.ts @@ -3,17 +3,17 @@ import { PageTitlePositioning } from './models/page-title-positioning'; import { MetaSettings } from './models/meta-settings'; export abstract class MetaLoader { - abstract getSettings(): MetaSettings; + abstract get settings(): MetaSettings; } export class MetaStaticLoader implements MetaLoader { - constructor(private readonly settings: MetaSettings = { - pageTitlePositioning: PageTitlePositioning.PrependPageTitle, - defaults: {} - }) { + get settings(): MetaSettings { + return this.providedSettings; } - getSettings(): MetaSettings { - return this.settings; + constructor(private readonly providedSettings: MetaSettings = { + pageTitlePositioning: PageTitlePositioning.PrependPageTitle, + defaults: {} + }) { } } diff --git a/packages/@ngx-meta/core/src/meta.service.ts b/packages/@ngx-meta/core/src/meta.service.ts index 50f35aa..dacc4dd 100644 --- a/packages/@ngx-meta/core/src/meta.service.ts +++ b/packages/@ngx-meta/core/src/meta.service.ts @@ -15,47 +15,50 @@ import { isObservable, isPromise } from './util'; @Injectable() export class MetaService { - private readonly metaSettings: any; + protected readonly settings: any; private readonly isMetaTagSet: any; constructor(public readonly loader: MetaLoader, private readonly title: Title, private readonly meta: MetaHelper) { - this.metaSettings = loader.getSettings(); + this.settings = loader.settings; this.isMetaTagSet = {}; } setTitle(title: string, override = false): void { - const title$ = !!title + const title$ = title ? this.callback(title) : Observable.of(''); - title$.subscribe((res: string) => { - let fullTitle = ''; - - if (!res) { - const defaultTitle$ = (!!this.metaSettings.defaults && !!this.metaSettings.defaults['title']) - ? this.callback(this.metaSettings.defaults['title']) - : Observable.of(''); - - defaultTitle$.subscribe((defaultTitle: string) => { - if (!override && this.metaSettings.pageTitleSeparator && this.metaSettings.applicationName) - this.callback(this.metaSettings.applicationName).subscribe((applicationName: string) => { - fullTitle = !!applicationName ? this.getTitleWithPositioning(defaultTitle, applicationName) : defaultTitle; + title$ + .subscribe((res: string) => { + let fullTitle = ''; + + if (!res) { + const defaultTitle$ = (this.settings.defaults && this.settings.defaults['title']) + ? this.callback(this.settings.defaults['title']) + : Observable.of(''); + + defaultTitle$ + .subscribe((defaultTitle: string) => { + if (!override && this.settings.pageTitleSeparator && this.settings.applicationName) + this.callback(this.settings.applicationName) + .subscribe((applicationName: string) => { + fullTitle = applicationName ? this.getTitleWithPositioning(defaultTitle, applicationName) : defaultTitle; + this.updateTitle(fullTitle); + }); + else + this.updateTitle(defaultTitle); + }); + } else if (!override && this.settings.pageTitleSeparator && this.settings.applicationName) + this.callback(this.settings.applicationName) + .subscribe((applicationName: string) => { + fullTitle = applicationName ? this.getTitleWithPositioning(res, applicationName) : res; this.updateTitle(fullTitle); }); - else - this.updateTitle(defaultTitle); - }); - } else - if (!override && this.metaSettings.pageTitleSeparator && this.metaSettings.applicationName) - this.callback(this.metaSettings.applicationName).subscribe((applicationName: string) => { - fullTitle = !!applicationName ? this.getTitleWithPositioning(res, applicationName) : res; - this.updateTitle(fullTitle); - }); else this.updateTitle(res); - }); + }); } setTag(key: string, value: string): void { @@ -63,24 +66,25 @@ export class MetaService { throw new Error(`Attempt to set ${key} through "setTag": "title" is a reserved tag name. ` + 'Please use `MetaService.setTitle` instead.'); - value = value || ((!!this.metaSettings.defaults && !!this.metaSettings.defaults[key]) - ? this.metaSettings.defaults[key] - : ''); + value = value || ((this.settings.defaults && this.settings.defaults[key]) + ? this.settings.defaults[key] + : ''); const value$ = (key !== 'og:locale' && key !== 'og:locale:alternate') ? this.callback(value) : Observable.of(value); - value$.subscribe((res: string) => { - this.updateTag(key, res); - }); + value$ + .subscribe((res: string) => { + this.updateTag(key, res); + }); } update(currentUrl: string, metaSettings?: any): void { if (!metaSettings) { - const fallbackTitle = !!this.metaSettings.defaults - ? (this.metaSettings.defaults['title'] || this.metaSettings['applicationName']) - : this.metaSettings['applicationName']; + const fallbackTitle = this.settings.defaults + ? (this.settings.defaults['title'] || this.settings['applicationName']) + : this.settings['applicationName']; this.setTitle(fallbackTitle, true); } else { @@ -111,17 +115,17 @@ export class MetaService { }); } - if (!!this.metaSettings.defaults) - Object.keys(this.metaSettings.defaults) + if (this.settings.defaults) + Object.keys(this.settings.defaults) .forEach(key => { - let value = this.metaSettings.defaults[key]; + let value = this.settings.defaults[key]; - if ((!!metaSettings && (key in this.isMetaTagSet || key in metaSettings)) || key === 'title' || key === 'override') + if ((metaSettings && (key in this.isMetaTagSet || key in metaSettings)) || key === 'title' || key === 'override') return; else if (key === 'og:locale') value = value.replace(/-/g, '_'); else if (key === 'og:locale:alternate') { - const currentLocale = !!metaSettings ? metaSettings['og:locale'] : undefined; + const currentLocale = metaSettings ? metaSettings['og:locale'] : undefined; this.updateLocales(currentLocale, value); return; @@ -130,7 +134,7 @@ export class MetaService { this.setTag(key, value); }); - const url = ((this.metaSettings.applicationUrl || '/') + currentUrl) + const url = ((this.settings.applicationUrl || '/') + currentUrl) .replace(/(https?:\/\/)|(\/)+/g, '$1$2') .replace(/\/$/g, ''); @@ -138,8 +142,8 @@ export class MetaService { } private callback(value: string): Observable { - if (!!this.metaSettings.callback) { - const value$ = this.metaSettings.callback(value); + if (this.settings.callback) { + const value$ = this.settings.callback(value); if (!isObservable(value$)) return isPromise(value$) @@ -153,13 +157,13 @@ export class MetaService { } private getTitleWithPositioning(title: string, applicationName: string): string { - switch (this.metaSettings.pageTitlePositioning) { + switch (this.settings.pageTitlePositioning) { case PageTitlePositioning.AppendPageTitle: - return applicationName + this.metaSettings.pageTitleSeparator + title; + return applicationName + this.settings.pageTitleSeparator + title; case PageTitlePositioning.PrependPageTitle: - return title + this.metaSettings.pageTitleSeparator + applicationName; + return title + this.settings.pageTitleSeparator + applicationName; default: - throw new Error(`Invalid pageTitlePositioning specified [${this.metaSettings.pageTitlePositioning}]!`); + throw new Error(`Invalid pageTitlePositioning specified [${this.settings.pageTitlePositioning}]!`); } } @@ -172,12 +176,12 @@ export class MetaService { } private updateLocales(currentLocale: string, availableLocales: string): void { - currentLocale = currentLocale || (!!this.metaSettings.defaults - ? this.metaSettings.defaults['og:locale'] - : ''); + currentLocale = currentLocale || (this.settings.defaults + ? this.settings.defaults['og:locale'] + : ''); - if (!!currentLocale && !!this.metaSettings.defaults) - this.metaSettings.defaults['og:locale'] = currentLocale.replace(/_/g, '-'); + if (currentLocale && this.settings.defaults) + this.settings.defaults['og:locale'] = currentLocale.replace(/_/g, '-'); // TODO: set HTML lang attribute - https://github.com/ngx-meta/core/issues/32 // const html = this.document.querySelector('html'); @@ -189,7 +193,7 @@ export class MetaService { this.meta.removeElement(element); }); - if (!!currentLocale && !!availableLocales) + if (currentLocale && availableLocales) availableLocales.split(',') .forEach((locale: string) => { if (currentLocale.replace(/-/g, '_') !== locale.replace(/-/g, '_')) @@ -230,8 +234,8 @@ export class MetaService { content: value }); else if (key === 'og:locale') { - const availableLocales = !!this.metaSettings.defaults - ? this.metaSettings.defaults['og:locale:alternate'] + const availableLocales = this.settings.defaults + ? this.settings.defaults['og:locale:alternate'] : ''; this.updateLocales(value, availableLocales); diff --git a/packages/@ngx-meta/core/src/models/meta-definition.ts b/packages/@ngx-meta/core/src/models/meta-definition.ts index bd9be74..45cf749 100644 --- a/packages/@ngx-meta/core/src/models/meta-definition.ts +++ b/packages/@ngx-meta/core/src/models/meta-definition.ts @@ -11,5 +11,6 @@ export interface MetaDefinition { property?: string; scheme?: string; url?: string; + [prop: string]: string; } diff --git a/packages/@ngx-meta/core/src/util.ts b/packages/@ngx-meta/core/src/util.ts index 75b4a07..07a38f7 100644 --- a/packages/@ngx-meta/core/src/util.ts +++ b/packages/@ngx-meta/core/src/util.ts @@ -1,20 +1,12 @@ // libs import { Observable } from 'rxjs/Observable'; // TODO use Symbol.observable when https://github.com/ReactiveX/rxjs/issues/2415 will be resolved -import { $$observable as symbolObservable } from 'rxjs/symbol/observable'; +// import { $$observable as symbolObservable } from 'rxjs/symbol/observable'; -/** - * Determine if the argument is shaped like a Promise - */ export function isPromise(obj: any): obj is Promise { - // allow any Promise/A+ compliant thenable. - // It's up to the caller to ensure that obj.then conforms to the spec return !!obj && typeof obj.then === 'function'; } -/** - * Determine if the argument is an Observable - */ export function isObservable(obj: any | Observable): obj is Observable { // TODO use Symbol.observable when https://github.com/ReactiveX/rxjs/issues/2415 will be resolved // return !!(obj && obj[symbolObservable]); diff --git a/packages/@ngx-meta/core/tests/index.spec.ts b/packages/@ngx-meta/core/tests/index.spec.ts index 0f7bd99..bcad581 100644 --- a/packages/@ngx-meta/core/tests/index.spec.ts +++ b/packages/@ngx-meta/core/tests/index.spec.ts @@ -45,7 +45,7 @@ const testRoutes: Routes = [ data: { meta: { title: 'Toothpaste', - override: true, // prevents appending/prepending the application name to the title attribute + override: true, description: 'Eating toothpaste is considered to be too healthy!', 'og:locale': 'fr-FR', 'og:locale:alternate': 'en-US,fr-FR,tr-TR' @@ -101,20 +101,18 @@ export const testSettings: MetaSettings = { } }; -// test module configuration for each test export const testModuleConfig = (moduleOptions?: any) => { - // reset the test environment before initializing it. TestBed.resetTestEnvironment(); TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting()) .configureTestingModule({ - declarations: [ - TestBootstrapComponent, - TestComponent - ], imports: [ RouterTestingModule.withRoutes(testRoutes), MetaModule.forRoot(moduleOptions) + ], + declarations: [ + TestBootstrapComponent, + TestComponent ] }); }; diff --git a/packages/@ngx-meta/core/tests/meta.loader.spec.ts b/packages/@ngx-meta/core/tests/meta.loader.spec.ts index 41d4b34..f9ea3a5 100644 --- a/packages/@ngx-meta/core/tests/meta.loader.spec.ts +++ b/packages/@ngx-meta/core/tests/meta.loader.spec.ts @@ -18,10 +18,10 @@ describe('@ngx-meta/core:', describe('MetaLoader', () => { - it('should be able to return the default metaSettings', + it('should be able to return the default settings', () => { const loader = new MetaStaticLoader(); - const loadedApiEndpoint = loader.getSettings(); + const loadedApiEndpoint = loader.settings; expect(loadedApiEndpoint).toEqual(defaultSettings); }); @@ -46,7 +46,7 @@ describe('@ngx-meta/core:', it('should be able to provide any `MetaLoader`', () => { class CustomLoader implements MetaLoader { - getSettings(): MetaSettings { + get settings(): MetaSettings { return emptySettings; } } diff --git a/packages/@ngx-meta/core/tests/meta.service.spec.ts b/packages/@ngx-meta/core/tests/meta.service.spec.ts index 5b507e6..3b9749e 100644 --- a/packages/@ngx-meta/core/tests/meta.service.spec.ts +++ b/packages/@ngx-meta/core/tests/meta.service.spec.ts @@ -57,14 +57,12 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { expect(title.getTitle()).toEqual('Sweet home - Tour of (lazy/busy) heroes'); expect(meta.getMetaElement('name="description"').content).toEqual('Home, home sweet home... and what?'); expect(meta.getMetaElement('property="og:url"').content).toEqual('http://localhost:3000'); - // navigate to /toothpaste (override applicationName) router.navigate(['/toothpaste']) .then(() => { expect(title.getTitle()).toEqual('Toothpaste'); @@ -72,7 +70,6 @@ describe('@ngx-meta/core:', .toEqual('Eating toothpaste is considered to be too healthy!'); expect(meta.getMetaElement('property="og:url"').content).toEqual('http://localhost:3000/toothpaste'); - // navigate to /duck (meta disable) router.navigate(['/duck']) .then(() => { expect(title.getTitle()).toEqual('Mighty mighty mouse'); @@ -80,7 +77,6 @@ describe('@ngx-meta/core:', .toEqual('Mighty Mouse is an animated superhero mouse character'); expect(meta.getMetaElement('property="og:url"').content).toEqual('http://localhost:3000/duck'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { expect(title.getTitle()).toEqual('Mighty mighty mouse'); @@ -88,7 +84,6 @@ describe('@ngx-meta/core:', .toEqual('Mighty Mouse is an animated superhero mouse character'); expect(meta.getMetaElement('property="og:url"').content).toEqual('http://localhost:3000/no-data'); - // navigate to /no-meta router.navigate(['/no-meta']) .then(() => { expect(title.getTitle()).toEqual('Mighty mighty mouse'); @@ -111,7 +106,6 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { expect(title.getTitle()).toEqual('Mighty mighty mouse'); @@ -138,7 +132,6 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { expect(title.getTitle()).toEqual('Sweet home'); @@ -169,7 +162,6 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { expect(title.getTitle()).toEqual('Tour of (lazy/busy) heroes'); @@ -196,7 +188,6 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { expect(title.getTitle()).toEqual(''); @@ -213,24 +204,18 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default title metaService.setTitle(''); expect(title.getTitle()).toEqual('Mighty mighty mouse - Tour of (lazy/busy) heroes'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given title metaService.setTitle('Mighty tiny mouse'); expect(title.getTitle()).toEqual('Mighty tiny mouse - Tour of (lazy/busy) heroes'); - // navigate to / router.navigate(['/']) .then(() => { - // override applicationName metaService.setTitle('Mighty tiny mouse', true); expect(title.getTitle()).toEqual('Mighty tiny mouse'); }); @@ -258,24 +243,18 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default title metaService.setTitle(''); expect(title.getTitle()).toEqual('Tour of (lazy/busy) heroes - Mighty mighty mouse'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given title metaService.setTitle('Mighty tiny mouse'); expect(title.getTitle()).toEqual('Tour of (lazy/busy) heroes - Mighty tiny mouse'); - // navigate to / router.navigate(['/']) .then(() => { - // override applicationName metaService.setTitle('Mighty tiny mouse', true); expect(title.getTitle()).toEqual('Mighty tiny mouse'); }); @@ -301,10 +280,8 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default title metaService.setTitle(''); expect(title.getTitle()).toEqual(''); }); @@ -330,10 +307,8 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default title metaService.setTitle(''); expect(title.getTitle()).toEqual(''); }); @@ -374,18 +349,14 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default meta description metaService.setTag('description', ''); expect(meta.getMetaElement('name="description"').content) .toEqual('Mighty Mouse is an animated superhero mouse character'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given meta description metaService.setTag('description', 'Mighty Mouse is a cool character'); expect(meta.getMetaElement('name="description"').content).toEqual('Mighty Mouse is a cool character'); }); @@ -410,10 +381,8 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default meta description metaService.setTag('description', ''); expect(meta.getMetaElement('name="description"').content).toEqual(''); }); @@ -428,17 +397,13 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default meta author metaService.setTag('author', ''); expect(meta.getMetaElement('name="author"').content).toEqual('Mighty Mouse'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given meta author metaService.setTag('author', 'Mickey Mouse'); expect(meta.getMetaElement('name="author"').content).toEqual('Mickey Mouse'); }); @@ -454,17 +419,13 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default meta publisher metaService.setTag('publisher', ''); expect(meta.getMetaElement('name="publisher"').content).toEqual('a superhero'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given meta publisher metaService.setTag('publisher', 'another superhero'); expect(meta.getMetaElement('name="publisher"').content).toEqual('another superhero'); }); @@ -480,10 +441,8 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default og:locale metaService.setTag('og:locale', ''); expect(meta.getMetaElement('property="og:locale"').content).toEqual('en_US'); @@ -493,10 +452,8 @@ describe('@ngx-meta/core:', expect(elements[0].content).toEqual('nl_NL'); expect(elements[1].content).toEqual('tr_TR'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given og:locale metaService.setTag('og:locale', 'tr-TR'); expect(meta.getMetaElement('property="og:locale"').content).toEqual('tr_TR'); @@ -518,10 +475,8 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default og:locale:alternate metaService.setTag('og:locale:alternate', ''); const elements = meta.getMetaElements('property="og:locale:alternate"'); @@ -529,10 +484,8 @@ describe('@ngx-meta/core:', expect(elements[0].content).toEqual('nl_NL'); expect(elements[1].content).toEqual('tr_TR'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given og:locale:alternate metaService.setTag('og:locale:alternate', 'tr-TR'); expect(meta.getMetaElement('property="og:locale:alternate"').content).toEqual('tr_TR'); }); @@ -557,17 +510,13 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default og:locale metaService.setTag('og:locale', ''); expect(meta.getMetaElement('property="og:locale"').content).toEqual(''); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given og:locale metaService.setTag('og:locale', 'tr-TR'); expect(meta.getMetaElement('property="og:locale"').content).toEqual('tr_TR'); }); @@ -592,7 +541,6 @@ describe('@ngx-meta/core:', expect(meta.getMetaElement('property="og:locale"').content).toEqual('tr_TR'); - // given og:locale:alternate metaService.setTag('og:locale:alternate', 'tr-TR'); expect(meta.getMetaElement('property="og:locale:alternate"')).toBeNull(); })); @@ -616,7 +564,6 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { expect(title.getTitle()).toEqual('Sweet home'); @@ -635,17 +582,13 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default og:type metaService.setTag('og:type', ''); expect(meta.getMetaElement('property="og:type"').content).toEqual('website'); - // navigate to /no-data router.navigate(['/no-data']) .then(() => { - // given og:type metaService.setTag('og:type', 'blog'); expect(meta.getMetaElement('property="og:type"').content).toEqual('blog'); }); @@ -676,10 +619,8 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default title metaService.setTitle('test'); expect(title.getTitle()).toEqual('test'); }); @@ -709,10 +650,8 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { - // default title metaService.setTitle(''); expect(title.getTitle()).toEqual('test'); }); @@ -738,7 +677,6 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { expect(title.getTitle()).toEqual('Sweet home - Tour of (lazy/busy) heroes'); @@ -763,7 +701,6 @@ describe('@ngx-meta/core:', const fixture = TestBed.createComponent(TestBootstrapComponent); fixture.detectChanges(); - // initial navigation router.navigate(['/']) .then(() => { expect(title.getTitle()).toEqual('Sweet home - Tour of (lazy/busy) heroes'); diff --git a/packages/@ngx-meta/core/tests/tsconfig.json b/packages/@ngx-meta/core/tests/tsconfig.json new file mode 100644 index 0000000..f8a2283 --- /dev/null +++ b/packages/@ngx-meta/core/tests/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "module": "commonjs", + "target": "es5", + "noImplicitAny": true, + "suppressImplicitAnyIndexErrors": true, + "importHelpers": true, + "removeComments": true, + "typeRoots": [ + "../../../../node_modules/@types" + ], + "lib": [ + "es2017", + "dom" + ] + }, + "exclude": [ + "node_modules" + ], + "compileOnSave": false, + "buildOnSave": false +} diff --git a/packages/@ngx-meta/core/tsconfig.json b/packages/@ngx-meta/core/tsconfig.json index e996c7c..720d03e 100644 --- a/packages/@ngx-meta/core/tsconfig.json +++ b/packages/@ngx-meta/core/tsconfig.json @@ -1,18 +1,21 @@ { "compilerOptions": { - "target": "es5", - "module": "es2015", "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, - "removeComments": true, + "module": "es2015", + "target": "es5", "noImplicitAny": true, "suppressImplicitAnyIndexErrors": true, "importHelpers": true, - "lib": [ "es2015", "dom" ], "declaration": true, + "removeComments": true, "typeRoots": [ "../../../node_modules/@types" + ], + "lib": [ + "es2017", + "dom" ] }, "files": [