Skip to content

Commit f7962ef

Browse files
committed
Enable strict mode and remove module prop hacks.
1 parent 0773b5d commit f7962ef

File tree

6 files changed

+56
-49
lines changed

6 files changed

+56
-49
lines changed
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
<!DOCTYPE html>
2-
<script src="dist/bundle.js"></script>
2+
<!--
3+
type=module makes browers treat it as an ES6 module and enforces strict mode. This helps catch
4+
some errors in the test (e.g. extending frozen objects or accidentally creating global variables).
5+
-->
6+
<script type="module" src="dist/bundle.js"></script>

packages-exp/auth-exp/test/integration/webdriver/static/index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@ import * as persistence from './persistence';
2424
import { initializeApp } from '@firebase/app-exp';
2525
import { getAuth, useAuthEmulator } from '@firebase/auth-exp';
2626

27-
window.core = { ...core };
28-
window.anonymous = { ...anonymous };
29-
window.redirect = { ...redirect };
30-
window.popup = { ...popup };
31-
window.email = { ...email };
32-
window.persistence = { ...persistence };
27+
window.core = core;
28+
window.anonymous = anonymous;
29+
window.redirect = redirect;
30+
window.popup = popup;
31+
window.email = email;
32+
window.persistence = persistence;
33+
34+
window.auth = null;
3335

3436
// The config and emulator URL are injected by the test. The test framework
3537
// calls this function after that injection.
3638
window.startAuth = async () => {
3739
const app = initializeApp(firebaseConfig);
38-
auth = getAuth(app);
40+
const auth = getAuth(app);
3941
useAuthEmulator(auth, emulatorUrl);
4042
window.auth = auth;
4143
};

packages-exp/auth-exp/test/integration/webdriver/static/popup.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,46 +30,46 @@ import {
3030
// pass data back to the main Node process. Because of that setup, we can't
3131
// return the popup tasks as pending promises as they won't resolve until
3232
// the WebDriver is allowed to do other stuff. Instead, we'll store the
33-
// promises on the window and provide a way to retrieve them later, unblocking
33+
// promises in variables and provide a way to retrieve them later, unblocking
3434
// the WebDriver process.
35+
let popupPromise = null;
36+
let popupCred = null;
37+
let errorCred = null;
3538

3639
export function idpPopup(optProvider) {
3740
const provider = optProvider
3841
? new OAuthProvider(optProvider)
3942
: new GoogleAuthProvider();
40-
window.popup.popupPromise = signInWithPopup(auth, provider);
43+
popupPromise = signInWithPopup(auth, provider);
4144
}
4245

4346
export function idpReauthPopup() {
44-
window.popup.popupPromise = reauthenticateWithPopup(
47+
popupPromise = reauthenticateWithPopup(
4548
auth.currentUser,
4649
new GoogleAuthProvider()
4750
);
4851
}
4952

5053
export function idpLinkPopup() {
51-
window.popup.popupPromise = linkWithPopup(
52-
auth.currentUser,
53-
new GoogleAuthProvider()
54-
);
54+
popupPromise = linkWithPopup(auth.currentUser, new GoogleAuthProvider());
5555
}
5656

5757
export function popupResult() {
58-
return window.popup.popupPromise;
58+
return popupPromise;
5959
}
6060

6161
export async function generateCredentialFromResult() {
62-
const result = await window.popup.popupPromise;
63-
window.popup.popupCred = GoogleAuthProvider.credentialFromResult(result);
64-
return window.popup.popupCred;
62+
const result = await popupPromise;
63+
popupCred = GoogleAuthProvider.credentialFromResult(result);
64+
return popupCred;
6565
}
6666

6767
export async function signInWithPopupCredential() {
68-
return signInWithCredential(auth, window.popup.popupCred);
68+
return signInWithCredential(auth, popupCred);
6969
}
7070

7171
export async function linkWithErrorCredential() {
72-
await linkWithCredential(auth.currentUser, window.popup.errorCred);
72+
await linkWithCredential(auth.currentUser, errorCred);
7373
}
7474

7575
// These below are not technically popup functions but they're helpers for
@@ -93,7 +93,7 @@ export async function tryToSignInUnverified(email) {
9393
)
9494
);
9595
} catch (e) {
96-
window.popup.errorCred = FacebookAuthProvider.credentialFromError(e);
96+
errorCred = FacebookAuthProvider.credentialFromError(e);
9797
throw e;
9898
}
9999
}

packages-exp/auth-exp/test/integration/webdriver/static/redirect.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import {
2727
signInWithRedirect
2828
} from '@firebase/auth-exp';
2929

