Skip to content

Commit 4ddb6a5

Browse files
authored
Merge 02721e1 into 15c36cc
2 parents 15c36cc + 02721e1 commit 4ddb6a5

File tree

12 files changed

+454
-33
lines changed

12 files changed

+454
-33
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,29 @@ jobs:
102102
run: xvfb-run yarn test:changed auth
103103
env:
104104
BROWSERS: 'Firefox'
105+
106+
test-safari:
107+
name: Test Auth on Safari If Changed
108+
runs-on: macos-latest
109+
110+
steps:
111+
- name: Checkout Repo
112+
uses: actions/checkout@v4
113+
with:
114+
# This makes Actions fetch all Git history so run-changed script can diff properly.
115+
fetch-depth: 0
116+
- name: Set up Node (20)
117+
uses: actions/setup-node@v3
118+
with:
119+
node-version: 20.x
120+
- name: Test setup and yarn install
121+
run: |
122+
cp config/ci.config.json config/project.json
123+
yarn
124+
- name: build
125+
run: yarn build:changed auth
126+
- name: Run tests on auth changed packages
127+
run: yarn test:changed auth
128+
env:
129+
BROWSERS: 'Safari'
130+

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,60 @@ jobs:
230230
env:
231231
BROWSERS: 'Firefox'
232232
EXPERIMENTAL_MODE: true
233+
234+
compat-test-safari:
235+
name: Test Firestore Compatible on Firefox
236+
# Whatever version of Firefox comes with 22.04 is causing Firefox
237+
# startup to hang when launched by karma. Need to look further into
238+
# why.
239+
runs-on: macos-latest
240+
needs: build
241+
if: ${{ needs.build.outputs.changed == 'true'}}
242+
steps:
243+
- name: Set up Node (20)
244+
uses: actions/setup-node@v3
245+
with:
246+
node-version: 20.x
247+
- name: Download build archive
248+
uses: actions/download-artifact@v3
249+
with:
250+
name: build.tar.gz
251+
- name: Unzip build artifact
252+
run: tar xf build.tar.gz
253+
- name: Test setup and yarn install
254+
run: cp config/ci.config.json config/project.json
255+
- name: Run compat tests
256+
run: cd packages/firestore-compat && yarn run test:ci
257+
env:
258+
BROWSERS: 'Safari'
259+
260+
test-safari:
261+
name: Test Firestore on Safari
262+
strategy:
263+
matrix:
264+
test-name: ["test:browser", "test:lite:browser", "test:browser:prod:nameddb", "test:lite:browser:nameddb"]
265+
runs-on: macos-latest
266+
needs: build
267+
if: ${{ needs.build.outputs.changed == 'true'}}
268+
steps:
269+
- name: Download build archive
270+
uses: actions/download-artifact@v3
271+
with:
272+
name: build.tar.gz
273+
- name: Unzip build artifact
274+
run: tar xf build.tar.gz
275+
- name: Set up Node (20)
276+
uses: actions/setup-node@v3
277+
with:
278+
node-version: 20.x
279+
- name: Test setup and yarn install
280+
run: cp config/ci.config.json config/project.json
281+
- name: Run tests
282+
run: cd packages/firestore && yarn run ${{ matrix.test-name }}
283+
env:
284+
BROWSERS: 'Safari'
285+
EXPERIMENTAL_MODE: true
286+
233287

234288
# A job that fails if any required job in the test matrix fails,
235289
# to be used as a required check for merging.

.github/workflows/test-changed.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,28 @@ jobs:
7878
run: xvfb-run yarn test:changed core
7979
env:
8080
BROWSERS: 'Firefox'
81+
82+
test-safari:
83+
name: Test Packages With Changed Files in Safari
84+
runs-on: macos-latest
85+
86+
steps:
87+
- name: Checkout Repo
88+
uses: actions/checkout@v4
89+
with:
90+
fetch-depth: 0
91+
- name: Set up Node (20)
92+
uses: actions/setup-node@v3
93+
with:
94+
node-version: 20.x
95+
- name: Test setup and yarn install
96+
run: |
97+
cp config/ci.config.json config/project.json
98+
yarn
99+
- name: build
100+
run: yarn build
101+
- name: Run tests on changed packages
102+
run: npx lerna run test:browser --ignore @firebase/firestore --ignore @firebase/auth --ignore firebase-messaging-integration-test
103+
env:
104+
BROWSERS: 'Safari'
105+

