Skip to content

Commit 6f66b4b

Browse files
authored
Add E2E workflow and tests (#5204)
1 parent 2ad6ce8 commit 6f66b4b

File tree

15 files changed

+7869
-1
lines changed

15 files changed

+7869
-1
lines changed

.github/workflows/e2e-test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: E2E Smoke Tests
2+
3+
on: workflow_dispatch
4+
5+
jobs:
6+
test:
7+
name: Run E2E Smoke Tests
8+
runs-on: ubuntu-latest
9+
defaults:
10+
run:
11+
# Run any command steps in the /e2e subdir
12+
working-directory: './e2e'
13+
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@master
17+
- name: Set up Node (12)
18+
uses: actions/setup-node@v2
19+
with:
20+
node-version: 12.x
21+
- name: install Chrome stable
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install google-chrome-stable
25+
- name: Bump Node memory limit
26+
run: echo "NODE_OPTIONS=--max_old_space_size=4096" >> $GITHUB_ENV
27+
- name: Write project config
28+
env:
29+
PROJECT_CONFIG: ${{ secrets.TEST_PROJECT_CONFIG }}
30+
TEST_ACCOUNT: ${{ secrets.TEST_ACCOUNT }}
31+
run: |
32+
echo "export const config = $PROJECT_CONFIG; export const testAccount = $TEST_ACCOUNT" > firebase-config.js
33+
- name: Yarn install
34+
run: |
35+
yarn add firebase
36+
yarn
37+
- name: Deploy "callTest" cloud function
38+
run: |
39+
pushd functions
40+
npm install
41+
popd
42+
npx firebase-tools deploy --only functions:callTest --project jscore-sandbox-141b5 --token $FIREBASE_CLI_TOKEN
43+
working-directory: ./config
44+
env:
45+
FIREBASE_CLI_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }}
46+
- name: Run modular tests
47+
env:
48+
APP_CHECK_DEBUG_TOKEN: ${{ secrets.APP_CHECK_DEBUG_TOKEN }}
49+
run: xvfb-run yarn test:modular
50+
- name: Run compat tests
51+
env:
52+
APP_CHECK_DEBUG_TOKEN: ${{ secrets.APP_CHECK_DEBUG_TOKEN }}
53+
run: xvfb-run yarn test:compat

config/functions/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @license
3-
* Copyright 2017 Google Inc.
3+
* Copyright 2017 Google LLC
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -142,3 +142,8 @@ exports.timeoutTest = functions.https.onRequest((request, response) => {
142142
setTimeout(() => response.send({ data: true }), 500);
143143
});
144144
});
145+
146+
// Used by E2E test.
147+
exports.callTest = functions.https.onCall((data, context) => {
148+
return { word: 'hellooo' };
149+
});

