Skip to content

Commit

Permalink
Dusting things off (#119)
Browse files Browse the repository at this point in the history
* Bump minor
* Bump github actions
* Bump firebase dep
* Bump emulators
* Refactored tests
  * `take(1)` where needed
  * clean up race conditions
  * drop delete app hack (except for firestore...)
  * retry on a flaky RTDB test
  • Loading branch information
jamesdaniels authored Dec 12, 2024
1 parent 5cfad21 commit b91f358
Show file tree
Hide file tree
Showing 16 changed files with 3,644 additions and 7,141 deletions.
60 changes: 27 additions & 33 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@ jobs:
name: Build
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v4
with:
node-version: '20'
- name: node_modules cache
uses: actions/cache@v2
uses: actions/cache@v4
id: node_modules_cache
with:
path: ./node_modules
key: ${{ runner.os }}-20-node_modules-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-20-11-7-node_modules-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-20-node_modules-
${{ runner.os }}-20-11-7-node_modules-
${{ runner.os }}-20-
- name: Yarn offline cache
if: steps.node_modules_cache.outputs.cache-hit != 'true'
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.npm-packages-offline-cache
key: yarn-offline-${{ hashFiles('**/yarn.lock') }}
Expand All @@ -49,7 +50,7 @@ jobs:
id: yarn-pack-dir
run: ./build.sh
- name: 'Upload Artifact'
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: rxfire-${{ github.run_id }}
path: dist
Expand All @@ -61,38 +62,38 @@ jobs:
strategy:
matrix:
node: ["20"]
firebase: ["9", "10"]
firebase: ["9", "10", "11"]
rxjs: ["6", "7"]
fail-fast: false
name: Test firebase@${{ matrix.firebase }} rxjs@${{ matrix.rxjs }} on Node.js ${{ matrix.node }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
check-latest: true
- name: node_modules cache
id: node_modules_cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ./node_modules
key: ${{ runner.os }}-${{ matrix.node }}-${{ matrix.firebase }}-${{ matrix.rxjs }}-node_modules-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node }}-${{ matrix.firebase }}-${{ matrix.rxjs }}-node_modules-
${{ runner.os }}-${{ matrix.node }}-node_modules-
${{ runner.os }}-${{ matrix.node }}-
- name: test/functions node_modules cache
id: functions_node_modules_cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ./test/functions/node_modules
key: ${{ runner.os }}-${{ matrix.node }}-functions_node_modules-${{ hashFiles('test/functions/yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node }}-functions_node_modules-
- name: Yarn offline cache
if: steps.node_modules_cache.outputs.cache-hit != 'true' || steps.functions_node_modules_cache.outputs.cache-hit != 'true'
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.npm-packages-offline-cache
key: yarn-offline-${{ hashFiles('**/yarn.lock') }}
Expand All @@ -110,46 +111,40 @@ jobs:
cd test/functions
yarn install --frozen-lockfile --prefer-offline
- name: Firebase emulator cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.cache/firebase/emulators
key: firebase_emulators
- name: 'Download Artifacts'
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
- name: Run tests
run: |
mv rxfire-${{ github.run_id }} dist
yarn test
lint:
runs-on: ubuntu-latest
strategy:
matrix:
node: ["20"]
firebase: ["9", "10"]
rxjs: ["7"]
fail-fast: false
name: Lint
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
node-version: "20"
check-latest: true
- name: node_modules cache
id: node_modules_cache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ./node_modules
key: ${{ runner.os }}-${{ matrix.node }}-${{ matrix.firebase }}-${{ matrix.rxjs }}-node_modules-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-20-11-7-node_modules-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.node }}-${{ matrix.firebase }}-${{ matrix.rxjs }}-node_modules-
${{ runner.os }}-${{ matrix.node }}-node_modules-
${{ runner.os }}-20-11-7-node_modules-
${{ runner.os }}-20-
- name: Yarn offline cache
if: steps.node_modules_cache.outputs.cache-hit != 'true' || steps.functions_node_modules_cache.outputs.cache-hit != 'true'
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ~/.npm-packages-offline-cache
key: yarn-offline-${{ hashFiles('**/yarn.lock') }}
Expand All @@ -159,7 +154,6 @@ jobs:
run: |
yarn config set yarn-offline-mirror ~/.npm-packages-offline-cache
yarn install --frozen-lockfile --prefer-offline
yarn add --dev firebase@${{ matrix.firebase }} rxjs@${{ matrix.rxjs }} --prefer-offline
- name: Run lint
run: |
yarn lint
Expand All @@ -171,12 +165,12 @@ jobs:
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'release' }}
steps:
- name: Setup node
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://wombat-dressing-room.appspot.com'
- name: 'Download Artifacts'
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
- name: Publish
run: |
cd ./rxfire-${{ github.run_id }}
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules
dist
/*.log
*.log
/rxfire-*.tgz
.firebase
.yarn
1 change: 1 addition & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodeLinker: node-modules
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rxfire",
"version": "6.0.6",
"version": "6.1.0",
"private": true,
"description": "Firebase JavaScript library RxJS",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
Expand Down Expand Up @@ -82,14 +82,13 @@
"build:docs": "cp README.md ./dist/ && cp -r ./docs ./dist/",
"dev": "rollup -c -w",
"echo:chrome": "echo 'Open Chrome DevTools: \nchrome://inspect/#devices'",
"test": "firebase emulators:exec \"jest --detectOpenHandles\" --project=rxfire-test-c497c",
"test": "npx -y firebase-tools@latest emulators:exec \"jest --detectOpenHandles\" --project=rxfire-test-c497c",
"test:debug": "yarn echo:chrome && firebase emulators:exec ./test-debug.sh --project=rxfire-test-c497c",
"emulators": "firebase emulators:start --project=rxfire-test-c497c",
"emulators": "npx -y firebase-tools@latest emulators:start --project=rxfire-test-c497c",
"jest": "jest --detectOpenHandles"
},
"dependencies": {},
"peerDependencies": {
"firebase": "^9.0.0 || ^10.0.0",
"firebase": "^9.0.0 || ^10.0.0 || ^11.0.0",
"rxjs": "^6.0.0 || ^7.0.0"
},
"devDependencies": {
Expand All @@ -107,7 +106,6 @@
"eslint": "^7.32.0",
"eslint-config-google": "^0.14.0",
"firebase": "^10.0.0",
"firebase-tools": "^12.5.2",
"glob": "^7.1.6",
"jest": "^29.6.4",
"jest-environment-jsdom": "^29.6.4",
Expand Down
12 changes: 4 additions & 8 deletions test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {default as config, authEmulatorPort} from './config';
import {initializeApp, FirebaseApp, deleteApp} from 'firebase/app';
import {default as config, resolvedAuthEmulatorPort} from './config';
import {initializeApp, FirebaseApp} from 'firebase/app';
import {getAuth, Auth, connectAuthEmulator, signInAnonymously} from 'firebase/auth';
import {authState} from '../dist/auth';
import {skip, take} from 'rxjs/operators';
Expand All @@ -25,14 +25,10 @@ describe('RxFire Auth', () => {
let app: FirebaseApp;
let auth: Auth;

beforeEach(() => {
beforeEach(async () => {
app = initializeApp(config);
auth = getAuth(app);
connectAuthEmulator(auth, `http://localhost:${authEmulatorPort}`, {disableWarnings: true});
});

afterEach(() => {
deleteApp(app).catch(() => undefined);
connectAuthEmulator(auth, `http://localhost:${await resolvedAuthEmulatorPort}`, {disableWarnings: true});
});

describe('Authentication state', () => {
Expand Down
20 changes: 14 additions & 6 deletions test/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as firebaseConfig from '../firebase.json';
import fetch from 'cross-fetch';

export default {
apiKey: 'AIzaSyCD1LqWoxivr0hu7YJ_xF6WyAT4_l-Aw0I',
Expand All @@ -11,8 +11,16 @@ export default {
measurementId: 'G-K35MQE7EN2',
};

export const authEmulatorPort = firebaseConfig.emulators.auth.port;
export const databaseEmulatorPort = firebaseConfig.emulators.database.port;
export const firestoreEmulatorPort = firebaseConfig.emulators.firestore.port;
export const storageEmulatorPort = firebaseConfig.emulators.storage.port;
export const functionsEmulatorPort = firebaseConfig.emulators.functions.port;
const resolvedEmulatorHubResponse = (async () => {
await new Promise((resolve) => setTimeout(resolve, 1_000));
if (!process.env.FIREBASE_EMULATOR_HUB) throw new Error('$FIREBASE_EMULATOR_HUB not found');
const response = await fetch(`http://${process.env.FIREBASE_EMULATOR_HUB}/emulators`);
if (!response.ok) throw new Error('Unable to fetch emulator hub REST api.');
return await response.json();
})();

export const resolvedAuthEmulatorPort = resolvedEmulatorHubResponse.then((it) => it.auth.port);
export const resolvedDatabaseEmulatorPort = resolvedEmulatorHubResponse.then((it) => it.database.port);
export const resolvedFirestoreEmulatorPort = resolvedEmulatorHubResponse.then((it) => it.firestore.port);
export const resolvedStorageEmulatorPort = resolvedEmulatorHubResponse.then((it) => it.storage.port);
export const resolvedFunctionsEmulatorPort = resolvedEmulatorHubResponse.then((it) => it.functions.port);
Loading

0 comments on commit b91f358

Please sign in to comment.