config/karma.base.js

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,66 @@ const path = require('path');
2020
const webpackTestConfig = require('./webpack.test');
2121
const { argv } = require('yargs');
2222

23+
function determineBrowsers() {
24+
const supportedBrowsers = ['ChromeHeadless', 'Safari', 'Firefox'];
25+
26+
if (process.env.BROWSERS) {
27+
const browsers = process.env.BROWSERS.split(',');
28+
29+
const validBrowsers = browsers.filter(browser =>
30+
supportedBrowsers.includes(browser)
31+
);
32+
if (validBrowsers.length === 0) {
33+
console.error(
34+
`The \'BROWSER\' environment variable was set, but no supported browsers were listed. The supported browsers are ${JSON.stringify(
35+
supportedBrowsers
36+
)}.`
37+
);
38+
return [];
39+
}
40+
41+
if (browsers.includes('Safari') && process.platform !== 'darwin') {
42+
console.error(
43+
"The 'BROWSER' environment variable includes 'Safari', which is not supported on this platform. The only supported platform is darwin."
44+
);
45+
return [];
46+
}
47+
48+
if (browsers.includes('Safari')) {
49+
console.log(
50+
"\x1b[38;2;255;165;0mSafari browser testing has been enabled. This requires Full Disk Access be granted to the executor. To grant Full Disk Access on macOS > 13, visit 'System Settings' > 'Privacy & Security' > 'Full Disk Access'.\x1b[0m"
51+
); // Log in orange
52+
}
53+
54+
return validBrowsers;
55+
} else {
56+
/**
57+
* By default we only run the Chrome tests locally since the Safari launcher has some quirks
58+
* that make local testing annoying:
59+
* - Tabs from previous test runs are restored, causing the tests to be ran once on each tab.
60+
* To prevent this, Safari has to be manually re-opened and then quit after every test run.
61+
* - Full Disk Access has to be manually enabled
62+
*
63+
* Running the browser tests in Chrome should catch most browser bugs. If that's not the case,
64+
* the bugs will be caught when the browser tests are ran on Safari in CI.
65+
*/
66+
console.log(
67+
"The 'BROWSER' environment variable is undefined. Defaulting to 'ChromeHeadless'."
68+
);
69+
return ['ChromeHeadless'];
70+
}
71+
}
72+
2373
const config = {
74+
// See: https://karma-runner.github.io/6.4/config/plugins.html#loading-plugins
75+
plugins: [
76+
// We use our own custom Safari launcher plugin since https://github.com/karma-runner/karma-safari-launcher
77+
// does not work and is not maintained.
78+
require('../scripts/ci-test/karmaSafariLauncher.js'),
79+
// Include all other plugins from our npm modules
80+
'karma-*'
81+
],
82+
2483
// disable watcher
2584
autoWatch: false,
2685

@@ -57,10 +116,11 @@ const config = {
57116
// changes
58117
autoWatch: false,
59118

60-
// start these browsers
61-
// available browser launchers:
62-
// https://npmjs.org/browse/keyword/karma-launcher
63-
browsers: process.env?.BROWSERS?.split(',') ?? ['ChromeHeadless'],
119+
// Browsers to launch for testing
120+
// To use a custom set of browsers, define the BROWSERS environment variable as a comma-seperated list.
121+
// Supported browsers are 'ChromeHeadless', 'Safari', and 'Firefox'.
122+
// See: https://karma-runner.github.io/6.4/config/browsers.html
123+
browsers: determineBrowsers(),
64124

65125
webpack: webpackTestConfig,
66126

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@
120120
"karma-firefox-launcher": "2.1.3",
121121
"karma-mocha": "2.0.1",
122122
"karma-mocha-reporter": "2.2.5",
123-
"karma-safari-launcher": "1.0.0",
124123
"karma-sourcemap-loader": "0.4.0",
125124
"karma-spec-reporter": "0.0.36",
126125
"karma-summary-reporter": "3.1.1",
@@ -159,6 +158,7 @@
159158
"undici": "6.19.7",
160159
"watch": "1.0.2",
161160
"webpack": "5.76.0",
161+
"rimraf": "6.0.1",
162162
"yargs": "17.7.2"
163163
}
164164
}

