Skip to content

Commit e31d8df

Browse files
committed
Getting testing working locally
1 parent c2a8972 commit e31d8df

38 files changed

+3019
-4498
lines changed

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
*.spec.*
2-
bundles/test.umd.js
2+
testing
33
test-config.*

angular.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"@angular/fire": {
7+
"projectType": "library",
8+
"root": "src",
9+
"sourceRoot": "projects/example-ng6-lib/src",
10+
"prefix": "angularfire",
11+
"architect": {
12+
"build": {
13+
"builder": "@angular-devkit/build-ng-packagr:build",
14+
"options": {
15+
"tsConfig": "tsconfig.lib.json",
16+
"project": "src/package.json"
17+
}
18+
},
19+
"test": {
20+
"builder": "@angular-devkit/build-angular:karma",
21+
"options": {
22+
"main": "src/test.ts",
23+
"tsConfig": "tsconfig.spec.json",
24+
"karmaConfig": "karma.conf.js"
25+
}
26+
},
27+
"lint": {
28+
"builder": "@angular-devkit/build-angular:tslint",
29+
"options": {
30+
"tsConfig": [
31+
"tsconfig.lib.json",
32+
"tsconfig.spec.json"
33+
],
34+
"exclude": [
35+
"**/node_modules/**"
36+
]
37+
}
38+
}
39+
}
40+
}},
41+
"defaultProject": "@angular/fire"
42+
}

karma-test-shim.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

karma.conf.js

Lines changed: 22 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,31 @@
1-
// Karma configuration
2-
module.exports = function(config) {
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
module.exports = function (config) {
34
config.set({
4-
55
basePath: '',
6-
7-
frameworks: ['jasmine'],
8-
9-
files: [
10-
// Polyfills.
11-
'node_modules/es6-shim/es6-shim.js',
12-
13-
'node_modules/reflect-metadata/Reflect.js',
14-
15-
// Zone.js dependencies
16-
'node_modules/zone.js/dist/zone.js',
17-
'node_modules/zone.js/dist/proxy.js',
18-
'node_modules/zone.js/dist/sync-test.js',
19-
'node_modules/zone.js/dist/jasmine-patch.js',
20-
'node_modules/zone.js/dist/async-test.js',
21-
'node_modules/zone.js/dist/fake-async-test.js',
22-
23-
'node_modules/rxjs/bundles/rxjs.umd.{js,map}',
24-
25-
...getAngularFiles(['core','common','compiler','platform-browser','platform-browser-dynamic']),
26-
27-
'karma-test-shim.js',
28-
'node_modules/firebase/firebase-app.js',
29-
'node_modules/firebase/firebase-auth.js',
30-
'node_modules/firebase/firebase-database.js',
31-
'node_modules/firebase/firebase-firestore.js',
32-
'node_modules/firebase/firebase-functions.js',
33-
'node_modules/firebase/firebase-performance.js',
34-
'node_modules/firebase/firebase-storage.js',
35-
'dist/packages-dist/bundles/angular-fire.umd.{js,map}',
36-
'dist/packages-dist/bundles/angular-fire-auth.umd.{js,map}',
37-
'dist/packages-dist/bundles/angular-fire-auth-guard.umd.{js,map}',
38-
'dist/packages-dist/bundles/angular-fire-database.umd.{js,map}',
39-
'dist/packages-dist/bundles/angular-fire-firestore.umd.{js,map}',
40-
'dist/packages-dist/bundles/angular-fire-functions.umd.{js,map}',
41-
'dist/packages-dist/bundles/angular-fire-storage.umd.{js,map}',
42-
'dist/packages-dist/bundles/angular-fire-performance.umd.{js,map}',
43-
'dist/packages-dist/bundles/angular-fire-database-deprecated.umd.{js,map}',
44-
'dist/packages-dist/bundles/angular-fire-testing.umd.{js,map}',
6+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
7+
plugins: [
8+
require('karma-jasmine'),
9+
require('karma-chrome-launcher'),
10+
require('karma-jasmine-html-reporter'),
11+
require('karma-coverage-istanbul-reporter'),
12+
require('@angular-devkit/build-angular/plugins/karma')
4513
],
46-
14+
client: {
15+
clearContext: false // leave Jasmine Spec Runner output visible in browser
16+
},
17+
coverageIstanbulReporter: {
18+
dir: require('path').join(__dirname, '../../coverage/example-ng6-lib'),
19+
reports: ['html', 'lcovonly'],
20+
fixWebpackSourcePaths: true
21+
},
22+
reporters: ['progress', 'kjhtml'],
4723
port: 9876,
4824
colors: true,
4925
logLevel: config.LOG_INFO,
5026
autoWatch: true,
51-
reporters: ['mocha'],
52-
browsers: ['ChromeHeadless'],
27+
browsers: ['Chrome'],
5328
singleRun: false,
54-
customLaunchers: {
55-
ChromeHeadlessTravis: {
56-
base: 'ChromeHeadless',
57-
flags: ['--no-sandbox']
58-
}
59-
},
60-
})
29+
restartOnFileChange: true
30+
});
6131
};
62-
63-
function getAngularFiles(packages) {
64-
return packages.reduce((files, pkg) => {
65-
files.push(`node_modules/@angular/${pkg}/bundles/${pkg}.umd.js`);
66-
files.push(`node_modules/@angular/${pkg}/bundles/${pkg}-testing.umd.js`);
67-
return files;
68-
}, []);
69-
}

