Skip to content
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
2 changes: 1 addition & 1 deletion .size-limit.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ module.exports = [
import: createImport('init'),
ignore: [...builtinModules, ...nodePrefixedBuiltinModules],
gzip: true,
limit: '157 KB',
limit: '158 KB',
},
{
name: '@sentry/node - without tracing',
Expand Down

This file was deleted.

80 changes: 33 additions & 47 deletions dev-packages/e2e-tests/test-applications/node-firebase/README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,50 @@
## Assuming you already have installed docker desktop or orbstack etc. or any other docker software
<center>
<a href="https://firebase.google.com/" target="_blank">
<img src="https://firebase.google.com/static/downloads/brand-guidelines/SVG/logo-standard.svg" alt="Firebase" width="200">
</a>
</center>

### Enabling / authorising firebase emulator through docker
## Description

1. Run the docker
[Firebase](https://firebase.google.com/) starter repository with Cloud Functions for Firebase and Firestore.

```bash
pnpm docker
```

2. In new tab, enter the docker container by simply running
## Project setup

```bash
docker exec -it sentry-firebase bash
```sh
$ pnpm install
```

3. Now inside docker container run
## Compile and run the project

```bash
firebase login
```sh
$ pnpm dev # builds the functions and firestore app
$ pnpm emulate
$ pnpm start # run the firestore app
```

4. You should now see a long link to authenticate with google account, copy the link and open it using your browser
5. Choose the account you want to authenticate with
6. Once you do this you should be able to see something like "Firebase CLI Login Successful"
7. And inside docker container you should see something like "Success! Logged in as <here is the email you have chosen>"
8. Now you can exit docker container

```bash
exit
```
## Run tests

9. Switch back to previous tab, stop the docker container (ctrl+c).
10. You should now be able to run the test, as you have correctly authenticated the firebase emulator
Either run the tests directly:

### Preparing data for CLI

1. Please authorize the docker first - see the previous section
2. Once you do that you can generate .env file locally, to do that just run

```bash
npm run createEnvFromConfig
```sh
$ pnpm test:build
$ pnpm test:assert
```

3. It will create a new file called ".env" inside folder "docker"
4. View the file. There will be 2 params CONFIG_FIREBASE_TOOLS and CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS.
5. Now inside the CLI create a new variable under the name CONFIG_FIREBASE_TOOLS and
CONFIG_UPDATE_NOTIFIER_FIREBASE_TOOLS - take values from mentioned .env file
6. File .env is ignored to avoid situation when developer after authorizing firebase with private account will
accidently push the tokens to github.
7. But if we want the users to still have some default to be used for authorisation (on their local development) it will
be enough to commit this file, we just have to authorize it with some "special" account.
Or run develop while running the tests directly against the emulator. Start each script in a separate terminal:

**Some explanation towards environment settings, the environment variable defined directly in "environments" takes
precedence over .env file, that means it will be safe to define it in CLI and still keeps the .env file.**
```sh
$ pnpm dev
$ pnpm emulate
$ pnpm test --ui
```

### Scripts - helpers
The tests will run against the Firebase Emulator Suite.

- createEnvFromConfig - it will use the firebase docker authentication and create .env file which will be used then by
docker whenever you run emulator
- createConfigFromEnv - it will use '.env' file in docker folder to create .config for the firebase to be used to
authenticate whenever you run docker, Docker by default loads .env file itself
## Resources

Use these scripts when testing and updating the environment settings on CLI
- [Firebase](https://firebase.google.com/)
- [Firebase Emulator Suite](https://firebase.google.com/docs/emulator-suite)
- [Firebase SDK](https://firebase.google.com/docs/sdk)
- [Firebase Functions](https://firebase.google.com/docs/functions)
- [Firestore](https://firebase.google.com/docs/firestore)
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,12 @@
"enabled": true
},
"singleProjectMode": true
}
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": ["node_modules", ".git", "firebase-debug.log", "firebase-debug.*.log", "*.local"]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "firestore-app",
"private": true,
"scripts": {
"build": "tsc",
"dev": "tsc --build --watch",
"start": "node ./dist/app.js"
},
"dependencies": {
"@firebase/app": "^0.13.1",
"@sentry/node": "latest || *",
"express": "^4.18.2",
"firebase": "^12.0.0"
},
"devDependencies": {
"@types/express": "^4.17.13",
"@types/node": "^22.13.14",
"typescript": "5.9.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"skipLibCheck": true
},
"include": ["src"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "functions",
"scripts": {
"build": "tsc",
"dev": "tsc --build --watch"
},
"engines": {
"node": "20"
},
"main": "dist/index.js",
"dependencies": {
"firebase-admin": "^12.6.0",
"firebase-functions": "^6.0.1",
"@sentry/node": "latest || *"
},
"devDependencies": {
"typescript": "5.9.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import './init';

import { onDocumentCreated, onDocumentCreatedWithAuthContext } from 'firebase-functions/firestore';
import { onRequest } from 'firebase-functions/https';
import * as logger from 'firebase-functions/logger';
import { setGlobalOptions } from 'firebase-functions/options';
import * as admin from 'firebase-admin';

setGlobalOptions({ region: 'default' });

admin.initializeApp();

const db = admin.firestore();

export const helloWorld = onRequest(async (request, response) => {
logger.info('Hello logs!', { structuredData: true });

response.send('Hello from Firebase!');
});

export const unhandeledError = onRequest(async (request, response) => {
throw new Error('There is an error!');
});

export const onCallSomething = onRequest(async (request, response) => {
const data = {
name: request.body?.name || 'Sample Document',
timestamp: performance.now(),
description: request.body?.description || 'Created via Cloud Function',
};

await db.collection('documents').add(data);

logger.info('Create document!', { structuredData: true });

response.send({ message: 'Document created!' });
});

export const onDocumentCreate = onDocumentCreated('documents/{documentId}', async event => {
const documentId = event.params.documentId;

await db.collection('documents').doc(documentId).update({
processed: true,
processedAt: new Date(),
});
});

export const onDocumentCreateWithAuthContext = onDocumentCreatedWithAuthContext('documents/{documentId}', async () => {
// noop
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as Sentry from '@sentry/node';

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '1.0',
tracesSampleRate: 1.0,
integrations: [Sentry.firebaseIntegration()],
defaultIntegrations: false,
tunnel: `http://localhost:3031/`, // proxy server
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"skipLibCheck": true
},
"include": ["src"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@
"version": "0.0.1",
"private": true,
"scripts": {
"build": "tsc",
"dev": "tsc --build --watch",
"build": "pnpm run -r build",
"dev": "pnpm run -r dev",
"proxy": "node start-event-proxy.mjs",
"emulate": "firebase emulators:start &",
"start": "node ./dist/app.js",
"emulate": "firebase emulators:start --project demo-functions",
"start": "pnpm run -r start",
"test": "playwright test",
"clean": "npx rimraf node_modules pnpm-lock.yaml",
"clean": "npx rimraf node_modules **/node_modules pnpm-lock.yaml **/dist *-debug.log test-results",
"test:build": "pnpm install && pnpm build",
"test:assert": "pnpm firebase emulators:exec 'pnpm test'"
"test:assert": "pnpm firebase emulators:exec --project demo-functions 'pnpm test'"
},
"dependencies": {
"@firebase/app": "^0.13.1",
"@sentry/node": "latest || *",
"@sentry/core": "latest || *",
"@sentry/opentelemetry": "latest || *",
"@types/node": "^18.19.1",
"@types/node": "^22.13.14",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"firebase": "^12.0.0",
"firebase-admin": "^12.0.0",
"tsconfig-paths": "^4.2.0",
"typescript": "4.9.5"
"typescript": "5.9.3"
},
"devDependencies": {
"@playwright/test": "~1.53.2",
"@sentry-internal/test-utils": "link:../../../test-utils",
"@types/express": "^4.17.13",
"firebase-tools": "^12.0.0"
"firebase-tools": "^14.20.0"
},
"volta": {
"extends": "../../package.json"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
- 'functions'
- 'firestore-app'
Loading
Loading