Skip to content
This repository has been archived by the owner on Oct 7, 2022. It is now read-only.

Integration tests for Rally Web Platform #79

Merged
merged 68 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 63 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
f6f4ee0
basic jest, typescript, and selenium working, still need to update tests
rhelmer Aug 20, 2021
0f75e9c
add beginnings of working integration test, starting with Firefox
rhelmer Aug 21, 2021
da666ee
land sample extension for now
rhelmer Aug 21, 2021
6b7a8b9
upgrade to latest in-progress rally-sdk, so opening the site works
rhelmer Aug 21, 2021
07d1c86
add firebase functions, starting with rallytoken
rhelmer Aug 20, 2021
b553da7
start adding basic UX flows integration tests against emulator
rhelmer Aug 21, 2021
fd956d5
start adding basic UX flows integration tests against emulator
rhelmer Aug 21, 2021
603eb41
make jest and babel work with a type:module package.json
rhelmer Aug 21, 2021
2873271
run firebase emulator as part of test:integration target, and have it…
rhelmer Aug 21, 2021
6a03e7c
configure circle to run integration tests
rhelmer Aug 21, 2021
1d08907
upgrade node on circle
rhelmer Aug 21, 2021
b838b2e
headless browser test by default
rhelmer Aug 21, 2021
0a3a24c
import data to firestore and auth emulators
rhelmer Aug 21, 2021
c7c657f
firebase emulators need openjdk
rhelmer Aug 21, 2021
965dbc4
firebase emulators need openjdk+node
rhelmer Aug 21, 2021
90e8fe2
set up cloud functions before running tests
rhelmer Aug 21, 2021
68535e3
remove function build step for now, not sure we need it
rhelmer Aug 21, 2021
38da5b0
install firefox for integration tests
rhelmer Aug 21, 2021
8e27a0d
build is necessary for emulated functions
rhelmer Aug 21, 2021
38bce40
explicitly wait for buttons to become visible, to avoid slow animations
rhelmer Aug 21, 2021
599541b
add a few extension-installed tests
rhelmer Aug 21, 2021
53ef244
update text extension, and make it easy to flip headless mode
rhelmer Aug 22, 2021
7f41b13
use content script to pass token, which works on both Firefox and Chrome
rhelmer Aug 22, 2021
41ac335
better logging, and latest .xpi
rhelmer Aug 22, 2021
9fec8ed
better logging, and latest .xpi
rhelmer Aug 22, 2021
f16549e
dump extension console logs so selenium can see them
rhelmer Aug 22, 2021
fea4595
point to latest rally-sdk fork
rhelmer Aug 22, 2021
96bf963
remove dev version of rally.js, it is only needed for the test extens…
rhelmer Aug 22, 2021
9082fb4
generate and pass rally token to study extensions
rhelmer Aug 22, 2021
08a8117
document the current state of firebase emulation and integration testing
rhelmer Aug 22, 2021
c1663b8
add fixme to integration test - need to decide if we want to flush d…
rhelmer Aug 22, 2021
a7b8090
not sure this route is working correctly
rhelmer Aug 22, 2021
9c23e46
enable headless more for ci
rhelmer Aug 22, 2021
7b27a5a
add chrome support
rhelmer Aug 23, 2021
a61e040
Add chrome and extension support
rhelmer Aug 23, 2021
8067909
enable headless more for CI
rhelmer Aug 23, 2021
29f2202
set up circle to test chrome
rhelmer Aug 23, 2021
6158e62
typo in package name
rhelmer Aug 23, 2021
b40b136
take screenshots, and be more careful to wait until animations have f…
rhelmer Aug 23, 2021
6ea0a45
tell circle to store screenshots
rhelmer Aug 23, 2021
5d3d603
enable headless browser
rhelmer Aug 23, 2021
16ba237
increase jest timeout, and clarify variable names
rhelmer Aug 23, 2021
542849d
set user initially unenrolled in test data
rhelmer Aug 23, 2021
0a53548
default test user should start unenrolled
rhelmer Aug 23, 2021
39c2029
temporarily disable chrome to see if intermittents go away
rhelmer Aug 23, 2021
f62eb6f
disable for CI
rhelmer Aug 23, 2021
32eddfd
re-enable Chrome
rhelmer Aug 23, 2021
0c082c8
disable Chrome
rhelmer Aug 23, 2021
b59d0b2
enabled chrome in next test
rhelmer Aug 23, 2021
6cd153b
typo
rhelmer Aug 23, 2021
05102f1
support passing the study name to the generate_token function
rhelmer Aug 23, 2021
cee3ee4
typo
rhelmer Aug 23, 2021
6f887d4
make eslint happy
rhelmer Aug 24, 2021
e3acd19
deploy functions on merge to master
rhelmer Aug 24, 2021
d924f10
Re-enable enrollment test
rhelmer Aug 24, 2021
59d9eb9
seeing an inconsistency with this turned on locally vs. on Circle
rhelmer Aug 24, 2021
a0cd7a5
set onboarding to false by default
rhelmer Aug 24, 2021
a73318a
still trying to make tests consistent between local and circle
rhelmer Aug 24, 2021
e258a81
have jest check logs to make sure extension is responding appropriately
rhelmer Aug 24, 2021
063d813
add a --config-integration-test-mode flag for setting up to use fireb…
rhelmer Aug 24, 2021
e50b6b2
move test runner to script so we can use pipefail
rhelmer Aug 24, 2021
1fecd5a
circle is failing to find this prompt even though it works locally
rhelmer Aug 24, 2021
c337b8d
temporarily disable chrome on the full test
rhelmer Aug 24, 2021
62f7e3e
Update README.md
rhelmer Aug 25, 2021
fb83d3a
do not add .js on import for consistency
rhelmer Aug 25, 2021
31f031e
Merge branch 'integration-test' of github.com:rhelmer/rally-web-platf…
rhelmer Aug 25, 2021
93a603c
link to the file we use the emulator from
rhelmer Aug 25, 2021
625e492
Merge branch 'master' into integration-test
rhelmer Aug 25, 2021
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
20 changes: 14 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ orbs:
# The Node.js orb contains a set of prepackaged CircleCI configuration you can utilize
# Orbs reduce the amount of configuration required for common tasks.
# See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/node
node: circleci/node@4.1
node: circleci/node@4.7.0

