Skip to content

Commit 405a45b

Browse files
committed
chore(build): fix tests with new build
1 parent ef5abdf commit 405a45b

20 files changed

+142
-75
lines changed

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
*.spec.*
2-

karma.conf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ module.exports = function(config) {
2626

2727
'karma-test-shim.js',
2828
'node_modules/firebase/firebase.js',
29-
'dist/bundles/test-root.umd.{js,map}',
29+
'dist/packages-dist/bundles/core.umd.{js,map}',
30+
'dist/packages-dist/bundles/test.umd.{js,map}',
3031
],
3132

3233
port: 9876,

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
22
"name": "angularfire2",
3-
"version": "4.0.0-rc.1",
3+
"version": "4.0.0-rc.2",
44
"description": "",
55
"main": "bundles/angularfire2.umd.js",
66
"module": "index.js",
77
"scripts": {
8-
"test": "npm run build && karma start --single-run",
8+
"test": "karma start --single-run",
99
"test:watch": "concurrently \"npm run build:watch\" \"npm run delayed_karma\"",
1010
"test:debug": "npm run build && karma start",
1111
"delayed_karma": "sleep 10 && karma start",
1212
"delayed_rollup": "sleep 5 && rollup --watch -c rollup.test.config.js",
1313
"build:watch": "rm -rf dist && concurrently \"tsc -w\" \"npm run delayed_rollup\"",
14-
"build": "rm -rf dist && tsc && rollup -c rollup.test.config.js",
14+
"build": "rm -rf dist && node tools/build.js",
1515
"build_npm": "rm -rf dist && ngc -p tsconfig.publish.es6.json && rollup -c rollup.publish.config.js && npm run postbuild_npm",
1616
"build_e2e": "rm -rf dist-test && npm run build && tsc -p test/ && cp test/e2e/firebase_object/index.html dist-test/e2e/firebase_object/ && cp test/e2e/firebase_list/index.html dist-test/e2e/firebase_list/ && cp test/e2e/auth/index.html dist-test/e2e/auth/",
1717
"postbuild_npm": "cp package.json README.md .npmignore dist/ && npm run rewrite_npm_package",
@@ -74,6 +74,7 @@
7474
"reflect-metadata": "0.1.2",
7575
"rimraf": "^2.5.4",
7676
"rollup": "^0.35.11",
77+
"rollup-plugin-node-resolve": "^3.0.0",
7778
"rollup-watch": "^2.5.0",
7879
"systemjs": "^0.19.16",
7980
"systemjs-builder": "^0.15.7",

rollup.test.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export default {
44
entry: 'dist/test-root.js',
55
dest: 'dist/bundles/test-root.umd.js',
66
format: 'umd',
7-
moduleName: 'angularFire2.test',
7+
moduleName: 'angularfire2.test',
88
globals
99
}

src/auth/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './auth.spec';

src/auth/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"files": [
2727
"index.ts",
28+
"index.spec.ts",
2829
"../../node_modules/zone.js/dist/zone.js.d.ts"
2930
],
3031
"angularCompilerOptions": {

src/auth/tsconfig-test.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig-build.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"angularfire2": ["../../dist/packages-dist"]
7+
}
8+
},
9+
"files": [
10+
"index.spec.ts"
11+
]
12+
}

src/core/angularfire2.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as firebase from 'firebase/app';
22
import { TestBed, inject, withModule, async } from '@angular/core/testing';
33
import { ReflectiveInjector, Provider, PlatformRef, NgModule, Compiler, ApplicationRef, CompilerFactory } from '@angular/core';
4-
import { FirebaseApp, FirebaseAppConfig, AngularFireModule } from './angularfire2';
4+
import { FirebaseApp, FirebaseAppConfig, AngularFireModule } from 'angularfire2';
55
import { Subscription } from 'rxjs/Subscription';
66
import { COMMON_CONFIG } from './test-config';
77
import { BrowserModule } from '@angular/platform-browser';

src/core/index.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './angularfire2.spec';

src/core/tsconfig-test.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig-esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"angularfire2": ["../../dist/packages-dist"]
7+
}
8+
},
9+
"files": [
10+
"index.spec.ts"
11+
]
12+
}