30+
let redirectCred = null;
31+
let errorCred = null;
32+
3033
export function idpRedirect(optProvider) {
3134
const provider = optProvider
3235
? new OAuthProvider(optProvider)
@@ -48,18 +51,16 @@ export function redirectResult() {
4851

4952
export async function generateCredentialFromRedirectResultAndStore() {
5053
const result = await getRedirectResult(auth);
51-
window.redirect.redirectCred = GoogleAuthProvider.credentialFromResult(
52-
result
53-
);
54-
return window.redirect.redirectCred;
54+
redirectCred = GoogleAuthProvider.credentialFromResult(result);
55+
return redirectCred;
5556
}
5657

5758
export async function signInWithRedirectCredential() {
58-
return signInWithCredential(auth, window.redirect.redirectCred);
59+
return signInWithCredential(auth, redirectCred);
5960
}
6061

6162
export async function linkWithErrorCredential() {
62-
await linkWithCredential(auth.currentUser, window.redirect.errorCred);
63+
await linkWithCredential(auth.currentUser, errorCred);
6364
}
6465

6566
// These below are not technically redirect functions but they're helpers for
@@ -83,7 +84,7 @@ export async function tryToSignInUnverified(email) {
8384
)
8485
);
8586
} catch (e) {
86-
window.redirect.errorCred = FacebookAuthProvider.credentialFromError(e);
87+
errorCred = FacebookAuthProvider.credentialFromError(e);
8788
throw e;
8889
}
8990
}

packages-exp/auth-exp/test/integration/webdriver/util/auth_driver.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ import { authTestServer } from './test_server';
3131
const START_FUNCTION = 'startAuth';
3232
const PASSED_ARGS = '...Array.prototype.slice.call(arguments, 0, -1)';
3333

34+
type DriverCallResult =
35+
| { type: 'success'; value: string /* JSON stringified */ }
36+
| {
37+
type: 'error';
38+
fields: string /* JSON stringified */;
39+
message: string;
40+
stack: string;
41+
};
42+
3443
/** Helper wraper around the WebDriver object */
3544
export class AuthDriver {
3645
webDriver!: WebDriver;
@@ -52,30 +61,27 @@ export class AuthDriver {
5261
// serialization which blows up the whole thing. It's okay though; this is
5362
// an integration test: we don't care about the internal (hidden) values of
5463
// these objects.
55-
const {
56-
type,
57-
value
58-
}: {
59-
type: string;
60-
value: string;
61-
} = await this.webDriver.executeAsyncScript(
64+
const result = await this.webDriver.executeAsyncScript<DriverCallResult>(
6265
`
6366
var callback = arguments[arguments.length - 1];
6467
${fn}(${PASSED_ARGS}).then(result => {
6568
callback({type: 'success', value: JSON.stringify(result)});
6669
}).catch(e => {
67-
callback({type: 'error', value: JSON.stringify(e)});
70+
callback({type: 'error', message: e.message, stack: e.stack, fields: JSON.stringify(e)});
6871
});
6972
`,
7073
...args
7174
);
7275

73-
const parsed: object = JSON.parse(value);
74-
if (type === 'success') {
75-
return JSON.parse(value) as T;
76+
if (result.type === 'success') {
77+
return JSON.parse(result.value) as T;
7678
} else {
77-
const e = new Error('Test promise rejection');
78-
Object.assign(e, parsed);
79+
const e = new Error(result.message);
80+
const stack = e.stack;
81+
Object.assign(e, JSON.parse(result.fields));
82+
83+
const trimmedDriverStack = result.stack.split('at eval (')[0];
84+
e.stack = `${trimmedDriverStack}\nfrom WebDriver call ${fn}(...)\n${stack}`;
7985
throw e;
8086
}
8187
}

packages-exp/auth-exp/test/integration/webdriver/util/test_runner.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ setTimeout(() => {
6060
before(async function () {
6161
this.timeout(20000); // Starting browsers can be slow.
6262
await DRIVER.start(browser);
63-
64-
// Prime for the first test.
65-
await DRIVER.reset();
6663
});
6764

6865
after(async () => {
@@ -72,11 +69,8 @@ setTimeout(() => {
7269
// It's assumed that the tests will start with a clean slate (i.e.
7370
// no storage).
7471
beforeEach(async () => {
75-
await DRIVER.injectConfigAndInitAuth();
76-
});
77-
78-
afterEach(async () => {
7972
await DRIVER.reset();
73+
await DRIVER.injectConfigAndInitAuth();
8074
});
8175

8276
for (const { title, generator } of SUITES) {

0 commit comments

Comments
 (0)