e2e/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build/*.js
2+
firebase-config.js
3+
context.html

e2e/README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Firebase JS SDK E2E Tests
2+
3+
This directory contains end-to-end tests for the Firebase JS SDK package as well as minimal quick start sample apps for debugging and development.
4+
5+
## E2E Tests
6+
7+
### Setup
8+
9+
Before running the tests, you will need:
10+
11+
- a project config
12+
- a test user with an email/password login which has read/write privileges for Storage, Realtime Database, and Firestore
13+
- an App Check debug token
14+
- to deploy the `callTest` Cloud Function
15+
16+
#### Project Config and Test User
17+
18+
Create a file named `firebase-config.js` in the top level of this `e2e/` directory. The contents of the file should be:
19+
20+
```javascript
21+
// A config for a project
22+
export const config = {
23+
apiKey: ************,
24+
authDomain: ************,
25+
databaseURL: ************,
26+
projectId: ************,
27+
storageBucket: ************,
28+
messagingSenderId: ************,
29+
appId: ************,
30+
measurementId: ************
31+
};
32+
*
33+
// A user account with read/write privileges in that project
34+
// for storage, database, firestore
35+
export const testAccount = {
36+
email: ************,
37+
password: ************
38+
}
39+
```
40+
41+
#### App Check Debug Token
42+
43+
Create an App Check debug token in the Firebase Console. Assign it to an environment variable in your shell named `APP_CHECK_DEBUG_TOKEN`.
44+
45+
#### Deploy `callTest` Cloud Function
46+
47+
From the top level of the firebase repo, ensure you have the Firebase CLI (`firebase-tools`) installed (if not, `npm install -g firebase-tools`).
48+
49+
Ensure you are logged in using the CLI (`firebase login`);
50+
51+
Then deploy the function with:
52+
`firebase deploy --only functions:callTest --project YOUR_PROJECT_ID`
53+
54+
### Running the Tests
55+
56+
To run the tests on the default modular API:
57+
58+
```
59+
yarn test:modular
60+
```
61+
62+
To run the tests on the compat API:
63+
64+
```
65+
yarn test:compat
66+
```
67+
68+
## Sample Apps
69+
70+
Two minimal sample apps are provided for quick debugging and development. These apps import and initialize every product in the SDK and call some basic methods. Products can easily be commented out to focus on one or more products you are interested in looking at.
71+
72+
### Setup
73+
74+
The setup is the same as for the E2E tests above. Certain tests can be skipped if you are commenting out that product (e.g, no need to deploy the Cloud Function if you are commenting out the `callFunctions()` line in the sample app, and no need to set the App Check debug token env variable if not using App Check).
75+
76+
### Running Sample Apps
77+
78+
To run the modular sample app (uses current default version of the API):
79+
80+
```
81+
yarn start:modular
82+
```
83+
84+
Then open `localhost:8080` in a browser.
85+
86+
To run the compat sample app (uses current compat version of the API):
87+
88+
```
89+
yarn start:compat
90+
```
91+
92+
Then open `localhost:8080` in a browser.

e2e/build/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<body>
2+
<script src="./app.bundle.js"></script>
3+
</body>

e2e/context-template.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<!--
3+
NOTE: This file is identical to karma's default except for the
4+
FIREBASE_APPCHECK_DEBUG_TOKEN line.
5+
6+
This is the execution context.
7+
Loaded within the iframe.
8+
Reloaded before every execution run.
9+
-->
10+
<html>
11+
<head>
12+
<title></title>
13+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
14+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
15+
</head>
16+
<body>
17+
<!-- The scripts need to be in the body DOM element, as some test running frameworks need the body
18+
to have already been created so they can insert their magic into it. For example, if loaded
19+
before body, Angular Scenario test framework fails to find the body and crashes and burns in
20+
an epic manner. -->
21+
<script src="context.js"></script>
22+
<script type="text/javascript">
23+
// test-setup.js will replace with token pulled from process.env.APP_CHECK_DEBUG_TOKEN
24+
self.FIREBASE_APPCHECK_DEBUG_TOKEN = 'APP_CHECK_DEBUG_TOKEN';
25+
// Configure our Karma and set up bindings
26+
%CLIENT_CONFIG%
27+
window.__karma__.setupContext(window);
28+
29+
// All served files with the latest timestamps
30+
%MAPPINGS%
31+
</script>
32+
<!-- Dynamically replaced with <script> tags -->
33+
%SCRIPTS%
34+
<!-- Since %SCRIPTS% might include modules, the `loaded()` call needs to be in a module too.
35+
This ensures all the tests will have been declared before karma tries to run them. -->
36+
<script type="module">
37+
window.__karma__.loaded();
38+
</script>
39+
<script nomodule>
40+
window.__karma__.loaded();
41+
</script>
42+
</body>
43+
</html>

e2e/karma.conf.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
function getTestFiles(argv) {
19+
const files = [];
20+
if (argv.includes('--compat')) {
21+
files.push('./tests/compat.test.ts');
22+
}
23+
if (argv.includes('--modular')) {
24+
files.push('./tests/modular.test.ts');
25+
}
26+
return files;
27+
}
28+
const karma = require('karma');
29+
30+
module.exports = function (config) {
31+
config.set({
32+
frameworks: ['karma-typescript', 'mocha'],
33+
files: getTestFiles(process.argv),
34+
preprocessors: {
35+
'./tests/*.test.ts': ['karma-typescript']
36+
},
37+
browsers: ['Chrome'],
38+
singleRun: true,
39+
client: {
40+
mocha: {
41+
timeout: 10000
42+
}
43+
},
44+
customContextFile: './context.html',
45+
reporters: ['spec'],
46+
specReporter: {
47+
maxLogLines: 5, // limit number of lines logged per test
48+
suppressErrorSummary: true, // do not print error summary
49+
suppressFailed: false, // do not print information about failed tests
50+
suppressPassed: false, // do not print information about passed tests
51+
suppressSkipped: true, // do not print information about skipped tests
52+
showSpecTiming: false // print the time elapsed for each spec
53+
},
54+
concurrency: 1,
55+
karmaTypescriptConfig: {
56+
bundlerOptions: {
57+
resolve: {
58+
directories: ['./node_modules'],
59+
alias: {
60+
'@firebase/messaging/sw':
61+
'node_modules/@firebase/messaging/dist/index.sw.esm2017.js'
62+
}
63+
},
64+
transforms: [
65+
require('karma-typescript-es6-transform')({
66+
presets: [
67+
[
68+
'@babel/preset-env',
69+
{
70+
targets: {
71+
browsers: ['last 2 Chrome versions']
72+
}
73+
}
74+
]
75+
]
76+
})
77+
]
78+
},
79+
compilerOptions: {
80+
allowJs: true
81+
}
82+
},
83+
plugins: [
84+
'karma-typescript',
85+
'karma-mocha',
86+
'karma-chrome-launcher',
87+
'karma-spec-reporter'
88+
]
89+
});
90+
};

e2e/package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "firebase-smoke-test",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"setup": "node test-setup.js",
8+
"test": "yarn setup && karma start --compat --modular",
9+
"test:compat": "yarn setup && yarn karma start --compat",
10+
"test:modular": "yarn setup && karma start --modular",
11+
"watch": "webpack --watch",
12+
"build": "webpack",
13+
"start:modular": "webpack serve --config-name modular",
14+
"start:compat": "webpack serve --config-name compat"
15+
},
16+
"author": "",
17+
"license": "ISC",
18+
"dependencies": {
19+
"firebase": "9.0.2"
20+
},
21+
"devDependencies": {
22+
"@babel/core": "7.14.6",
23+
"@babel/preset-env": "7.14.4",
24+
"@types/chai": "4.2.18",
25+
"@types/mocha": "8.2.2",
26+
"babel-loader": "8.0.5",
27+
"chai": "4.3.4",
28+
"karma": "6.3.4",
29+
"karma-chrome-launcher": "3.1.0",
30+
"karma-mocha": "2.0.1",
31+
"karma-spec-reporter": "0.0.32",
32+
"karma-typescript": "5.5.1",
33+
"karma-typescript-es6-transform": "5.5.1",
34+
"mocha": "9.0.0",
35+
"typescript": "4.3.4",
36+
"webpack": "5.41.1",
37+
"webpack-cli": "4.7.2",
38+
"webpack-dev-server": "3.10.1"
39+
}
40+
}

0 commit comments

Comments
 (0)