Skip to content

Commit 062e3f4

Browse files
committed
Version replacements and specs
1 parent e619a82 commit 062e3f4

File tree

17 files changed

+45
-58
lines changed

17 files changed

+45
-58
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"private": true,
66
"scripts": {
77
"test": "npm run test:node",
8-
"test:chrome": "npx firebase emulators:exec --project=angularfire2-test \"npx ng test --watch=false --browsers=Chrome\"",
8+
"test:watch": "npx firebase emulators:exec --project=angularfire2-test \"npx ng test --watch=true --browsers=Chrome\"",
9+
"test:chrome": "npx firebase emulators:exec --project=angularfire2-test \"npx ng test --watch=false --browsers=Chrome\"",
910
"test:chrome-headless": "npx firebase emulators:exec --project=angularfire2-test \"npx ng test --watch=false --browsers=ChromeHeadless\"",
1011
"lint": "npx ng lint",
1112
"test:node": "npx tsc -p tsconfig.jasmine.json; cp ./dist/packages-dist/schematics/versions.json ./dist/out-tsc/jasmine/schematics && npx firebase emulators:exec --project=angularfire2-test \"node -r tsconfig-paths/register ./tools/jasmine.js\"",

src/analytics/analytics.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable, Inject, Optional, NgZone, InjectionToken, PLATFORM_ID } from '@angular/core';
2-
import { of, empty, throwError } from 'rxjs';
2+
import { of, empty } from 'rxjs';
33
import { isPlatformBrowser } from '@angular/common';
4-
import { map, tap, shareReplay, switchMap, catchError, observeOn } from 'rxjs/operators';
4+
import { map, tap, shareReplay, switchMap, observeOn } from 'rxjs/operators';
55
import { FirebaseAppConfig, FirebaseOptions, ɵAngularFireSchedulers, ɵlazySDKProxy, FIREBASE_OPTIONS, FIREBASE_APP_NAME, ɵfirebaseAppFactory, ɵPromiseProxy } from '@angular/fire';
66
import { analytics } from 'firebase';
77

@@ -77,8 +77,7 @@ export class AngularFireAnalytics {
7777

7878
const analytics = of(undefined).pipe(
7979
observeOn(schedulers.outsideAngular),
80-
switchMap(() => import('firebase/analytics')),
81-
catchError(err => err.message === 'Not supported' ? empty() : throwError(err) ),
80+
switchMap(() => isPlatformBrowser(platformId) ? import('firebase/analytics') : empty()),
8281
map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)),
8382
map(app => app.analytics()),
8483
tap(analytics => {
@@ -88,7 +87,7 @@ export class AngularFireAnalytics {
8887
);
8988

9089
return ɵlazySDKProxy(this, analytics, zone);
91-
90+
9291
}
9392

9493
}

src/core/angularfire2.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { TestBed, inject } from '@angular/core/testing';
22
import { PlatformRef, NgModule, CompilerFactory, NgZone } from '@angular/core';
33
import { FirebaseApp, AngularFireModule } from './public_api';
44
import { Subscription, Observable, Subject, of } from 'rxjs';
5-
import { COMMON_CONFIG } from './test-config';
5+
import { COMMON_CONFIG } from '../test-config';
66
import { BrowserModule } from '@angular/platform-browser';
77
import { database } from 'firebase/app';
88
import { ɵZoneScheduler, ɵkeepUnstableUntilFirstFactory, ɵAngularFireSchedulers } from './angularfire2';

src/database/database.spec.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ import { NgZone } from '@angular/core';
66
import 'firebase/database';
77

88
// generate random string to test fidelity of naming
9-
const APP_NAME = (Math.random() + 1).toString(36).substring(7);
9+
const rando = () => (Math.random() + 1).toString(36).substring(7);
10+
const FIREBASE_DB_NAME = 'http://localhost:9000/';
1011