packages/analytics/testing/integration-tests/integration.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ async function checkForEventCalls(retryCount = 0): Promise<PerformanceEntry[]> {
5656

5757
describe('FirebaseAnalytics Integration Smoke Tests', () => {
5858
let app: FirebaseApp;
59+
60+
// Clear cookies to prevent persistence issues across tests when run in non-headless browsers.
61+
// This is required since gtag/logEvent behaviour is dependent on the session state; if an event has already been logged
62+
// in a session, the event will be sent in the request payload instead of the query string.
63+
beforeEach(() => {
64+
document.cookie.split(';').forEach(cookie => {
65+
document.cookie = cookie
66+
.replace(/^ +/, '')
67+
.replace(/=.*/, '=;expires=' + new Date().toUTCString() + ';path=/');
68+
});
69+
});
70+
5971
describe('Using getAnalytics()', () => {
6072
afterEach(() => deleteApp(app));
6173
it('logEvent() sends correct network request.', async () => {

packages/auth-compat/karma.conf.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const files = ['src/**/*.test.ts'];
2323

2424
module.exports = function (config) {
2525
const karmaConfig = Object.assign({}, karmaBase, {
26-
browsers: getTestBrowsers(argv),
2726
// files to load into karma
2827
files: getTestFiles(),
2928
preprocessors: { '**/*.ts': ['webpack', 'sourcemap'] },
@@ -56,14 +55,6 @@ function getTestFiles() {
5655
}
5756
}
5857

59-
function getTestBrowsers(argv) {
60-
let browsers = ['ChromeHeadless'];
61-
if (process.env?.BROWSERS && argv.unit) {
62-
browsers = process.env?.BROWSERS?.split(',');
63-
}
64-
return browsers;
65-
}
66-
6758
function getClientConfig() {
6859
if (!argv.integration) {
6960
return {};

packages/auth/karma.conf.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const { argv } = require('yargs');
2121

2222
module.exports = function (config) {
2323
const karmaConfig = Object.assign({}, karmaBase, {
24-
browsers: getTestBrowsers(argv),
2524
// files to load into karma
2625
files: getTestFiles(argv),
2726
// frameworks to use
@@ -60,7 +59,7 @@ function getTestFiles(argv) {
6059
} else if (argv.cordova) {
6160
return ['src/platform_cordova/**/*.test.ts'];
6261
} else {
63-
// For the catch-all yarn:test, ignore the phone integration test
62+
// For the catch-all yarn browser:test, ignore the phone integration test
6463
return [
6564
'src/**/*.test.ts',
6665
'test/helpers/**/*.test.ts',
@@ -71,14 +70,6 @@ function getTestFiles(argv) {
7170
}
7271
}
7372

74-
function getTestBrowsers(argv) {
75-
let browsers = ['ChromeHeadless'];
76-
if (process.env?.BROWSERS && argv.unit) {
77-
browsers = process.env?.BROWSERS?.split(',');
78-
}
79-
return browsers;
80-
}
81-
8273
function getClientConfig(argv) {
8374
if (!argv.local) {
8475
return {};

packages/auth/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,12 @@
9393
"build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'",
9494
"dev": "rollup -c -w",
9595
"test": "run-p --npm-path npm lint test:all",
96-
"test:all": "run-p --npm-path npm test:browser:unit test:node:unit test:integration test:browser:integration:prodbackend",
97-
"test:integration": "firebase emulators:exec --project emulatedproject --only auth \"run-s --npm-path npm test:browser:integration:local test:node:integration:local test:webdriver\"",
96+
"test:all": "run-p --npm-path npm test:browser:unit test:node:unit test:integration",
97+
"test:integration": "firebase emulators:exec --project emulatedproject --only auth \"run-s --npm-path npm test:browser:integration:local test:browser:integration:prodbackend test:node:integration:local test:webdriver\"",
9898
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all",
9999
"test:integration:local": "run-s --npm-path npm test:node:integration:local test:browser:integration:local test:webdriver",
100-
"test:browser": "karma start --single-run --local",
100+
"test:browser": "karma start --single-run",
101+
"test:browser:local": "karma start --single-run --local",
101102
"test:browser:unit": "karma start --single-run --unit",
102103
"test:browser:integration": "karma start --single-run --integration",
103104
"test:browser:integration:local": "karma start --single-run --integration --local",

0 commit comments

Comments
 (0)