Skip to content

Commit

Permalink
feat: switch to firebase-admin module imports (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
prescottprue committed Sep 5, 2022
1 parent b859acf commit 2dce7ff
Show file tree
Hide file tree
Showing 28 changed files with 7,968 additions and 7,788 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ module.exports = {
trailingComma: 'all', // airbnb
},
],
// NOTE: This is added since eslint-plugin-import does not support exports in package.json
// which is what firebase-admin v10 uses. See: https://github.com/import-js/eslint-plugin-import/issues/1810
'import/no-unresolved': [
2,
{
ignore: [
'firebase-admin/database',
'firebase-admin/app',
'firebase-admin/auth',
'firebase-admin/storage',
'firebase-admin/firestore',
],
},
],
},
overrides: [
{
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: "CodeQL"
name: 'CodeQL'

on:
push:
branches: [ main ]
branches: [main]
pull_request:
# The branches below must be a subset of the branches above
branches: [ main ]
branches: [main]
schedule:
- cron: '24 2 * * 4'

Expand All @@ -19,14 +19,14 @@ jobs:
security-events: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: 'javascript'
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: 'javascript'

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ concurrency:
group: publish-${{ github.ref }}

env:
NODE_VERSION: 14.x
NODE_VERSION: 16.x

jobs:
publish-npm:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [16.x]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down Expand Up @@ -45,7 +45,7 @@ jobs:

- name: Upload Test Coverage
uses: codecov/codecov-action@v3
if: matrix.node-version == '14.x'
if: matrix.node-version == '16.x'
with:
fail_ci_if_error: false

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,22 @@ If you are interested in what drove the need for this checkout [the why section]

### Pre-Setup

1. If you do not already have it installed, install Cypress and add it to your package file: `npm i --save-dev cypress` or `yarn add -D cypress`
1. If you do not already have it installed, install Cypress and firebase-admin and add them to your package file: `npm i --save-dev cypress firebase-admin` or `yarn add -D cypress firebase-admin`
1. Make sure you have a `cypress` folder containing Cypress tests
1. `cypress-firebase` v3 uses firebase-admin v11 - if you want to use an earlier version of firebase-admin, use `^2` versions of `cypress-firebase`

### Setup

1. Set the following config in your `cypress.config.js` or `cypress.config.ts`

```js
import admin from 'firebase-admin';
import { initializeApp } from 'firebase-admin/app';
import { defineConfig } from 'cypress';
import { plugin as cypressFirebasePlugin } from 'cypress-firebase';

// Initialize firebase-admin default app
initializeApp();

const cypressConfig = defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
Expand All @@ -56,15 +60,17 @@ If you are interested in what drove the need for this checkout [the why section]
```js
const { defineConfig } = require('cypress');
const cypressFirebasePlugin = require('cypress-firebase').plugin;
const admin = require('firebase-admin');
const { initializeApp } = require('firebase-admin/app');

// Initialize firebase-admin default app
initializeApp();

module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
supportFile: 'cypress/support/e2e/index.js',
setupNodeEvents(on, config) {
cypressFirebasePlugin(on, config, admin);
// e2e testing node events setup code
return cypressFirebasePlugin(on, config, admin);
},
},
});
Expand Down
13 changes: 7 additions & 6 deletions examples/basic/cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
const { defineConfig } = require('cypress')
const tasks = require('cypress-firebase/lib/tasks')
const cypressFirebasePlugin = require('cypress-firebase').plugin
const admin = require('firebase-admin')
const { initializeApp } = require('firebase-admin/app');

// Initialize firebase-admin default app
initializeApp()

module.exports = defineConfig({
e2e: {
baseUrl: 'http://localhost:3000',
// supportFile: false,
supportFile: 'cypress/support/e2e/index.js',
setupNodeEvents(on, config) {
cypressFirebasePlugin(on, config, admin)
// e2e testing node events setup code
return cypressFirebasePlugin(on, config)
},
},
// Uncomment to enable for component testing
// component: {
// setupNodeEvents(on, config) {
// // component testing node events setup code
// return cypressFirebasePlugin(on, config)
// },
// },
})
15 changes: 15 additions & 0 deletions examples/typescript/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { plugin as cypressFirebasePlugin } from 'cypress-firebase';
import { initializeApp } from 'firebase-admin/app';
import { defineConfig } from 'cypress';

initializeApp()

const cypressConfig = defineConfig({
e2e: {
setupNodeEvents(on, config): Cypress.PluginConfigOptions {
return cypressFirebasePlugin(on, config);
},
},
});

export default cypressConfig;
1 change: 0 additions & 1 deletion examples/typescript/cypress.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,5 @@ describe('Projects View', () => {
expect(result).to.exist;
expect(result).to.be.an('object');
});
;
});
});
10 changes: 0 additions & 10 deletions examples/typescript/cypress/plugins/index.ts

This file was deleted.

File renamed without changes.
47 changes: 24 additions & 23 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@
"name": "typescript",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.0.0",
"@types/jest": "^28.0.0",
"@types/node": "^16.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"firebase": "^9.5.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"typescript": "^4.1.2",
"web-vitals": "^2.0.0"
},
"scripts": {
"start": "react-scripts start",
"start:emulate": "cross-env REACT_APP_USE_DB_EMULATORS=true yarn start",
Expand All @@ -29,6 +14,30 @@
"test:open": "cross-env GCLOUD_PROJECT=redux-firebasev3 CYPRESS_baseUrl=http://localhost:3000 cypress open",
"test:emulate": "cross-env FIREBASE_AUTH_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.auth.port)\" FIREBASE_DATABASE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.database.port)\" FIRESTORE_EMULATOR_HOST=\"localhost:$(cat firebase.json | jq .emulators.firestore.port)\" yarn test:open"
},
"dependencies": {
"firebase": "^9.9.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"web-vitals": "^2.0.0"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^12.0.0",
"@testing-library/user-event": "^13.0.0",
"@types/jest": "^28.0.0",
"@types/node": "^16.0.0",
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"cross-env": "7.0.3",
"cypress": "10.7.0",
"cypress-firebase": "2.2.2",
"eslint-plugin-chai-friendly": "0.7.2",
"eslint-plugin-cypress": "2.12.1",
"firebase-admin": "11.0.1",
"firebase-tools": "11.8.0",
"react-scripts": "5.0.1",
"typescript": "^4.8.2"
},
"eslintConfig": {
"extends": [
"react-app",
Expand All @@ -46,13 +55,5 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"cross-env": "7.0.3",
"cypress": "10.3.0",
"cypress-firebase": "2.2.2",
"eslint-plugin-chai-friendly": "0.7.2",
"eslint-plugin-cypress": "2.12.1",
"firebase-tools": "10.9.2"
}
}
Loading

0 comments on commit 2dce7ff

Please sign in to comment.