jobs:
# Below is the definition of your job to build and test your app, you can rename and customize it as you want.
Expand All @@ -15,7 +15,7 @@ jobs:
# You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub.
# A list of available CircleCI Docker Convenience Images are available here: https://circleci.com/developer/images/image/cimg/node
docker:
- image: cimg/node:15.1
- image: cimg/openjdk:16.0.2-node
# Then run your tests!
# CircleCI will report the results back to your VCS provider.
steps:
Expand All @@ -34,9 +34,17 @@ jobs:
root: .
paths:
- .
#- run:
# name: Run tests
# command: npm run test:unit
- run:
name: Install Nightly Firefox and dependencies for official Google Chrome package
command: sudo add-apt-repository ppa:ubuntu-mozilla-daily/ppa && sudo apt update && sudo apt install firefox-trunk default-jre fonts-liberation libgbm1 xdg-utils
- run:
name: Download and install official Google Chrome package
command: wget 'https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb' && sudo dpkg -i google-chrome-stable_current_amd64.deb
- run:
name: Run tests
command: npm run test:integration
- store_artifacts:
path: ./screenshots
site-deploy:
docker:
- image: cimg/node:15.1
Expand All @@ -45,7 +53,7 @@ jobs:
at: .
- run:
name: Firebase Deploy
command: ./node_modules/.bin/firebase deploy --only hosting --token "$FIREBASE_TOKEN"
command: ./node_modules/.bin/firebase deploy --only hosting,functions --token "$FIREBASE_TOKEN"
workflows:
# Below is the definition of your workflow.
# Inside the workflow, you provide the jobs you want to run, e.g this workflow runs the build-and-test job above.
Expand Down
119 changes: 105 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# Rally Web Platform Spike
# Rally Web Platform

