Skip to content

Commit e20f19c

Browse files
authored
test: Add tests for firebaseui-core
2 parents b5e3231 + df77f0c commit e20f19c

File tree

14 files changed

+2021
-23
lines changed

14 files changed

+2021
-23
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Integration Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
integration-test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [22.x]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
25+
- name: Setup Java for Firebase Emulator
26+
uses: actions/setup-java@v4
27+
with:
28+
distribution: "temurin"
29+
java-version: "17"
30+
31+
- name: Install pnpm
32+
uses: pnpm/action-setup@v2
33+
with:
34+
version: 8
35+
36+
- name: Install dependencies
37+
run: pnpm install
38+
39+
- name: Install Firebase Tools
40+
run: npm install -g firebase-tools
41+
42+
- name: Create Firebase config
43+
run: |
44+
cat > firebase.json << EOF
45+
{
46+
"emulators": {
47+
"auth": {
48+
"port": 9099
49+
},
50+
"ui": {
51+
"enabled": false
52+
}
53+
}
54+
}
55+
EOF
56+
57+
- name: Start Firebase Emulator and Run Integration Tests
58+
run: |
59+
firebase emulators:start &
60+
sleep 10
61+
pnpm --filter @firebase-ui/core test:integration

.github/workflows/unit-tests.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
unit-test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
node-version: [22.x]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
25+
- name: Install pnpm
26+
uses: pnpm/action-setup@v2
27+
with:
28+
version: 8
29+
30+
- name: Install dependencies
31+
run: pnpm install
32+
33+
- name: Run unit tests
34+
run: pnpm --filter @firebase-ui/core test

packages/firebaseui-core/.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Firebase
2+
firebase-debug.log
3+
ui-debug.log
4+
.firebaserc
5+
6+
# Build output
7+
dist/
8+
*.tgz
9+
10+
# Dependencies
11+
node_modules/
12+
13+
# Environment variables
14+
.env*
15+
16+
# IDE
17+
.idea/
18+
.vscode/
19+
*.swp
20+
*.swo
21+
22+
# OS
23+
.DS_Store
24+
Thumbs.db
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"emulators": {
3+
"auth": {
4+
"port": 9099
5+
},
6+
"ui": {
7+
"enabled": true,
8+
"port": 4000
9+
},
10+
"singleProjectMode": true
11+
}
12+
}

packages/firebaseui-core/package.json

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@
2121
"build:local": "pnpm run build && pnpm pack",
2222
"dev": "tsup --watch",
2323
"lint": "tsc --noEmit",
24-
"format": "prettier --write \"src/**/*.ts\"",
25-
"clean": "rimraf dist"
24+
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
25+
"clean": "rimraf dist",
26+
"test": "vitest run tests/unit",
27+
"test:watch": "vitest tests/unit",
28+
"test:integration": "vitest run tests/integration",
29+
"test:integration:watch": "vitest tests/integration",
30+
"test:all": "vitest run"
2631
},
2732
"keywords": [
2833
"firebase",
@@ -40,9 +45,14 @@
4045
"zod": "^3.24.1"
4146
},
4247
"devDependencies": {
43-
"typescript": "^5.7.3",
44-
"tsup": "^8.0.1",
48+
"@types/jsdom": "^21.1.7",
49+
"firebase": "^11.0.0",
50+
"jsdom": "^26.0.0",
4551
"prettier": "^3.1.1",
46-
"rimraf": "^6.0.1"
52+
"rimraf": "^6.0.1",
53+
"tsup": "^8.0.1",
54+
"typescript": "^5.7.3",
55+
"vite": "^6.2.0",
56+
"vitest": "^3.0.7"
4757
}
4858
}

packages/firebaseui-core/src/auth.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,9 @@ import {
1818
RecaptchaVerifier,
1919
AuthProvider,
2020
} from 'firebase/auth';
21-
import { FirebaseUIError } from './errors';
21+
import { handleFirebaseError } from './errors';
2222
import { type TranslationsConfig } from './translations';
2323

24-
function handleFirebaseError(error: any, translations?: TranslationsConfig, language?: string): never {
25-
// TODO: Debug why instanceof FirebaseError is not working
26-
if (error?.name === 'FirebaseError') {
27-
throw new FirebaseUIError(error, translations, language);
28-
}
29-
throw new FirebaseUIError({ code: 'unknown' }, translations, language);
30-
}
31-
3224
export async function fuiSignInWithEmailAndPassword(
3325
auth: Auth,
3426
email: string,

packages/firebaseui-core/src/errors.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ export class FirebaseUIError extends Error {
1313
this.code = errorCode;
1414
}
1515
}
16+
17+
export function handleFirebaseError(error: any, translations?: TranslationsConfig, language?: string): never {
18+
// TODO: Debug why instanceof FirebaseError is not working
19+
if (error?.name === 'FirebaseError') {
20+
throw new FirebaseUIError(error, translations, language);
21+
}
22+
throw new FirebaseUIError({ code: 'unknown' }, translations, language);
23+
}

0 commit comments

Comments
 (0)