Skip to content

Commit dc7574e

Browse files
authored
Add Firefox testing to Auth (#6522)
* Update version test to accomidate multiple browsers * Add notes and console.logs * Update tests to accomidate firefox browser * Remove console.log * Update browsers based on environment variable * Update browsers when unit test selected * Update karma config to take env variable * Add test github action * Update github workflow * Update build command * Update format in test changed auth * Remove stand alone action for firefox auth * Add expect for spys, and test command for browser unit * Update spy to use proper sinon chai syntax
1 parent 2b2079d commit dc7574e

File tree

8 files changed

+99
-44
lines changed

8 files changed

+99
-44
lines changed

.github/workflows/test-changed-auth.yml

+60-26
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,66 @@ env:
77
DETECT_CHROMEDRIVER_VERSION: true
88

99
jobs:
10-
test:
11-
name: Test Auth If Changed
10+
test-chrome:
11+
name: Test Auth on Chrome and Node If Changed
1212
runs-on: ubuntu-latest
1313

1414
steps:
15-
# install Chrome first, so the correct version of webdriver can be installed by chromedriver when setting up the repo
16-
- name: install Chrome stable
17-
run: |
18-
sudo apt-get update
19-
sudo apt-get install google-chrome-stable
20-
- name: Checkout Repo
21-
uses: actions/checkout@master
22-
with:
23-
# This makes Actions fetch all Git history so run-changed script can diff properly.
24-
fetch-depth: 0
25-
- name: Set up Node (14)
26-
uses: actions/setup-node@v2
27-
with:
28-
node-version: 14.x
29-
- name: Bump Node memory limit
30-
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
31-
- name: Test setup and yarn install
32-
run: |
33-
cp config/ci.config.json config/project.json
34-
yarn
35-
- name: build
36-
run: yarn build:changed auth
37-
- name: Run tests on changed packages
38-
run: xvfb-run yarn test:changed auth
15+
# install Chrome first, so the correct version of webdriver can be installed by chromedriver when setting up the repo
16+
- name: install Chrome stable
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install google-chrome-stable
20+
- name: Checkout Repo
21+
uses: actions/checkout@master
22+
with:
23+
# This makes Actions fetch all Git history so run-changed script can diff properly.
24+
fetch-depth: 0
25+
- name: Set up Node (14)
26+
uses: actions/setup-node@v2
27+
with:
28+
node-version: 14.x
29+
- name: Bump Node memory limit
30+
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
31+
- name: Test setup and yarn install
32+
run: |
33+
cp config/ci.config.json config/project.json
34+
yarn
35+
- name: build
36+
run: yarn build:changed auth
37+
- name: Run tests on changed packages
38+
run: xvfb-run yarn test:changed auth
39+
test-firefox:
40+
name: Test Auth on Firefox If Changed
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- name: install Firefox stable
45+
run: |
46+
sudo apt-get update
47+
sudo apt-get install firefox
48+
- name: Checkout Repo
49+
uses: actions/checkout@master
50+
with:
51+
# This makes Actions fetch all Git history so run-changed script can diff properly.
52+
fetch-depth: 0
53+
- name: Set up Node (14)
54+
uses: actions/setup-node@v2
55+
with:
56+
node-version: 14.x
57+
- name: Bump Node memory limit
58+
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
59+
- name: Test setup and yarn install
60+
run: |
61+
cp config/ci.config.json config/project.json
62+
yarn
63+
- name: build
64+
run: yarn build:changed auth
65+
- name: Run tests on auth changed packages
66+
run: xvfb-run yarn --cwd packages/auth test:browser:unit
67+
env:
68+
BROWSERS: 'Firefox'
69+
- name: Run tests on auth-compat changed packages
70+
run: xvfb-run yarn --cwd packages/auth-compat test:browser:unit
71+
env:
72+
BROWSERS: 'Firefox'

packages/auth-compat/karma.conf.js

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const files = ['src/**/*.test.ts'];
2222

2323
module.exports = function (config) {
2424
const karmaConfig = Object.assign({}, karmaBase, {
25+
browsers: getTestBrowsers(argv),
2526
// files to load into karma
2627
files: getTestFiles(),
2728
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
@@ -43,6 +44,14 @@ function getTestFiles() {
4344
}
4445
}
4546

47+
function getTestBrowsers(argv) {
48+
let browsers = ['ChromeHeadless'];
49+
if (process.env?.BROWSERS && argv.unit) {
50+
browsers = process.env?.BROWSERS?.split(',');
51+
}
52+
return browsers;
53+
}
54+
4655
function getClientConfig() {
4756
if (!argv.integration) {
4857
return {};

packages/auth-compat/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"test:all": "run-p test:browser test:node test:integration",
3535
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
3636
"test:browser": "karma start --single-run",
37+
"test:browser:unit": "karma start --single-run --unit",
3738
"test:browser:integration": "karma start --single-run --integration",
3839
"test:node": "ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts",
3940
"test:node:integration": "ts-node -O '{\"module\": \"commonjs\", \"target\": \"es6\"}' scripts/run_node_tests.ts --integration",

packages/auth/karma.conf.js

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const { argv } = require('yargs');
2020

2121
module.exports = function (config) {
2222
const karmaConfig = Object.assign({}, karmaBase, {
23+
browsers: getTestBrowsers(argv),
2324
// files to load into karma
2425
files: getTestFiles(argv),
2526
// frameworks to use
@@ -52,6 +53,14 @@ function getTestFiles(argv) {
5253
}
5354
}
5455

56+
function getTestBrowsers(argv) {
57+
let browsers = ["ChromeHeadless"];
58+
if (process.env?.BROWSERS && argv.unit) {
59+
browsers = process.env?.BROWSERS?.split(',');
60+
}
61+
return browsers;
62+
}
63+
5564
function getClientConfig(argv) {
5665
if (!argv.local) {
5766
return {};

packages/auth/src/core/util/version.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
import { SDK_VERSION } from '@firebase/app';
1919
import { expect } from 'chai';
2020
import { ClientPlatform, _getClientVersion } from './version';
21-
import { isNode } from '@firebase/util';
21+
import { getUA, isNode } from '@firebase/util';
22+
import { _getBrowserName } from './browser';
2223

2324
describe('core/util/_getClientVersion', () => {
2425
if (isNode()) {
@@ -33,15 +34,15 @@ describe('core/util/_getClientVersion', () => {
3334
context('browser', () => {
3435
it('should set the correct version', () => {
3536
expect(_getClientVersion(ClientPlatform.BROWSER)).to.eq(
36-
`Chrome/JsCore/${SDK_VERSION}/FirebaseCore-web`
37+
`${_getBrowserName(getUA())}/JsCore/${SDK_VERSION}/FirebaseCore-web`
3738
);
3839
});
3940
});
4041

4142
context('worker', () => {
4243
it('should set the correct version', () => {
4344
expect(_getClientVersion(ClientPlatform.WORKER)).to.eq(
44-
`Chrome-Worker/JsCore/${SDK_VERSION}/FirebaseCore-web`
45+
`${_getBrowserName(getUA())}-Worker/JsCore/${SDK_VERSION}/FirebaseCore-web`
4546
);
4647
});
4748
});

packages/auth/src/platform_browser/persistence/local_storage.test.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,15 @@ describe('platform_browser/persistence/local_storage', () => {
6565
});
6666

6767
describe('#isAvailable', () => {
68+
afterEach(() => sinon.restore());
69+
6870
it('should emit false if localStorage setItem throws', async () => {
69-
sinon.stub(localStorage, 'setItem').throws(new Error('nope'));
71+
sinon.stub(Storage.prototype, 'setItem').throws(new Error('nope'));
7072
expect(await persistence._isAvailable()).to.be.false;
7173
});
7274

7375
it('should emit false if localStorage removeItem throws', async () => {
74-
sinon.stub(localStorage, 'removeItem').throws(new Error('nope'));
76+
sinon.stub(Storage.prototype, 'removeItem').throws(new Error('nope'));
7577
expect(await persistence._isAvailable()).to.be.false;
7678
});
7779

packages/auth/src/platform_browser/persistence/session_storage.test.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ describe('platform_browser/persistence/session_storage', () => {
6363
});
6464

6565
describe('#isAvailable', () => {
66+
afterEach(() => sinon.restore());
67+
6668
it('should emit false if sessionStorage setItem throws', async () => {
67-
sinon.stub(sessionStorage, 'setItem').throws(new Error('nope'));
68-
expect(await persistence._isAvailable()).to.be.false;
69+
sinon.stub(Storage.prototype, 'setItem').throws(new Error('nope'));
70+
expect(await persistence._isAvailable()).to.be.false;
6971
});
7072

7173
it('should emit false if sessionStorage removeItem throws', async () => {
72-
sinon.stub(sessionStorage, 'removeItem').throws(new Error('nope'));
74+
sinon.stub(Storage.prototype, 'removeItem').throws(new Error('nope'));
7375
expect(await persistence._isAvailable()).to.be.false;
7476
});
7577

packages/auth/src/platform_cordova/popup_redirect/events.test.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,8 @@ use(sinonChai);
3636

3737
describe('platform_cordova/popup_redirect/events', () => {
3838
let auth: TestAuth;
39-
let storageStub: sinon.SinonStubbedInstance<typeof localStorage>;
40-
4139
beforeEach(async () => {
4240
auth = await testAuth();
43-
storageStub = sinon.stub(localStorage);
4441
});
4542

4643
afterEach(() => {
@@ -73,28 +70,28 @@ describe('platform_cordova/popup_redirect/events', () => {
7370

7471
describe('_savePartialEvent', () => {
7572
it('sets the event', async () => {
73+
const spy = sinon.spy(Storage.prototype, 'setItem');
7674
const event = _generateNewEvent(auth, AuthEventType.REAUTH_VIA_REDIRECT);
7775
await _savePartialEvent(auth, event);
78-
expect(storageStub.setItem).to.have.been.calledWith(
79-
'firebase:authEvent:test-api-key:test-app',
80-
JSON.stringify(event)
81-
);
76+
expect(spy).to.have.been.calledWith('firebase:authEvent:test-api-key:test-app',
77+
JSON.stringify(event));
8278
});
8379
});
8480

8581
describe('_getAndRemoveEvent', () => {
8682
it('returns null if no event is present', async () => {
87-
storageStub.getItem.returns(null);
83+
sinon.stub(Storage.prototype, 'getItem').returns(null);
8884
expect(await _getAndRemoveEvent(auth)).to.be.null;
8985
});
9086

9187
it('returns the event and deletes the key if present', async () => {
9288
const event = JSON.stringify(
9389
_generateNewEvent(auth, AuthEventType.REAUTH_VIA_REDIRECT)
9490
);
95-
storageStub.getItem.returns(event);
91+
sinon.stub(Storage.prototype, 'getItem').returns(event);
92+
const spy = sinon.spy(Storage.prototype, 'removeItem');
9693
expect(await _getAndRemoveEvent(auth)).to.eql(JSON.parse(event));
97-
expect(storageStub.removeItem).to.have.been.calledWith(
94+
expect(spy).to.have.been.calledWith(
9895
'firebase:authEvent:test-api-key:test-app'
9996
);
10097
});

0 commit comments

Comments
 (0)