Skip to content

Commit cb19c2e

Browse files
fix(ci): run integration tests with Firebase Extensions emulator
Auth tests were starting only the functions emulator, so extension env vars never reached Cloud Functions and Stream sync timed out. Start the extensions emulator, drop duplicate functions deploy config, and call ext-auth-chat-getStreamUserToken in the correct LOCATION region. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 0710057 commit cb19c2e

6 files changed

Lines changed: 19 additions & 16 deletions

File tree

integration-tests/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ npm test
66

77
Use Node.js 20 when running the test suite locally. The repo includes a top-level `.nvmrc` to keep the extension packages, CI, and emulator runs aligned on the same runtime.
88

9+
Auth integration tests start the **Extensions** emulator (`--only auth,functions,extensions`) so Stream API credentials from `extensions/*.env.local` are passed into extension functions. Callable tests must target `ext-auth-chat-getStreamUserToken` (region = `LOCATION` in env files).
10+
911
## Locally
1012

1113
You'll need the following files to set the right environment variables.

integration-tests/firebase.auth-activity-feeds.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
"extensions": {
33
"auth-activity-feeds": "../auth-activity-feeds"
44
},
5-
"functions": {
6-
"source": "../auth-activity-feeds/functions",
7-
"runtime": "nodejs20",
8-
"region": "europe-west1"
9-
},
105
"emulators": {
116
"hub": {
127
"port": 4000

integration-tests/firebase.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
"extensions": {
33
"auth-chat": "../auth-chat"
44
},
5-
"functions": {
6-
"source": "../auth-chat/functions",
7-
"runtime": "nodejs20",
8-
"region": "europe-west1"
9-
},
105
"emulators": {
116
"hub": {
127
"port": 4000

integration-tests/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"prepare": "npm install --prefix ../auth-activity-feeds/functions && npm install --prefix ../auth-chat/functions && npm install --prefix ../firestore-activity-feeds/functions",
44
"test": "node scripts/validate-extension-env.js && npm run test-auth && npm run test-token-generation && npm run test-firestore",
55
"test:unit": "npm --prefix ../auth-chat/functions ci && npm --prefix ../auth-chat/functions test",
6-
"test-token-generation": "firebase emulators:exec --only auth,functions --project demo-stream --config firebase.json --log-verbosity SILENT 'npx jest token-generation.test.ts --runInBand --detectOpenHandles --forceExit'",
6+
"test-token-generation": "firebase emulators:exec --only auth,functions,extensions --project demo-stream --config firebase.json --log-verbosity SILENT 'npx jest token-generation.test.ts --runInBand --detectOpenHandles --forceExit'",
77
"test-auth": "npm run test-auth-chat && npm run test-auth-activity-feeds",
8-
"test-auth-chat": "firebase emulators:exec --only auth,functions --project demo-stream --config firebase.json --log-verbosity SILENT 'npx jest auth-chat.test.ts --runInBand --detectOpenHandles --forceExit'",
9-
"test-auth-activity-feeds": "firebase emulators:exec --only auth,functions --project demo-stream --config firebase.auth-activity-feeds.json --log-verbosity SILENT 'npx jest auth-activity-feeds.test.ts --runInBand --detectOpenHandles --forceExit'",
8+
"test-auth-chat": "firebase emulators:exec --only auth,functions,extensions --project demo-stream --config firebase.json --log-verbosity SILENT 'npx jest auth-chat.test.ts --runInBand --detectOpenHandles --forceExit'",
9+
"test-auth-activity-feeds": "firebase emulators:exec --only auth,functions,extensions --project demo-stream --config firebase.auth-activity-feeds.json --log-verbosity SILENT 'npx jest auth-activity-feeds.test.ts --runInBand --detectOpenHandles --forceExit'",
1010
"test-firestore": "sh -c 'cp \"extensions/firestore-activity-feeds.env.local\" \"../firestore-activity-feeds/functions/.env.local\" && cp \"extensions/firestore-activity-feeds.secret.local\" \"../firestore-activity-feeds/functions/.secret.local\" && firebase emulators:exec --only firestore,functions --project demo-stream --config firebase.firestore.json --log-verbosity SILENT \"npx jest firestore.test.ts --runInBand --detectOpenHandles --forceExit\"; rc=$?; rm -f \"../firestore-activity-feeds/functions/.env.local\" \"../firestore-activity-feeds/functions/.secret.local\"; exit $rc'"
1111
},
1212
"engines": {

integration-tests/test/emulator-setup.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ export const emulatorProjectId = projectId;
2828
export const functionsRegion =
2929
process.env.LOCATION?.trim() || 'us-central1';
3030

31+
/** Firebase extension instance id from integration-tests/firebase.json */
32+
export const authChatExtensionInstanceId = 'auth-chat';
33+
34+
export function extensionCallableName(functionName: string): string {
35+
return `ext-${authChatExtensionInstanceId}-${functionName}`;
36+
}
37+
3138
export function syncTimeoutMs(defaultMs: number, ciMs: number): number {
3239
return process.env.CI ? ciMs : defaultMs;
3340
}

integration-tests/test/token-generation.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
} from 'firebase/auth';
1212
import { StreamChat } from 'stream-chat';
1313
import * as dotenv from 'dotenv';
14-
import { emulatorProjectId, functionsRegion } from './emulator-setup';
14+
import {
15+
emulatorProjectId,
16+
extensionCallableName,
17+
functionsRegion,
18+
} from './emulator-setup';
1519

1620
describe('Token Generation', () => {
1721
let auth: Auth;
@@ -94,7 +98,7 @@ describe('Token Generation', () => {
9498
// Get Stream token
9599
const getStreamUserToken = httpsCallable<undefined, string>(
96100
functions,
97-
'getStreamUserToken'
101+
extensionCallableName('getStreamUserToken')
98102
);
99103
try {
100104
const { data: token } = await getStreamUserToken();
@@ -123,7 +127,7 @@ describe('Token Generation', () => {
123127
// Attempt to get Stream token
124128
const getStreamUserToken = httpsCallable<undefined, string>(
125129
functions,
126-
'getStreamUserToken'
130+
extensionCallableName('getStreamUserToken')
127131
);
128132

129133
// Verify it fails with the correct error

0 commit comments

Comments
 (0)