Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add browser unit tests for firefox in firestore #6538

Merged
merged 9 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 56 additions & 25 deletions .github/workflows/test-changed-firestore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,62 @@ name: Test Firestore
on: pull_request

jobs:
test:
name: Test Firestore If Changed
test-chrome:
name: Test Firestore on Chrome and Node If Changed
runs-on: ubuntu-latest

steps:
- name: Checkout Repo
uses: actions/checkout@master
with:
# This makes Actions fetch all Git history so run-changed script can diff properly.
fetch-depth: 0
- name: Set up Node (14)
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: install Chrome stable
run: |
sudo apt-get update
sudo apt-get install google-chrome-stable
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- name: Test setup and yarn install
run: |
cp config/ci.config.json config/project.json
yarn
- name: build
run: yarn build:changed firestore
- name: Run tests if firestore or its dependencies has changed
run: yarn test:changed firestore
- name: Checkout Repo
uses: actions/checkout@master
with:
# This makes Actions fetch all Git history so run-changed script can diff properly.
fetch-depth: 0
- name: Set up Node (14)
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: install Chrome stable
run: |
sudo apt-get update
sudo apt-get install google-chrome-stable
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- name: Test setup and yarn install
run: |
cp config/ci.config.json config/project.json
yarn
- name: build
run: yarn build:changed firestore
- name: Run tests if firestore or its dependencies has changed
run: yarn test:changed firestore

test-firefox:
name: Test Firestore on Firefox If Changed
runs-on: ubuntu-latest

steps:
- name: install Firefox stable
run: |
sudo apt-get update
sudo apt-get install firefox
- name: Checkout Repo
uses: actions/checkout@master
with:
# This makes Actions fetch all Git history so run-changed script can diff properly.
fetch-depth: 0
- name: Set up Node (14)
uses: actions/setup-node@v2
with:
node-version: 14.x
- name: Bump Node memory limit
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
- name: Test setup and yarn install
run: |
cp config/ci.config.json config/project.json
yarn
- name: build
run: yarn build:changed firestore
- name: Run tests if firestore or its dependencies has changed
run: xvfb-run yarn test:changed firestore
env:
BROWSERS: 'Firefox'
9 changes: 9 additions & 0 deletions packages/firestore/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const { argv } = require('yargs');

module.exports = function (config) {
const karmaConfig = Object.assign({}, karmaBase, {
browsers: getTestBrowsers(argv),
// files to load into karma
files: getTestFiles(argv),

Expand Down Expand Up @@ -59,6 +60,14 @@ function getTestFiles(argv) {
}
}

function getTestBrowsers(argv) {
let browsers = ['ChromeHeadless'];
if (process.env?.BROWSERS && argv.unit) {
browsers = process.env?.BROWSERS?.split(',');
}
return browsers;
}

/**
* If the --local argument is passed, returns a {host, ssl} FirestoreSettings
* object that point to localhost instead of production.
Expand Down
1 change: 1 addition & 0 deletions packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"test:all:ci": "run-p test:browser test:lite:browser test:travis",
"test:all": "run-p test:browser test:lite:browser test:travis test:minified",
"test:browser": "karma start --single-run",
"test:browser:unit": "karma start --single-run --unit",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"test:node": "node ./scripts/run-tests.js --main=test/register.ts --emulator 'test/{,!(browser|lite)/**/}*.test.ts'",
"test:node:prod": "node ./scripts/run-tests.js --main=test/register.ts 'test/{,!(browser|lite)/**/}*.test.ts'",
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/test/unit/util/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function genericBundleReadingTests(bytesPerRead: number): void {

await expect(
generateBundleAndParse('{metadata: "no length prefix"}', bytesPerRead)
).to.be.rejectedWith('Unexpected end of JSON input');
).to.be.rejectedWith(/(Unexpected end of )(?=.*JSON\b).*/gi);

await expect(
generateBundleAndParse(
Expand Down
5 changes: 4 additions & 1 deletion scripts/run_tests_in_ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const { writeFileSync } = require('fs');
const LOGDIR = process.env.CI ? process.env.HOME : '/tmp';
// Maps the packages where we should not run `test:all` and instead isolate the cross-browser tests.
// TODO(dwyfrequency): Update object with `storage` and `firestore` packages.
const crossBrowserPackages = { 'packages/auth': 'test:browser:unit' };
const crossBrowserPackages = {
'packages/auth': 'test:browser:unit',
'packages/firestore': 'test:browser:unit'
};

function writeLogs(status, name, logText) {
const safeName = name.replace(/@/g, 'at_').replace(/\//g, '_');
Expand Down