Skip to content

Commit d0e3fb9

Browse files
committed
test(e2e): add more testing tools and auth e2e test
1 parent 5fe4f54 commit d0e3fb9

21 files changed

+326
-97
lines changed

.gitignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
node_modules/
22
dist/
3+
dist-test/
34
docs/api/
45
typings/
56
npm-debug.log
67
.idea/
7-
test/e2e/firebase_list/firebase_list_example.js
8-
test/e2e/firebase_list/firebase_list_example.js.map
9-
test/e2e/firebase_list/firebase_list_example.d.ts
10-
test/e2e/firebase_object/firebase_object_example.js
11-
test/e2e/firebase_object/firebase_object_example.js.map
12-
test/e2e/firebase_object/firebase_object_example.d.ts
8+
.vscode/settings.json

karma.conf.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ module.exports = function(config) {
3636

3737
{pattern: 'node_modules/firebase/firebase.js', included: false, watched: false},
3838
{pattern: 'dist/**/*.js', included: false, watched: true},
39-
{pattern: 'dist/**/*.js.map', included: false, watched: false}
39+
{pattern: 'dist/**/*.js.map', included: false, watched: false},
40+
{pattern: 'src/**/*.ts', included: false, watched: false}
4041
],
41-
42-
reporters: ['mocha'],
42+
4343
port: 9876,
4444
colors: true,
4545
logLevel: config.LOG_INFO,

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
"test": "npm run build; karma start",
99
"docs": "typedoc --out docs/api/ --module commonjs --mode modules --name AngularFire2 src",
1010
"build": "rm -rf dist; tsc",
11-
"build_npm": "rm -rf dist && tsc -p tsconfig.publish.es5.json && tsc -p tsconfig.publish.es6.json",
12-
"postbuild_npm": "cp package.json README.md .npmignore dist/ && npm run rewrite_npm_package",
13-
"postinstall": "typings install",
11+
"build_npm": "rm -rf dist && ./node_modules/.bin/tsc -p tsconfig.publish.es5.json && ./node_modules/.bin/tsc -p tsconfig.publish.es6.json",
12+
"postbuild_npm": "cp manual_typings/firebase3/firebase3.d.ts package.json README.md .npmignore dist/ && npm run rewrite_npm_package",
1413
"rewrite_npm_package": "node --harmony_destructuring tools/rewrite-published-package.js",
15-
"build_bundle": "cp -r src angularfire2 && tsc typings/main.d.ts angularfire2.ts --rootDir . --module system -t es5 --outFile dist/bundles/angularfire2.js --moduleResolution node --emitDecoratorMetadata --experimentalDecorators"
14+
"build_bundle": "cp -r src angularfire2 && tsc typings/main.d.ts angularfire2.ts --rootDir . --module system -t es5 --outFile dist/bundles/angularfire2.js --moduleResolution node --emitDecoratorMetadata --experimentalDecorators",
15+
"e2e_test": "webdriver-manager update && npm run build_e2e && protractor",
16+
"build_e2e": "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/"
1617
},
1718
"keywords": [
1819
"angular2",
@@ -63,7 +64,7 @@
6364
"traceur": "0.0.96",
6465
"tsd": "^0.6.5",
6566
"typedoc": "github:jeffbcross/typedoc",
66-
"typescript": "1.8.9",
67+
"typescript": "^1.9.0-dev.20160608-1.0",
6768
"typings": "^0.6.2",
6869
"zone.js": "^0.6.6"
6970
},