package.json

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@
44
"description": "The official library of Firebase and Angular.",
55
"private": true,
66
"scripts": {
7-
"test": "npm run build && karma start --single-run",
7+
"test": "npm run build && npx ng test",
88
"test:node": "jasmine 'dist/packages-dist/schematics/**/*[sS]pec.js'",
9-
"test:watch": "concurrently \"npm run build:watch\" \"npm run delayed_karma\"",
10-
"test:debug": "npm run build && karma start",
11-
"karma": "karma start",
129
"test:universal": "npm run build && cp -R dist/packages-dist test/universal-test/node_modules/angularfire2 && cd test/universal-test && npm run prerender",
13-
"delayed_karma": "sleep 10 && karma start",
1410
"build": "tsc tools/build.ts; node ./tools/build.js",
1511
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"
1612
},
@@ -56,49 +52,37 @@
5652
"utf-8-validate": "~4.0.0"
5753
},
5854
"devDependencies": {
55+
"@angular-devkit/build-angular": "^0.800.3",
5956
"@angular/animations": ">=6.0.0 <9 || ^9.0.0-0",
57+
"@angular/cli": "^8.0.3",
6058
"@angular/compiler-cli": ">=6.0.0 <9 || ^9.0.0-0",
6159
"@angular/platform-server": ">=6.0.0 <9 || ^9.0.0-0",
6260
"@types/fs-extra": "^7.0.0",
6361
"@types/gzip-size": "^5.1.1",
6462
"@types/inquirer": "^0.0.44",
65-
"@types/jasmine": "^2.5.36",
63+
"@types/jasmine": "^3.3.13",
6664
"@types/request": "0.0.30",
67-
"@types/rollup-plugin-node-resolve": "^4.1.0",
6865
"concurrently": "^2.2.0",
6966
"conventional-changelog-cli": "^1.2.0",
70-
"es6-module-loader": "^0.17.10",
71-
"es6-shim": "^0.35.0",
7267
"fs-extra": "^8.0.1",
73-
"gulp": "^3.9.0",
74-
"gulp-jasmine": "^2.2.1",
75-
"gulp-typescript": "^2.10.0",
7668
"gzip-size": "^5.1.1",
77-
"http-server": "^0.8.5",
78-
"jasmine": "^2.4.1",
79-
"jasmine-core": "^2.4.1",
80-
"json": "^9.0.3",
81-
"karma": "^2.0.0",
69+
"jasmine": "^3.4.0",
70+
"jasmine-core": "^3.4.0",
71+
"karma": "^4.1.0",
8272
"karma-chrome-launcher": "^2.2.0",
83-
"karma-firefox-launcher": "^1.1.0",
84-
"karma-jasmine": "^0.3.6",
85-
"karma-mocha-reporter": "^2.0.2",
86-
"karma-systemjs": "^0.10.0",
73+
"karma-coverage-istanbul-reporter": "^2.0.5",
74+
"karma-jasmine": "^2.0.1",
75+
"karma-jasmine-html-reporter": "^1.4.2",
8776
"ncp": "^2.0.0",
8877
"ng-packagr": "^5.3.0",
89-
"parse5": "^1.3.2",
9078
"pretty-size": "^2.0.0",
9179
"protractor": "3.0.0",
9280
"reflect-metadata": "0.1.2",
9381
"rimraf": "^2.5.4",
9482
"rollup": "^1.15.6",
9583
"rollup-plugin-node-resolve": "^5.0.3",
96-
"rollup-watch": "^4.3.1",
9784
"schematics-utilities": "^1.1.1",
98-
"shelljs": "^0.8.0",
99-
"systemjs": "^0.19.16",
100-
"systemjs-builder": "^0.15.7",
101-
"traceur": "0.0.96",
85+
"tsickle": "^0.35.0",
10286
"typescript": ">=3.4.0 <3.5.0"
10387
},
10488
"typings": "index.d.ts"

