Skip to content

Commit

Permalink
Fix minified tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Jan 10, 2022
1 parent 44b61ee commit 0d0aba4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 63 deletions.
47 changes: 12 additions & 35 deletions integration/firestore/firebase_export.ts
Expand Up @@ -15,10 +15,12 @@
* limitations under the License.
*/

import firebase from '@firebase/app-compat';
import '@firebase/firestore-compat';
import { FirebaseApp } from '@firebase/app-types';
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
import { FirebaseApp, initializeApp } from '@firebase/app';
import {
Firestore,
FirestoreSettings,
initializeFirestore
} from '@firebase/firestore';

// This file replaces "packages/firestore/test/integration/util/firebase_export"
// and depends on the minified sources.
Expand All @@ -28,43 +30,18 @@ let appCount = 0;
export function newTestFirestore(
projectId: string,
nameOrApp?: string | FirebaseApp,
settings?: Settings
): FirebaseFirestore {
settings?: FirestoreSettings
): Firestore {
if (nameOrApp === undefined) {
nameOrApp = 'test-app-' + appCount++;
}
const app =
typeof nameOrApp === 'string'
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
? initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
: nameOrApp;

const firestore = firebase.firestore(app);
if (settings) {
firestore.settings(settings);
}
return firestore;
return initializeFirestore(app, settings || {});
}

export function usesFunctionalApi(): false {
return false;
}

const Blob = firebase.firestore.Blob;
const DocumentReference = firebase.firestore.DocumentReference;
const FieldPath = firebase.firestore.FieldPath;
const FieldValue = firebase.firestore.FieldValue;
const Firestore = firebase.firestore.Firestore;
const GeoPoint = firebase.firestore.GeoPoint;
const QueryDocumentSnapshot = firebase.firestore.QueryDocumentSnapshot;
const Timestamp = firebase.firestore.Timestamp;
export * from '@firebase/firestore';

export {
Blob,
DocumentReference,
FieldPath,
FieldValue,
Firestore,
GeoPoint,
QueryDocumentSnapshot,
Timestamp
};
export type PrivateSettings = Record<string, any>;
27 changes: 10 additions & 17 deletions integration/firestore/gulpfile.js
Expand Up @@ -53,25 +53,18 @@ function copyTests() {
.pipe(
replace(
/**
* This regex is designed to match the following statement used in our
* firestore integration test suites:
*
* import * as firebaseExport from '../../util/firebase_export';
*
* It will handle variations in whitespace, single/double quote
* differences, as well as different paths to a valid firebase_export
* This regex is designed to match the Firebase import in our
* integration tests.
*/
/import\s+\* as firebaseExport\s+from\s+('|")[^\1]+firebase_export\1;?/,
`import * as firebaseExport from '${resolve(
__dirname,
'./firebase_export'
)}';
/\s+from '\.(\.\/util)?\/firebase_export';/,
` from '${resolve(__dirname, './firebase_export')}';
if (typeof process === 'undefined') {
process = { env: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
} else {
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
}`
if (typeof process === 'undefined') {
process = { env: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
} else {
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
}
`
)
)
.pipe(
Expand Down
3 changes: 2 additions & 1 deletion integration/firestore/package.json
Expand Up @@ -6,6 +6,7 @@
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
"build:persistence": "INCLUDE_FIRESTORE_PERSISTENCE=true gulp compile-tests",
"build:memory": "INCLUDE_FIRESTORE_PERSISTENCE=false gulp compile-tests",
"prettier": "prettier --write '*.js' '*.ts'",
"test": "yarn build:memory; karma start --single-run; yarn build:persistence; karma start --single-run;",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
"test:persistence": " yarn build:persistence; karma start --single-run",
Expand All @@ -15,7 +16,7 @@
},
"devDependencies": {
"@firebase/app": "0.7.11",
"@firebase/firestore-compat": "0.1.10",
"@firebase/firestore": "3.4.1",
"@types/mocha": "9.0.0",
"gulp": "4.0.2",
"gulp-filter": "7.0.0",
Expand Down
Expand Up @@ -17,7 +17,7 @@

import { expect } from 'chai';

import { DocumentSnapshot, QuerySnapshot } from '../../../src';
import { DocumentSnapshot, QuerySnapshot } from './firebase_export';
import { Deferred } from '../../util/promise';

/**
Expand Down
Expand Up @@ -53,3 +53,4 @@ export function newTestFirestore(
}

export * from '../../../src';
export { PrivateSettings };
14 changes: 6 additions & 8 deletions packages/firestore/test/integration/util/helpers.ts
Expand Up @@ -17,7 +17,6 @@

import { isIndexedDBAvailable } from '@firebase/util';

import * as firebaseExport from './firebase_export';
import {
collection,
doc,
Expand All @@ -26,21 +25,20 @@ import {
terminate,
clearIndexedDbPersistence,
enableIndexedDbPersistence,
Settings,
CollectionReference,
DocumentData,
QuerySnapshot,
setDoc,
SnapshotListenOptions
PrivateSettings,
SnapshotListenOptions,
newTestFirestore
} from './firebase_export';
import {
ALT_PROJECT_ID,
DEFAULT_PROJECT_ID,
DEFAULT_SETTINGS
} from './settings';

const newTestFirestore = firebaseExport.newTestFirestore;

/* eslint-disable no-restricted-globals */

function isIeOrEdge(): boolean {
Expand Down Expand Up @@ -173,7 +171,7 @@ export function withTestDbs(
export async function withTestDbsSettings(
persistence: boolean,
projectId: string,
settings: Settings,
settings: PrivateSettings,
numDbs: number,
fn: (db: Firestore[]) => Promise<void>
): Promise<void> {
Expand Down Expand Up @@ -214,7 +212,7 @@ export function withTestDoc(

export function withTestDocAndSettings(
persistence: boolean,
settings: Settings,
settings: PrivateSettings,
fn: (doc: DocumentReference) => Promise<void>
): Promise<void> {
return withTestDbsSettings(
Expand Down Expand Up @@ -260,7 +258,7 @@ export function withTestCollection(
// return the same collection every time.
export function withTestCollectionSettings(
persistence: boolean,
settings: Settings,
settings: PrivateSettings,
docs: { [key: string]: DocumentData },
fn: (collection: CollectionReference, db: Firestore) => Promise<void>
): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/test/integration/util/settings.ts
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import { PrivateSettings } from '../../../src/lite-api/settings';
import { PrivateSettings } from './firebase_export';

/**
* NOTE: These helpers are used by api/ tests and therefore may not have any
Expand Down

0 comments on commit 0d0aba4

Please sign in to comment.