1112
describe('AngularFireDatabase', () => {
1213
let app: FirebaseApp;
1314
let db: AngularFireDatabase;
1415
let zone: NgZone
16+
let firebaseAppName: string;
1517

1618
beforeEach(() => {
19+
firebaseAppName = rando();
1720
TestBed.configureTestingModule({
1821
imports: [
19-
AngularFireModule.initializeApp(COMMON_CONFIG, APP_NAME),
22+
AngularFireModule.initializeApp(COMMON_CONFIG, firebaseAppName),
2023
AngularFireDatabaseModule
21-
],
22-
providers: [
23-
{ provide: URL, useValue: 'http://localhost:9000?ns=angularfire2-test'}
2424
]
2525
});
2626
inject([FirebaseApp, AngularFireDatabase, NgZone], (app_: FirebaseApp, _db: AngularFireDatabase, _zone: NgZone) => {
@@ -50,31 +50,30 @@ describe('AngularFireDatabase', () => {
5050
});
5151

5252
it('should have an initialized Firebase app instance member', () => {
53-
expect(db.database.app.name).toEqual(APP_NAME);
53+
expect(db.database.app.name).toEqual(firebaseAppName);
5454
});
5555

5656
});
5757

5858
});
5959

60-
const FIREBASE_APP_NAME_TOO = (Math.random() + 1).toString(36).substring(7);
61-
const FIREBASE_DB_NAME = 'http://localhost:9000/';
6260
const QUERY = (Math.random() + 1).toString(36).substring(7)
6361

6462
describe('AngularFireDatabase w/options', () => {
6563
let app: FirebaseApp;
6664
let db: AngularFireDatabase;
65+
let firebaseAppName: string;
6766

6867
beforeEach(() => {
68+
firebaseAppName = rando();
6969
TestBed.configureTestingModule({
7070
imports: [
71-
AngularFireModule.initializeApp(COMMON_CONFIG, APP_NAME),
71+
AngularFireModule.initializeApp(COMMON_CONFIG, firebaseAppName),
7272
AngularFireDatabaseModule
7373
],
7474
providers: [
75-
{ provide: FIREBASE_APP_NAME, useValue: FIREBASE_APP_NAME_TOO },
76-
{ provide: FIREBASE_OPTIONS, useValue: COMMON_CONFIG },
77-
{ provide: URL, useValue: FIREBASE_DB_NAME }
75+
{ provide: FIREBASE_APP_NAME, useValue: firebaseAppName },
76+
{ provide: FIREBASE_OPTIONS, useValue: COMMON_CONFIG }
7877
]
7978
});
8079
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {
@@ -98,7 +97,7 @@ describe('AngularFireDatabase w/options', () => {
9897
});
9998

10099
it('should have an initialized Firebase app instance member', () => {
101-
expect(db.database.app.name).toEqual(FIREBASE_APP_NAME_TOO);
100+
expect(db.database.app.name).toEqual(firebaseAppName);
102101
});
103102

104103
it('database be pointing to the provided DB instance', () => {

src/database/list/audit-trail.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ describe('auditTrail', () => {
2828
imports: [
2929
AngularFireModule.initializeApp(COMMON_CONFIG, FIREBASE_APP_NAME),
3030
AngularFireDatabaseModule
31-
],
32-
providers: [
33-
{ provide: URL, useValue: 'http://localhost:9000?ns=angularfire2-test'}
3431
]
3532
});
3633
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {

src/database/list/changes.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ describe('listChanges', () => {
2828
imports: [
2929
AngularFireModule.initializeApp(COMMON_CONFIG, FIREBASE_APP_NAME),
3030
AngularFireDatabaseModule
31-
],
32-
providers: [
33-
{ provide: URL, useValue: 'http://localhost:9000?ns=angularfire2-test'}
3431
]
3532
});
3633
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {

src/database/list/snapshot-changes.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ describe('snapshotChanges', () => {
2929
imports: [
3030
AngularFireModule.initializeApp(COMMON_CONFIG, FIREBASE_APP_NAME),
3131
AngularFireDatabaseModule
32-
],
33-
providers: [
34-
{ provide: URL, useValue: 'http://localhost:9000?ns=angularfire2-test'}
3532
]
3633
});
3734
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {

src/database/list/state-changes.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ describe('stateChanges', () => {
2828
imports: [
2929
AngularFireModule.initializeApp(COMMON_CONFIG, FIREBASE_APP_NAME),
3030
AngularFireDatabaseModule
31-
],
32-
providers: [
33-
{ provide: URL, useValue: 'http://localhost:9000?ns=angularfire2-test'}
3431
]
3532
});
3633
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {

src/database/observable/fromRef.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('fromRef', () => {
2929
AngularFireDatabaseModule
3030
],
3131
providers: [
32-
{ provide: URL, useValue: 'http://localhost:9000?ns=angularfire2-test'}
32+
{ provide: URL, useValue: 'http://localhost:9000'}
3333
]
3434
});
3535
inject([FirebaseApp], (app_: FirebaseApp) => {

src/messaging/messaging.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('AngularFireMessaging', () => {
3131
});
3232

3333
it('should have the FCM instance', () => {
34-
expect(afm.messaging).toBeDefined();
34+
expect(afm.deleteToken).toBeDefined();
3535
});
3636

3737
});
@@ -71,7 +71,7 @@ describe('AngularFireMessaging with different app', () => {
7171
});
7272

7373
it('should have the FCM instance', () => {
74-
expect(afm.messaging).toBeDefined();
74+
expect(afm.deleteToken).toBeDefined();
7575
});
7676

7777
});

src/messaging/messaging.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Injectable, Inject, Optional, NgZone, PLATFORM_ID } from '@angular/core';
22
import { messaging } from 'firebase/app';
3-
import { Observable, empty, from, of, throwError } from 'rxjs';
3+
import { Observable, empty, of, throwError } from 'rxjs';
44
import { mergeMap, catchError, map, switchMap, concat, observeOn, defaultIfEmpty } from 'rxjs/operators';
55
import { FirebaseOptions, FirebaseAppConfig, ɵAngularFireSchedulers, FIREBASE_APP_NAME, FIREBASE_OPTIONS, ɵlazySDKProxy, ɵPromiseProxy } from '@angular/fire';
66
import { ɵfirebaseAppFactory } from '@angular/fire';
@@ -28,14 +28,11 @@ export class AngularFireMessaging {
2828
) {
2929
const schedulers = new ɵAngularFireSchedulers(zone);
3030

31-
// @ts-ignore zapping in the UMD in the build script
32-
const requireMessaging = from(import('firebase/messaging'));
33-
34-
const messaging = requireMessaging.pipe(
31+
const messaging = of(undefined).pipe(
3532
observeOn(schedulers.outsideAngular),
33+
switchMap(() => isPlatformServer(platformId) ? empty() : import('firebase/messaging')),
3634
map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)),
37-
map(app => app.messaging()),
38-
catchError(err => err.message === 'Not supported' ? empty() : throwError(err) )
35+
map(app => app.messaging())
3936
);
4037

4138
if (!isPlatformServer(platformId)) {

src/performance/performance.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Injectable, NgZone, ApplicationRef, InjectionToken, Inject, Optional } from '@angular/core';
2-
import { Observable, Subscription, of } from 'rxjs';
1+
import { Injectable, NgZone, ApplicationRef, InjectionToken, Inject, Optional, PLATFORM_ID } from '@angular/core';
2+
import { Observable, Subscription, of, empty } from 'rxjs';
33
import { first, tap, map, shareReplay, switchMap } from 'rxjs/operators';
44
import { performance } from 'firebase/app';
55
import { FirebaseApp, ɵPromiseProxy, ɵlazySDKProxy } from '@angular/fire';
6+
import { isPlatformBrowser } from '@angular/common';
67

78
// SEMVER @ v6, drop and move core ng metrics to a service
89
export const AUTOMATICALLY_TRACE_CORE_NG_METRICS = new InjectionToken<boolean>('angularfire2.performance.auto_trace');
@@ -32,11 +33,12 @@ export class AngularFirePerformance {
3233
@Optional() @Inject(INSTRUMENTATION_ENABLED) instrumentationEnabled:boolean|null,
3334
@Optional() @Inject(DATA_COLLECTION_ENABLED) dataCollectionEnabled:boolean|null,
3435
appRef: ApplicationRef,
35-
private zone: NgZone
36+
private zone: NgZone,
37+
@Inject(PLATFORM_ID) platformId:Object
3638
) {
3739

3840
this.performance = of(undefined).pipe(
39-
switchMap(() => zone.runOutsideAngular(() => import('firebase/performance'))),
41+
switchMap(() => isPlatformBrowser(platformId) ? zone.runOutsideAngular(() => import('firebase/performance')) : empty()),
4042
map(() => zone.runOutsideAngular(() => app.performance())),
4143
tap(performance => {
4244
if (instrumentationEnabled == false) { performance.instrumentationEnabled = false }

src/remote-config/remote-config.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Injectable, Inject, Optional, NgZone, InjectionToken } from '@angular/core';
1+
import { Injectable, Inject, Optional, NgZone, InjectionToken, PLATFORM_ID } from '@angular/core';
22
import { Observable, concat, of, pipe, OperatorFunction, MonoTypeOperatorFunction, empty, throwError } from 'rxjs';
33
import { map, switchMap, tap, shareReplay, distinctUntilChanged, filter, groupBy, mergeMap, scan, withLatestFrom, startWith, debounceTime, observeOn, catchError } from 'rxjs/operators';
44
import { ɵPromiseProxy, ɵfirebaseAppFactory, ɵAngularFireSchedulers, FirebaseAppConfig, FirebaseOptions, ɵlazySDKProxy, FIREBASE_OPTIONS, FIREBASE_APP_NAME } from '@angular/fire';
55
import { remoteConfig } from 'firebase/app';
6+
import { isPlatformBrowser } from '@angular/common';
67

78
export interface ConfigTemplate {[key:string]: string|number|boolean};
89

@@ -53,16 +54,15 @@ export class AngularFireRemoteConfig {
5354
@Optional() @Inject(FIREBASE_APP_NAME) nameOrConfig:string|FirebaseAppConfig|null|undefined,
5455
@Optional() @Inject(SETTINGS) settings:remoteConfig.Settings|null,
5556
@Optional() @Inject(DEFAULTS) defaultConfig:ConfigTemplate|null,
56-
private zone: NgZone
57+
private zone: NgZone,
58+
@Inject(PLATFORM_ID) platformId:Object
5759
) {
5860

5961
const schedulers = new ɵAngularFireSchedulers(zone);
6062

6163
const remoteConfig$ = of(undefined).pipe(
6264
observeOn(schedulers.outsideAngular),
63-
// @ts-ignore zapping in the UMD in the build script
64-
switchMap(() => zone.runOutsideAngular(() => import('firebase/remote-config'))),
65-
catchError(err => err.message === 'Not supported' ? empty() : throwError(err) ),
65+
switchMap(() => isPlatformBrowser(platformId) ? import('firebase/remote-config') : empty()),
6666
map(() => ɵfirebaseAppFactory(options, zone, nameOrConfig)),
6767
map(app => app.remoteConfig()),
6868
tap(rc => {

src/test-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const COMMON_CONFIG = {
22
apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA",
33
authDomain: "angularfire2-test.firebaseapp.com",
4-
databaseURL: "https://angularfire2-test.firebaseio.com",
4+
databaseURL: "http://localhost:9000",
55
projectId: "angularfire2-test",
66
storageBucket: "angularfire2-test.appspot.com",
77
messagingSenderId: "920323787688",

src/test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import 'zone.js/dist/zone';
44
import 'zone.js/dist/zone-testing';
5+
import 'zone.js/dist/task-tracking';
6+
57
import { getTestBed } from '@angular/core/testing';
68
import {
79
BrowserDynamicTestingModule,
@@ -17,5 +19,6 @@ getTestBed().initTestEnvironment(
1719
);
1820
// Then we find all the tests.
1921
const context = require.context('./', true, /\.spec\.ts$/);
22+
2023
// And load the modules.
2124
context.keys().map(context);

tools/build.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,18 @@ var dest = function () {
8484
var rootPackage = Promise.resolve().then(function () { return require(path_1.join(process.cwd(), 'package.json')); });
8585
function replacePackageCoreVersion() {
8686
return __awaiter(this, void 0, void 0, function () {
87-
var root, replace, result;
87+
var root, replace;
8888
return __generator(this, function (_a) {
8989
switch (_a.label) {
9090
case 0: return [4 /*yield*/, rootPackage];
9191
case 1:
9292
root = _a.sent();
9393
replace = require('replace-in-file');
94-
return [4 /*yield*/, replace({
94+
return [2 /*return*/, replace({
9595
files: dest('**', '*.js'),
9696
from: 'ANGULARFIRE2_VERSION',
9797
to: root.version
9898
})];
99-
case 2:
100-
result = _a.sent();
101-
console.log(result);
102-
return [2 /*return*/];
10399
}
104100
});
105101
});

tools/jasmine.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ require('zone.js/dist/async-test');
1515
require('zone.js/dist/sync-test');
1616
require('zone.js/dist/fake-async-test');
1717
require('zone.js/dist/proxy');
18+
require('zone.js/dist/zone-patch-rxjs');
19+
require('zone.js/dist/task-tracking');
1820

1921
const { getTestBed } = require('@angular/core/testing');
2022
const { platformServerTesting, ServerTestingModule } = require('@angular/platform-server/testing');

0 commit comments

Comments
 (0)