src/auth-guard/auth-guard.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { TestBed, inject } from '@angular/core/testing';
22
import { FirebaseApp, AngularFireModule } from '@angular/fire';
3-
import { COMMON_CONFIG } from './test-config';
3+
import { COMMON_CONFIG } from '../test-config';
44
import { AngularFireAuthModule } from '@angular/fire/auth';
55
import { AngularFireAuthGuardModule, AngularFireAuthGuard } from '@angular/fire/auth-guard';
66
import { RouterModule, Router } from '@angular/router';

src/auth-guard/auth-guard.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Injectable, InjectionToken } from '@angular/core';
22
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
33
import { Observable, of, pipe, UnaryFunction } from 'rxjs';
4-
import { map, switchMap, take } from 'rxjs/operators'
4+
import { map, switchMap, take, tap } from 'rxjs/operators'
55
import { User, auth } from 'firebase/app';
66
import { AngularFireAuth } from '@angular/fire/auth';
77

@@ -13,12 +13,12 @@ export class AngularFireAuthGuard implements CanActivate {
1313

1414
constructor(private afAuth: AngularFireAuth, private router: Router) {}
1515

16-
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
16+
canActivate = (next: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
1717
const authPipeFactory: AuthPipeGenerator = next.data.authGuardPipe || (() => loggedIn);
1818
return this.afAuth.user.pipe(
1919
take(1),
2020
authPipeFactory(next, state),
21-
map(canActivate => typeof canActivate == "boolean" ? canActivate : this.router.createUrlTree(canActivate))
21+
map(can => typeof can == "boolean" ? can : this.router.createUrlTree(<any[]>can))
2222
);
2323
}
2424

src/auth/auth.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Observable, Subject } from 'rxjs'
33
import { TestBed, inject } from '@angular/core/testing';
44
import { FirebaseApp, FirebaseOptionsToken, AngularFireModule, FirebaseNameOrConfigToken } from '@angular/fire';
55
import { AngularFireAuth, AngularFireAuthModule } from '@angular/fire/auth';
6-
import { COMMON_CONFIG } from './test-config';
6+
import { COMMON_CONFIG } from '../test-config';
77
import { take, skip } from 'rxjs/operators';
88

99
function authTake(auth: Observable<any>, count: number): Observable<any> {
@@ -38,10 +38,12 @@ describe('AngularFireAuth', () => {
3838
})();
3939

4040
mockAuthState = new Subject<User>();
41+
//@ts-ignore
4142
spyOn(afAuth, 'authState').and.returnValue(mockAuthState);
43+
//@ts-ignore
4244
spyOn(afAuth, 'idToken').and.returnValue(mockAuthState);
43-
afAuth.authState = mockAuthState as Observable<User>;
44-
afAuth.idToken = mockAuthState as Observable<User>;
45+
(<any>afAuth).authState = mockAuthState as Observable<User>;
46+
(<any>afAuth).idToken = mockAuthState as Observable<User>;
4547
});
4648

4749
afterEach(done => {
@@ -112,7 +114,7 @@ describe('AngularFireAuth', () => {
112114
count = count + 1;
113115
mockAuthState.next(firebaseUser);
114116
} else {
115-
expect(user).toEqual(firebaseUser);
117+
expect(<any>user).toEqual(firebaseUser);
116118
subs.unsubscribe();
117119
done();
118120
}

src/core/angularfire2.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { TestBed, inject } from '@angular/core/testing';
22
import { PlatformRef, NgModule, CompilerFactory } from '@angular/core';
33
import { FirebaseApp, AngularFireModule } from '@angular/fire';
44
import { Subscription } 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';
8+
import 'firebase/database';
89

910
describe('angularfire', () => {
1011
let subscription:Subscription;

src/core/angularfire2.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ export class FirebaseZoneScheduler {
1515
if (isPlatformServer(this.platformId)) {
1616
return new Observable<T>(subscriber => {
1717
const noop = () => {};
18-
const task = global['Zone'].current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop);
18+
// @ts-ignore
19+
const task = Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop);
1920
obs$.subscribe(
2021
next => {
2122
if (task.state === 'scheduled') { task.invoke() };

src/core/firebase.app.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class FirebaseApp {
3030
delete: () => Promise<void>;
3131
firestore: () => FirebaseFirestore;
3232
functions: (region?: string) => FirebaseFunctions;
33+
installations: () => any; // SEMVER: drop once we can target
3334
}
3435

3536
export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: string|FirebaseAppConfig|null) {

0 commit comments

Comments
 (0)