protractor.conf.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var httpServer = require('http-server');
22
// An example configuration file.
33
exports.config = {
4-
baseUrl: 'http://localhost:8080/test/e2e/',
4+
baseUrl: 'http://localhost:8080/%3Cspan%20class="x x-first x-last">dist-test/e2e/',
55

66
directConnect: true,
77
// seleniumAddress: 'http://localhost:4444/wd/hub',
@@ -16,7 +16,7 @@ exports.config = {
1616

1717
// Spec patterns are relative to the current working directly when
1818
// protractor is called.
19-
specs: ['test/e2e/**/*.spec.js'],
19+
specs: ['dist-test/**/*.spec.js'],
2020
allScriptsTimeout: 110000,
2121

2222
onPrepare: function() {
@@ -26,7 +26,6 @@ exports.config = {
2626
httpServer.createServer({
2727
showDir: false
2828
}).listen('8080', 'localhost');
29-
require('./tools/test-server');
3029
},
3130
// Options to be passed to Jasmine.
3231
jasmineNodeOpts: {

src/test-config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const COMMON_CONFIG = {
2+
apiKey: "AIzaSyBVSy3YpkVGiKXbbxeK0qBnu3-MNZ9UIjA",
3+
authDomain: "angularfire2-test.firebaseapp.com",
4+
databaseURL: "https://angularfire2-test.firebaseio.com",
5+
storageBucket: "angularfire2-test.appspot.com",
6+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { waitForElement } from '../shared';
2+
3+
describe('FirebaseList', () => {
4+
it('should login anonymously', () => {
5+
browser.get('auth/index.html');
6+
waitForElement('#is-anonymous');
7+
var isAnonymous = $('#is-anonymous');
8+
expect(isAnonymous.getText()).toBe('');
9+
var login = $('#login-anonymous');
10+
login.click();
11+
browser.sleep(1000);
12+
expect(isAnonymous.getText()).toBe('true');
13+
});
14+
});
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import {Component, enableProdMode, Inject, provide} from '@angular/core';
2+
import {bootstrap} from '@angular/platform-browser-dynamic';
3+
import {
4+
AuthMethods,
5+
AuthProviders,
6+
defaultFirebase,
7+
AngularFire,
8+
FIREBASE_PROVIDERS,
9+
FirebaseListObservable,
10+
FirebaseApp
11+
} from '../../../dist/angularfire2';
12+
13+
enableProdMode();
14+
15+
import { COMMON_CONFIG } from '../../../src/test-config';
16+
17+
@Component({
18+
template: `
19+
<button id="logout" (click)="af.auth.logout()">Logout</button>
20+
<br><br>
21+
<blockquote>
22+
<h1>Anonymous Login</h1>
23+
<button id="login-anonymous" (click)="signInAnonymously()">Login Anonymously</button>
24+
25+
<p>
26+
Is Anonymous?
27+
<span id="is-anonymous">
28+
{{ user?.isAnonymous }}
29+
</span>
30+
</p>
31+
</blockquote>
32+
<blockquote class="oauth">
33+
<h1>OAuth Login</h1>
34+
35+
36+
<h2>OAuth Provider</h2>
37+
<select id="authProvider" #authProvider>
38+
<option selected>Twitter</option>
39+
<option>Facebook</option>
40+
<option>Google</option>
41+
<option>Github</option>
42+
</select>
43+
44+
<p>
45+
<label for="redirect">Redirect?</label>
46+
<input id="redirect" #redirect type="checkbox">
47+
</p>
48+
49+
<p>
50+
<button (click)="signInWithOAuth(redirect.checked, authProvider.value)">
51+
Sign In
52+
</button>
53+
</p>
54+
</blockquote>
55+
56+
<blockquote>
57+
<h1>Create User</h1>
58+
<input #createEmail type="email" placeholder="[email protected]">
59+
<input #createPassword type="password" placeholder="password">
60+
<button (click)="createUser(createEmail.value, createPassword.value)">Create</button>
61+
</blockquote>
62+
63+
<blockquote>
64+
<h1>Email and Password Login</h1>
65+
<input #loginEmail type="email" placeholder="[email protected]">
66+
<input #loginPassword type="password" placeholder="password">
67+
<button (click)="loginUser(loginEmail.value, loginPassword.value)">Login</button>
68+
</blockquote>
69+
70+
<blockquote>
71+
<h1>Custom Token Login</h1>
72+
<textarea #customToken type="text" placeholder="token"></textarea>
73+
<button (click)="signInWithCustomToken(customToken.value)">Login</button>
74+
</blockquote>
75+
76+
<hr>
77+
78+
<blockquote>
79+
<h2>Provider Data</h2>
80+
{{ user?.providerData && user.providerData[0] | json }}
81+
<span *ngIf="!user || !user.providerData">Not Logged In</span>
82+
</blockquote>
83+
`,
84+
selector: 'app'
85+
})
86+
class App {
87+
user: any;
88+
questions: FirebaseListObservable<any>;
89+
constructor(public af: AngularFire) {
90+
af.auth.onAuth()
91+
.subscribe(user => {
92+
console.log('onAuth', user);
93+
this.user = user
94+
});
95+
}
96+
97+
signInAnonymously() {
98+
this.af.auth.login({
99+
method: AuthMethods.Anonymous
100+
})
101+
.then((user) => console.log(`Anonymous Login Success:`, user))
102+
.catch(e => console.error(`Anonymous Login Failure:`, e));
103+
}
104+
105+
signInWithOAuth(redirect: boolean, provider: string) {
106+
this.af.auth.login({
107+
method: redirect ? AuthMethods.Redirect : AuthMethods.Popup,
108+
provider: (<any>AuthProviders)[provider]
109+
})
110+
.then((user) => console.log(`${provider} Login Success:`, user))
111+
.catch(e => console.error(`${provider} Login Failure:`, e));
112+
}
113+
114+
createUser(email: string, password: string) {
115+
this.af.auth.createUser({ email, password })
116+
.then((user) => console.log(`Create User Success:`, user))
117+
.catch(e => console.error(`Create User Failure:`, e));
118+
}
119+
120+
loginUser(email: string, password: string) {
121+
this.af.auth.login({ email, password }, {
122+
method: AuthMethods.Password,
123+
provider: AuthProviders.Password
124+
})
125+
.then((user) => console.log(`Password Login Success:`, user))
126+
.catch(e => console.error(`Password Login Failure:`, e));
127+
}
128+
129+
signInWithCustomToken(token: string) {
130+
// TODO: this.af.auth.login({ token });
131+
}
132+
}
133+
134+
bootstrap(App, [
135+
FIREBASE_PROVIDERS,
136+
defaultFirebase(COMMON_CONFIG)]).then(() => {
137+
console.log('bootstrap success');
138+
}, (e:any) => {
139+
console.error('bootstrap failed', e);
140+
});

test/e2e/auth/index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
<script src="/node_modules/systemjs/dist/system.src.js"></script>
4+
<script src="/node_modules/reflect-metadata/Reflect.js"></script>
5+
<script src="/node_modules/zone.js/dist/zone.js"></script>
6+
<script src="../system.config.js"></script>
7+
</head>
8+
<body>
9+
<app></app>
10+
<script>
11+
System.import('./firebase_auth_example.js');
12+
</script>
13+
</body>
14+
</html>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { waitForElement } from '../shared';
2+
3+
describe('FirebaseList', () => {
4+
it('should render', () => {
5+
browser.get('firebase_list/index.html');
6+
waitForElement('app');
7+
var app = $('app');
8+
browser.sleep(500);
9+
expect(app.getText()).toBe(`Hello
10+
why?
11+
how?`);
12+
});
13+
});

test/e2e/firebase_list/firebase_list_example.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,40 @@
11
import {Component, enableProdMode, Inject, provide} from '@angular/core';
22
import {bootstrap} from '@angular/platform-browser-dynamic';
3-
import {defaultFirebase, AngularFire, FIREBASE_PROVIDERS, FirebaseListObservable} from 'angularfire2';
4-
import * as Firebase from 'firebase';
3+
import {
4+
defaultFirebase,
5+
AngularFire,
6+
FIREBASE_PROVIDERS,
7+
FirebaseListObservable,
8+
FirebaseApp
9+
} from 'angularfire2';
510

611
enableProdMode();
712

8-
const rootFirebase = 'https://angularfire2.firebaseio-demo.com/%3C/span%3E';
13+
import { COMMON_CONFIG } from '../../../src/test-config';
914

1015
@Component({
1116
template: `
1217
<h1>Hello</h1>
13-
<div *ngFor="#question of questions | async">
18+
<div *ngFor="let question of questions | async">
1419
{{question.question}}
1520
</div>
1621
`,
1722
selector: 'app'
1823
})
1924
class App {
2025
questions:FirebaseListObservable<any>;
21-
constructor(public af:AngularFire) {
22-
var ref = new Firebase(rootFirebase);
26+
constructor(public af:AngularFire, @Inject(FirebaseApp) app: firebase.app.App) {
27+
var ref = app.database().ref();
2328
ref.remove();
24-
this.questions = af.list('/questions');
25-
this.questions.add({question: 'why?'});
26-
this.questions.add({question: 'how?'});
29+
this.questions = af.database.list('/questions');
30+
this.questions.push({question: 'why?'});
31+
this.questions.push({question: 'how?'});
2732
}
2833
}
2934

3035
bootstrap(App, [
3136
FIREBASE_PROVIDERS,
32-
defaultFirebase(rootFirebase)]).then(() => {
37+
defaultFirebase(COMMON_CONFIG)]).then(() => {
3338
console.log('bootstrap success');
3439
}, (e:any) => {
3540
console.error('bootstrap failed', e);

0 commit comments

Comments
 (0)