Skip to content

Share Integration Tests between firestore-exp and the main SDK #3374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/smooth-shirts-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
56 changes: 56 additions & 0 deletions integration/firestore/firebase_export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as firebase from 'firebase';

// This file replaces "packages/firestore/test/integration/util/firebase_export"
// and depends on the minified sources.

let appCount = 0;

export function newTestFirestore(
projectId: string,
nameOrApp?: string | firebase.app.App,
settings?: firebase.firestore.Settings
): firebase.firestore.Firestore {
if (nameOrApp === undefined) {
nameOrApp = 'test-app-' + appCount++;
}
const app =
typeof nameOrApp === 'string'
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
: nameOrApp;

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

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

const Firestore = firebase.firestore.Firestore;
const FieldPath = firebase.firestore.FieldPath;
const Timestamp = firebase.firestore.Timestamp;
const GeoPoint = firebase.firestore.GeoPoint;
const FieldValue = firebase.firestore.FieldValue;
const Blob = firebase.firestore.Blob;

export { Firestore, FieldValue, FieldPath, Timestamp, Blob, GeoPoint };
23 changes: 16 additions & 7 deletions integration/firestore/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function copyTests() {
return gulp
.src(
[
'firebase_export.ts',
testBase + '/integration/api/*.ts',
testBase + '/integration/util/events_accumulator.ts',
testBase + '/integration/util/helpers.ts',
Expand All @@ -63,21 +64,29 @@ function copyTests() {
* This regex is designed to match the following statement used in our
* firestore integration test suites:
*
* import firebase from '../../util/firebase_export';
* 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
*/
/import\s+firebase\s+from\s+('|")[^\1]+firebase_export\1;?/,
`import firebase from '${firebaseAppSdk}';
import '${firebaseFirestoreSdk}';
/import\s+\* as firebaseExport\s+from\s+('|")[^\1]+firebase_export\1;?/,
`import * as firebaseExport from '${resolve(
__dirname,
'./firebase_export'
)}';
if (typeof process === 'undefined') {
process = { env: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
} else {
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
}
`
}`
)
)
.pipe(
replace(
'import * as firebase from "firebase";',
`import firebase from '${firebaseAppSdk}';
import '${firebaseFirestoreSdk}';`
)
)
.pipe(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/firestore/exp/src/api/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export function disableNetwork(
export function terminate(
firestore: firestore.FirebaseFirestore
): Promise<void> {
_removeServiceInstance(firestore.app, 'firestore/lite');
_removeServiceInstance(firestore.app, 'firestore-exp');
const firestoreImpl = cast(firestore, Firestore);
return firestoreImpl._terminate();
}
4 changes: 3 additions & 1 deletion packages/firestore/exp/test/deps/verify_dependencies.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import * as dependencies from './dependencies.json';
import * as pkg from '../../package.json';
import { forEach } from '../../../src/util/obj';

describe('Dependencies', () => {
// TODO(firestoreexp): Enable once the dependencies are stable
// eslint-disable-next-line no-restricted-properties
describe.skip('Dependencies', () => {
forEach(dependencies, (api, { dependencies }) => {
it(api, () => {
return extractDependencies(api, resolve('exp', pkg.main)).then(
Expand Down
77 changes: 0 additions & 77 deletions packages/firestore/exp/test/helpers.ts

This file was deleted.

Loading