src/database/firebase_list_factory.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,8 @@ describe('FirebaseListFactory', () => {
578578

579579
it('should call off on all events when disposed', (done: any) => {
580580
const questionRef = app.database().ref().child('questions');
581-
let firebaseSpy = spyOn(questionRef, 'off').and.callThrough();
582581
subscription = FirebaseListFactory(questionRef).subscribe(_ => {
582+
let firebaseSpy = spyOn(questionRef, 'off').and.callThrough();
583583
expect(firebaseSpy).not.toHaveBeenCalled();
584584
subscription.unsubscribe();
585585
expect(firebaseSpy).toHaveBeenCalled();

src/database/index.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './firebase_list_factory.spec';
2+
import './firebase_object_factory.spec';
3+
import './firebase_list_observable.spec';
4+
import './firebase_object_observable.spec';
5+
import './query_observable.spec';

src/database/tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
},
2626
"files": [
2727
"index.ts",
28+
"index.spec.ts",
2829
"../../node_modules/zone.js/dist/zone.js.d.ts"
2930
],
3031
"angularCompilerOptions": {

src/database/tsconfig-test.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"extends": "./tsconfig-build.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"paths": {
6+
"angularfire2": ["../../dist/packages-dist"]
7+
}
8+
},
9+
"files": [
10+
"index.spec.ts"
11+
]
12+
}

src/root.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// These paths are written to use the dist build
2+
export * from './packages-dist/angularfire2.spec';
3+
export * from './packages-dist/database/firebase_list_factory.spec';
4+
export * from './packages-dist/database/firebase_object_factory.spec';
5+
export * from './packages-dist/database/firebase_list_observable.spec';
6+
export * from './packages-dist/database/firebase_object_observable.spec';
7+
export * from './packages-dist/database/query_observable.spec';
8+
export * from './packages-dist/auth/auth.spec';

src/test-root.ts

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

src/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"angularfire2": ["./core"],
5+
"angularfire2/auth": ["./auth"],
6+
"angularfire2/database": ["./database"]
7+
}
8+
}
9+
}

tools/build.js

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ const { Observable } = require('rxjs');
44
const { copy, readFileSync, writeFile } = require('fs-extra');
55
const { prettySize } = require('pretty-size');
66
const gzipSize = require('gzip-size');
7+
const resolve = require('rollup-plugin-node-resolve');
78

