Skip to content

Commit 92a3991

Browse files
committed
test: add test setup with emulator
1 parent 0890b01 commit 92a3991

16 files changed

+2014
-112
lines changed

.firebaserc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"projects": {
3+
"default": "vue-fire-store"
4+
}
5+
}

.github/workflows/test.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
with:
2424
node-version: '16'
2525
cache: 'pnpm'
26+
- run: npm i -g firebase-tools
2627

2728
- name: Install
2829
run: pnpm install
@@ -31,7 +32,7 @@ jobs:
3132
run: pnpm run lint
3233

3334
- name: Test
34-
run: pnpm run test:unit
35+
run: firebase emulators:exec --only firestore 'pnpm run test:unit'
3536

3637
- name: Build
3738
run: pnpm run build

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ package-lock.json
99
.DS_Store
1010
temp
1111
roadmap.md
12+
*-debug.log

firebase.json

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"firestore": {
3+
"rules": "firestore.rules"
4+
},
5+
"emulators": {
6+
"auth": {
7+
"port": 9099
8+
},
9+
"firestore": {
10+
"port": 8080
11+
},
12+
"database": {
13+
"port": 8081
14+
},
15+
"storage": {
16+
"port": 9199
17+
},
18+
"ui": {
19+
"enabled": true
20+
},
21+
"singleProjectMode": true
22+
}
23+
}

firestore.rules

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
rules_version = '2';
2+
service cloud.firestore {
3+
match /databases/{database}/documents {
4+
match /__tests/{document=**} {
5+
allow read, write;
6+
}
7+
match /{document=**} {
8+
allow read, write: if false;
9+
}
10+
}
11+
}

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
"lint:fix": "pnpm run lint --write",
3838
"test:types": "tsc --build tsconfig.json",
3939
"test:unit": "vitest --coverage",
40+
"firebase:emulators": "firebase emulators:start --only firestore",
41+
"test:dev": "vitest",
4042
"test": "pnpm run lint && pnpm run test:unit run && pnpm run build"
4143
},
4244
"keywords": [
@@ -68,12 +70,14 @@
6870
"devDependencies": {
6971
"@vitest/coverage-c8": "^0.24.1",
7072
"@vue/runtime-core": "^3.2.40",
73+
"@vue/test-utils": "^2.1.0",
7174
"chalk": "^5.1.2",
7275
"conventional-changelog-cli": "^2.0.34",
7376
"enquirer": "^2.3.6",
7477
"execa": "^6.1.0",
7578
"firebase": "^9.12.1",
7679
"focus-visible": "^5.2.0",
80+
"happy-dom": "^7.5.10",
7781
"lint-staged": "^13.0.3",
7882
"minimist": "^1.2.7",
7983
"p-series": "^3.0.0",

playground/firestore.rules

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
rules_version = '2';
12
service cloud.firestore {
23
match /databases/{database}/documents {
34
match /todos/{todoId} {
@@ -38,4 +39,4 @@ service cloud.firestore {
3839
allow write: if false;
3940
}
4041
}
41-
}
42+
}

playground/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"vuefire": "workspace:*"
1818
},
1919
"devDependencies": {
20+
"@firebase/app-types": "^0.8.0",
2021
"@types/node": "^16.11.65",
2122
"@vitejs/plugin-vue": "^3.0.3",
2223
"@vue/tsconfig": "^0.1.3",

playground/src/pages/config.vue

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<script setup lang="ts">
2-
import { doc } from 'firebase/firestore';
2+
import { doc } from 'firebase/firestore'
33
import { ref } from 'vue'
4-
import { firestoreBind } from 'vuefire';
5-
import { useFirestore } from '@/firebase;
4+
import { firestoreBind } from 'vuefire'
5+
import { useFirestore } from '@/firebase'
66
7-
8-
const db = useFirestore();
7+
const db = useFirestore()
98
const configRef = doc(db, 'configs', 'jORwjIykFo2NmkdzTkhU')
9+
const itemRef = doc(db, 'tests', 'item')
1010
11-
const config = ref(null)
12-
firestoreBind(config, configRef)
11+
const config = ref()
12+
firestoreBind(config, itemRef)
13+
// firestoreBind(config, configRef)
1314
</script>
1415

1516
<template>

playground/src/pages/index.vue

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
<script lang="ts" setup>
2-
import { computed } from 'vue';
3-
import { useRouter } from 'vue-router/auto';
2+
import { computed } from 'vue'
3+
import { useRouter } from 'vue-router/auto'
44
55
const router = useRouter()
6-
const routes = computed(() => router.getRoutes().filter(route => !route.path.includes(':') && !route.children.length))
6+
const routes = computed(() =>
7+
router
8+
.getRoutes()
9+
.filter(route => !route.path.includes(':') && !route.children.length)
10+
)
711
</script>
812

913
<template>
1014
<ul>
1115
<li v-for="route in routes">
12-
<RouterLink :to="{ name: route.name }" v-slot="{ href }">{{ href }}</RouterLink>
16+
<RouterLink :to="{ name: route.name }" v-slot="{ href }">{{
17+
href
18+
}}</RouterLink>
1319
</li>
1420
</ul>
1521
</template>

playground/src/pages/nested-collections.vue

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<script setup lang="ts">
2-
import { collection } from 'firebase/firestore';
2+
import { collection } from 'firebase/firestore'
33
import { ref } from 'vue'
4-
import { firestoreBind } from 'vuefire';
5-
import { useFirestore } from '@/firebase;
4+
import { firestoreBind } from 'vuefire'
5+
import { useFirestore } from '@/firebase'
66
7-
const db = useFirestore();
7+
const db = useFirestore()
88
const tweetsRef = collection(db, 'tweets')
99
const nestedRef = collection(db, 'nested')
1010
const momentsRef = collection(db, 'moments')

0 commit comments

Comments
 (0)