This repository contains the code for the user management experience. It is implemented in [Sveltekit](https://kit.svelte.dev/), a next.js-like framework for [Svelte](https://svelte.dev/).
This repository contains the code needed to build the Rally Web Platform.
Mozilla Rally is an opt-in data collection platform.

The Rally Web Platform consists of:

- A static website, built with Svelte.
- A storage and authentication backend, powered by Firebase.
- One or more WebExtensions which collect and submit user browsing data.

The website is used to create/log in to a Rally account, and allows users to
control what data is collected by any installed WebExtension(s).

WebExtensions are built from the [Rally Study Template](https://github.com/mozilla-rally/study-template).

## Requirements
* [Node.js](https://nodejs.org/en/)
* [Mozilla web-ext](https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/)

This repository contains the code needed to build the Rally Study 01 Web Extension.
The study submits data through [Mozilla Rally's Web Extension](https://github.com/mozilla-rally/rally-core-addon),
or can be run locally without Mozilla Rally installed on your computer.
* [Node.js](https://nodejs.org/en/)
* [Firebase](https://firebase.google.com/docs/cli)
* Authentication
* Functions
* Firestore
* Hosting
rhelmer marked this conversation as resolved.
Show resolved Hide resolved

## Quickstart

Expand All @@ -17,25 +30,103 @@ or can be run locally without Mozilla Rally installed on your computer.
3. Run `npm run dev` to spin up the dev environment at `localhost:3000`
4. Run `npm run build` to build the app; the results will be in `/build`

## Emulating the server backend (Firebase)

### Starting the emulators
The `firebase-tools` node package provides a suite of emulators for the various Firebase services:
`npm install -g firebase-tools`

By default, all emulators specified in `./firebase.json` will be started with an empty database and no user accounts:
`firebase emulators:start`

NOTE: any modifications you make within the emulators will not be saved, by default! You can save all data on exit
by passing `--export-on-exit`:
`firebase emulators:start --export-on-exit ./my-test-data/`

You may then load this data into the emulator on startup:
`firebase emulators:start --import ./my-test-data/`

You may find the test data used for integration tests helpfully for local development too:
`firebase emulators:start ./tests/integration/testdata`

### Configuring and using the emulators

Firebase will output something similar to the following:

```
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://localhost:4000 │
└─────────────────────────────────────────────────────────────┘

┌────────────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Authentication │ localhost:9099 │ http://localhost:4000/auth │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Functions │ localhost:5001 │ http://localhost:4000/functions │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Hosting │ localhost:5000 │ n/a │
└────────────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at localhost:4400
Other reserved ports: 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
```

You may now browse to http://localhost:4000 to access the various emulator control panels,
which allow you to add/remove users and documents from the Firestore database.

### Configuring the Rally Web Platform website and WebExtensions to use the emulators

When the website is re-built in "test integration" mode, it will automatically deploy to the emulated Firebase Hosting:
`npm run build:test:integration`

Clients wishing to connect to the Firebase emulators, including the website any WebExtensions, must set
this explicitly in their code after initializing the services.

Connecting to the Firebase Authentication
rhelmer marked this conversation as resolved.
Show resolved Hide resolved
```ts
const auth = getAuth(app);
connectAuthEmulator(auth, 'http://localhost:9099');
```

Connecting to the Firebase Firestore emulator:
```ts
db = getFirestore(app);
connectFirestoreEmulator(db, 'localhost', 8080);
```

## Tests

This repository comes (aspirationally) with
- unit tests: run `npm run test:unit`
Integration tests can be run with:

- integration tests: run `npm run test:integration`

These are currently severely underdeveloped right now.
Once we feel a bit more comfortable with the state of this branch,
we will prioritize integration testing.
This uses Selenium and the Firebase Emulators to run the full Rally Web Platform stack and test that
the various supported UX flows work as expected.

This repository comes (aspirationally) with unit tests:
- run `npm run test:unit`

These are currently severely underdeveloped right now, we are currently prioritizing
integration testing.


## Organization

There are two primary source file directories: `src/lib` and `src/routes`:
- `src/lib` – the components and utility functions utilized in the frontend.
- `src/lib/stores` – contains the overarching application store & any derived stores. These set in the context of the layouts in `src/routes`, which gives access to the global store to all children components (including pages).
- `src/lib/views` – the standalone views that get utilized for individual pages. We are breaking these out separately because we utilize the same content & functionality blocks on multiple routes (e.g. for onboarding, `/welcome/terms` and for the main view, `/terms`).
- The rest of the components and functions in `/src/lib/` are used throughout the page components and the views.
- `src/routes` – the page components utilized in the routes. Sveltekit's routing is directory-based; so `src/routes/terms/index.svelte` maps to `/terms`, and `src/routes/welcome/profile/index.svelte` maps to `/welcome/profile`.

- `functions` - Firebase functions needed to support the Rally Web Platform.

`svelte.config.js` – contains the configuration of the Sveltekit app. Sveltekit utilizes Vite under the hood, and has support for both Vite and Rollup plugins.

`firebase.config.js` – contains our public firebase configuration for this application.
`firebase.config.js` – contains our public firebase configuration for this application.

`firebase.json` - contains the server-side configuration for this Firebase project.
6 changes: 6 additions & 0 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
presets: [
['@babel/preset-env', { targets: { node: 'current' } }],
'@babel/preset-typescript',
],
};
4 changes: 0 additions & 4 deletions babel.config.js

This file was deleted.

8 changes: 8 additions & 0 deletions docs/rally_token.mermaid
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sequenceDiagram
Rally Website->>Firebase: User credentials
Firebase-->>Rally Website: IDToken (web)
Rally Website->>Rally Function: IDToken (web)
Rally Function-->>Rally Website: Custom Token
Rally Website->>Rally Extension: Custom Token
Rally Extension-->>Firebase: Custom Token
Firebase-)Rally Extension: IDToken (extension)
30 changes: 29 additions & 1 deletion firebase.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
{
"hosting": {
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
},
"functions": {
"source": "functions",
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
},
"emulators": {
"auth": {
"port": 9099
},
"functions": {
"port": 5001
},
"firestore": {
"port": 8080
},
"hosting": {
"port": 5000
},
"ui": {
"enabled": true
}
}
}
30 changes: 30 additions & 0 deletions functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings",
"plugin:import/typescript",
"google",
"plugin:@typescript-eslint/recommended",
],
parser: "@typescript-eslint/parser",
parserOptions: {
project: ["tsconfig.json", "tsconfig.dev.json"],
sourceType: "module",
},
ignorePatterns: [
"/lib/**/*", // Ignore built files.
],
plugins: [
"@typescript-eslint",
"import",
],
rules: {
quotes: ["error", "double"],
},
};
9 changes: 9 additions & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Compiled JavaScript files
lib/**/*.js
lib/**/*.js.map

# TypeScript v1 declaration files
typings/

# Node.js dependency directory
node_modules/
Loading