89
// Rollup globals
910
const GLOBALS = {
11+
'rxjs': 'Rx',
1012
'rxjs/Observable': 'Rx',
1113
'rxjs/Subject': 'Rx',
1214
'rxjs/Observer': 'Rx',
@@ -18,8 +20,14 @@ const GLOBALS = {
1820
'rxjs/operator/combineLatest': 'Rx.Observable.prototype',
1921
'rxjs/operator/merge': 'Rx.Observable.prototype',
2022
'rxjs/operator/map': 'Rx.Observable.prototype',
23+
'rxjs/observable/of': 'Rx.Observable',
2124
'rxjs/operator/auditTime': 'Rx.Observable.prototype',
2225
'rxjs/operator/switchMap': 'Rx.Observable.prototype',
26+
'rxjs/operator/do': 'Rx.Observable.prototype',
27+
'rxjs/operator/skip': 'Rx.Observable.prototype',
28+
'rxjs/operator/take': 'Rx.Observable.prototype',
29+
'rxjs/operator/toArray': 'Rx.Observable.prototype',
30+
'rxjs/operator/toPromise': 'Rx.Observable.prototype',
2331
'rxjs/operator': 'Rx.Observable.prototype',
2432
'@angular/core': 'ng.core',
2533
'@angular/compiler': 'ng.compiler',
@@ -29,7 +37,9 @@ const GLOBALS = {
2937
'firebase/database': 'firebase',
3038
'rxjs/scheduler/queue': 'Rx.Scheduler',
3139
'@angular/core/testing': 'ng.core.testing',
32-
'angularfire2': 'angularfire2'
40+
'angularfire2': 'angularfire2',
41+
'angularfire2/auth': 'angularfire2.auth',
42+
'angularfire2/database': 'angularfire2.database'
3343
};
3444

3545
// Map of dependency versions across all packages
@@ -45,6 +55,7 @@ const VERSIONS = {
4555
const TSC = 'node_modules/.bin/tsc';
4656
const NGC = 'node_modules/.bin/ngc';
4757
const TSC_ARGS = (name, config = 'build') => [`-p`, `${process.cwd()}/src/${name}/tsconfig-${config}.json`];
58+
const TSC_TEST_ARGS = [`-p`, `${process.cwd()}/src/tsconfig-test.json`];
4859

4960
/**
5061
* Create an Observable of a spawned child process.
@@ -61,33 +72,53 @@ function spawnObservable(command, args) {
6172
});
6273
}
6374

75+
function generateBundle(entry, { dest, globals, moduleName }) {
76+
return rollup({ entry }).then(bundle => {
77+
return bundle.write({
78+
format: 'umd',
79+
external: Object.keys(globals),
80+
plugins: [resolve()],
81+
dest,
82+
globals,
83+
moduleName,
84+
});
85+
});
86+
}
87+
6488
/**
65-
* Create a UMD bundle given a module name
89+
* Create a UMD bundle given a module name.
6690
* @param {string} name
6791
* @param {Object} globals
6892
*/
6993
function createUmd(name, globals) {
7094
// core module is angularfire2 the rest are angularfire2.feature
71-
const moduleName = name === 'core' ? 'angularfire2' : `angularfire2.${name}`;
72-
// core is at the root and the rest are in their own folders
73-
const entry = name === 'core' ? `${process.cwd()}/dist/packages-dist/index.js` :
74-
`${process.cwd()}/dist/packages-dist/${name}/index.js`;
75-
return rollup({ entry })
76-
.then(bundle => {
77-
const result = bundle.generate({
78-
format: 'umd',
79-
external: Object.keys(globals),
80-
globals,
81-
moduleName
82-
});
83-
return bundle.write({
84-
format: 'umd',
85-
dest: `${process.cwd()}/dist/packages-dist/bundles/${name}.umd.js`,
86-
external: Object.keys(globals),
87-
globals,
88-
moduleName
89-
});
90-
});
95+
const MODULE_NAMES = {
96+
core: 'angularfire2',
97+
auth: 'angularfire2.auth',
98+
database: 'angularfire2.database',
99+
};
100+
const ENTRIES = {
101+
core: `${process.cwd()}/dist/packages-dist/index.js`,
102+
auth: `${process.cwd()}/dist/packages-dist/auth/index.js`,
103+
database: `${process.cwd()}/dist/packages-dist/database/index.js`,
104+
};
105+
const moduleName = MODULE_NAMES[name];
106+
const entry = ENTRIES[name];
107+
return generateBundle(entry, {
108+
dest: `${process.cwd()}/dist/packages-dist/bundles/${name}.umd.js`,
109+
globals,
110+
moduleName
111+
});
112+
}
113+
114+
function createTestUmd(globals) {
115+
const entry = `${process.cwd()}/dist/root.spec.js`;
116+
const moduleName = 'angularfire2.test';
117+
return generateBundle(entry, {
118+
dest: `${process.cwd()}/dist/packages-dist/bundles/test.umd.js`,
119+
globals,
120+
moduleName
121+
});
91122
}
92123

93124
/**
@@ -133,7 +164,7 @@ function replaceVersionsObservable(name, versions) {
133164
});
134165
const outPath = getDestPackageFile(name);
135166
writeFile(outPath, pkg, err => {
136-
if(err) {
167+
if (err) {
137168
observer.error(err);
138169
} else {
139170
observer.next(pkg);
@@ -147,6 +178,10 @@ function copyPackage(moduleName) {
147178
return copy(getSrcPackageFile(moduleName), getDestPackageFile(moduleName));
148179
}
149180

181+
function copyRootTest() {
182+
return copy(`${process.cwd()}/src/root.spec.js`, `${process.cwd()}/dist/root.spec.js`);
183+
}
184+
150185
function measure(module, gzip = true) {
151186
const path = `${process.cwd()}/dist/packages-dist/bundles/${module}.umd.js`;
152187
const file = readFileSync(path);
@@ -157,18 +192,19 @@ function measure(module, gzip = true) {
157192
function buildModule(name, globals) {
158193
const es2015$ = spawnObservable(NGC, TSC_ARGS(name));
159194
const esm$ = spawnObservable(NGC, TSC_ARGS(name, 'esm'));
195+
const test$ = spawnObservable(TSC, TSC_ARGS(name, 'test'));
160196
return Observable
161-
.forkJoin(es2015$, esm$)
197+
.forkJoin(es2015$, esm$, test$)
162198
.switchMap(() => Observable.from(createUmd(name, globals)))
163199
.switchMap(() => replaceVersionsObservable(name, VERSIONS));
164200
}
165201

166-
function buildLibrary(globals) {
202+
function buildModules(globals) {
167203
const core$ = buildModule('core', globals);
168204
const auth$ = buildModule('auth', globals);
169205
const db$ = buildModule('database', globals);
170206
return Observable
171-
.forkJoin(core$)
207+
.forkJoin(core$, Observable.from(copyRootTest()))
172208
.switchMapTo(auth$)
173209
.switchMapTo(db$)
174210
.do(() => {
@@ -180,7 +216,14 @@ function buildLibrary(globals) {
180216
});
181217
}
182218

183-
const $lib = buildLibrary(GLOBALS).subscribe(
219+
function buildLibrary(globals) {
220+
const modules$ = buildModules(globals);
221+
return Observable
222+
.forkJoin(modules$)
223+
.switchMap(() => Observable.from(createTestUmd(globals)));
224+
}
225+
226+
buildLibrary(GLOBALS).subscribe(
184227
data => { console.log('data', data) },
185228
err => { console.log('err', err) },
186229
() => { console.log('complete') }

tools/run-typings-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ncp(pathToTestSrcFolder, pathToTestFolder, () => {
2828
const samplePackage = require(`${pathToTestFolder}/package.sample.json`);
2929

3030
fs.writeFileSync(`${pathToTestFolder}/package.json`, JSON.stringify(samplePackage, null, 2)
31-
.replace('{{ANGULARFIRE_VERSION}}', path.resolve(__dirname, '../dist'))
31+
.replace('{{ANGULARFIRE_VERSION}}', path.resolve(__dirname, '../dist/packages-dist'))
3232
.replace('{{FIREBASE_VERSION}}', rootPackage.dependencies.firebase)
3333
.replace('{{RXJS_VERSION}}', rootPackage.dependencies.rxjs)
3434
.replace('{{ZONE_VERSION}}', rootPackage.devDependencies['zone.js'])

tsconfig.json

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

0 commit comments

Comments
 (0)