Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! Initial test suites and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jits committed Feb 12, 2024
1 parent d9cc44d commit 1361dad
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
12 changes: 4 additions & 8 deletions firebase/test/firestore/firestore-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,18 @@ import { deleteDoc, doc, getDoc, setDoc, setLogLevel } from 'firebase/firestore'
import { createWriteStream, readFileSync } from 'node:fs';
import { get as httpGet } from 'node:http';
import { afterAll, beforeAll, beforeEach, describe, test } from 'vitest';
import { TEST_PROJECT_ID } from '../helpers/constants';
import { getFirestoreMeta } from '../helpers/firestore';

if (!process.env.GCLOUD_PROJECT) {
throw new Error('Missing GCLOUD_PROJECT env var');
}
const PROJECT_ID = process.env.GCLOUD_PROJECT;

let testEnv: RulesTestEnvironment;

beforeAll(async () => {
// Silence expected rules rejections from Firestore SDK. Unexpected rejections
// will still bubble up and will be thrown as an error (failing the tests as needed).
setLogLevel('error');
const { host, port } = getFirestoreMeta(PROJECT_ID);
const { host, port } = getFirestoreMeta(TEST_PROJECT_ID);
testEnv = await initializeTestEnvironment({
projectId: PROJECT_ID,
projectId: TEST_PROJECT_ID,
firestore: {
host,
port,
Expand All @@ -35,7 +31,7 @@ afterAll(async () => {
await testEnv.cleanup();

// Write the coverage report to a file
const { coverageUrl } = getFirestoreMeta(PROJECT_ID);
const { coverageUrl } = getFirestoreMeta(TEST_PROJECT_ID);
const coverageFile = './firestore-coverage.html';
const fstream = createWriteStream(coverageFile);
await new Promise((resolve, reject) => {
Expand Down
4 changes: 4 additions & 0 deletions firebase/test/helpers/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if (!process.env.GCLOUD_PROJECT) {
throw new Error('Missing GCLOUD_PROJECT env var');
}
export const TEST_PROJECT_ID = process.env.GCLOUD_PROJECT;
8 changes: 2 additions & 6 deletions firebase/test/rtdb/rtdb-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ import { get, ref, remove, set } from 'firebase/database';
import { createWriteStream, readFileSync } from 'node:fs';
import { get as httpGet } from 'node:http';
import { afterAll, beforeAll, beforeEach, describe, test } from 'vitest';
import { TEST_PROJECT_ID } from '../helpers/constants';
import { getRtdbMeta } from '../helpers/rtdb';

if (!process.env.GCLOUD_PROJECT) {
throw new Error('Missing GCLOUD_PROJECT env var');
}
const PROJECT_ID = process.env.GCLOUD_PROJECT;

const DATABASE_NAME = 'demo-test-rtdb';

let testEnv: RulesTestEnvironment;

beforeAll(async () => {
const { host, port } = getRtdbMeta(DATABASE_NAME);
testEnv = await initializeTestEnvironment({
projectId: PROJECT_ID,
projectId: TEST_PROJECT_ID,
database: {
port,
host,
Expand Down
8 changes: 2 additions & 6 deletions firebase/test/storage/storage-rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ import {
import { deleteObject, getDownloadURL, ref, updateMetadata } from 'firebase/storage';
import { readFileSync } from 'node:fs';
import { afterAll, beforeAll, beforeEach, describe, test } from 'vitest';
import { TEST_PROJECT_ID } from '../helpers/constants';
import { getStorageMeta } from '../helpers/storage';

if (!process.env.GCLOUD_PROJECT) {
throw new Error('Missing GCLOUD_PROJECT env var');
}
const PROJECT_ID = process.env.GCLOUD_PROJECT;

let testEnv: RulesTestEnvironment;

beforeAll(async () => {
const { host, port } = getStorageMeta();
testEnv = await initializeTestEnvironment({
projectId: PROJECT_ID,
projectId: TEST_PROJECT_ID,
storage: {
port,
host,
Expand Down

0 comments on commit 1361dad

Please sign in to comment.