Skip to content

Commit 4cc627a

Browse files
Share Integration Tests between firestore-exp and the main SDK
1 parent ddddda8 commit 4cc627a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1058
-923
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import * as firebase from 'firebase';
19+
20+
// This file replaces "packages/firestore/test/integration/util/firebase_export"
21+
// and depends on the minified sources.
22+
23+
let appCount = 0;
24+
25+
export function newTestFirestore(
26+
projectId: string,
27+
nameOrApp?: string | firebase.app.App,
28+
settings?: firebase.firestore.Settings
29+
): firebase.firestore.Firestore {
30+
if (nameOrApp === undefined) {
31+
nameOrApp = 'test-app-' + appCount++;
32+
}
33+
const app =
34+
typeof nameOrApp === 'string'
35+
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
36+
: nameOrApp;
37+
38+
const firestore = firebase.firestore(app);
39+
if (settings) {
40+
firestore.settings(settings);
41+
}
42+
return firestore;
43+
}
44+
45+
export function usesModularApi(): false {
46+
return false;
47+
}
48+
49+
const Firestore = firebase.firestore.Firestore;
50+
const FieldPath = firebase.firestore.FieldPath;
51+
const Timestamp = firebase.firestore.Timestamp;
52+
const GeoPoint = firebase.firestore.GeoPoint;
53+
const FieldValue = firebase.firestore.FieldValue;
54+
const Blob = firebase.firestore.Blob;
55+
56+
export { Firestore, FieldValue, FieldPath, Timestamp, Blob, GeoPoint };

integration/firestore/gulpfile.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function copyTests() {
4848
return gulp
4949
.src(
5050
[
51+
'firebase_export.ts',
5152
testBase + '/integration/api/*.ts',
5253
testBase + '/integration/util/events_accumulator.ts',
5354
testBase + '/integration/util/helpers.ts',
@@ -63,21 +64,29 @@ function copyTests() {
6364
* This regex is designed to match the following statement used in our
6465
* firestore integration test suites:
6566
*
66-
* import firebase from '../../util/firebase_export';
67+
* import * as firebaseExport from '../../util/firebase_export';
6768
*
6869
* It will handle variations in whitespace, single/double quote
6970
* differences, as well as different paths to a valid firebase_export
7071
*/
71-
/import\s+firebase\s+from\s+('|")[^\1]+firebase_export\1;?/,
72-
`import firebase from '${firebaseAppSdk}';
73-
import '${firebaseFirestoreSdk}';
74-
72+
/import\s+\* as firebaseExport\s+from\s+('|")[^\1]+firebase_export\1;?/,
73+
`import * as firebaseExport from '${resolve(
74+
__dirname,
75+
'./firebase_export'
76+
)}';
77+
7578
if (typeof process === 'undefined') {
7679
process = { env: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
7780
} else {
7881
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
79-
}
80-
`
82+
}`
83+
)
84+
)
85+
.pipe(
86+
replace(
87+
'import * as firebase from "firebase";',
88+
`import firebase from '${firebaseAppSdk}';
89+
import '${firebaseFirestoreSdk}';`
8190
)
8291
)
8392
.pipe(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import firebase from 'firebase/app/dist/index.esm.js';
2+
import '/Users/mrschmidt/GitHub/firebase/firebase-js-sdk/packages/firestore/dist/index.memory.esm.js';
3+
import * as exp from "../../packages/firestore/exp/test/shim";
4+
5+
let appCount = 0;
6+
7+
export function newTestFirestore(
8+
projectId: string,
9+
nameOrApp?: string | firebase.app.App,
10+
settings?: firebase.firestore.Settings
11+
): firebase.firestore.Firestore {
12+
if (nameOrApp === undefined) {
13+
nameOrApp = 'test-app-' + appCount++;
14+
}
15+
const app =
16+
typeof nameOrApp === 'string'
17+
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
18+
: nameOrApp;
19+
20+
const firestore = firebase.firestore(app);
21+
if (settings) {
22+
firestore.settings(settings);
23+
}
24+
return firestore;
25+
}
26+
27+
export function usesModularApi() : false {
28+
return false;
29+
}
30+
31+
const Firestore = firebase.firestore.Firestore;
32+
const FieldPath = firebase.firestore.FieldPath;
33+
const Timestamp = firebase.firestore.Timestamp;
34+
const GeoPoint = firebase.firestore.GeoPoint;
35+
const FieldValue = firebase.firestore.FieldValue;
36+
const Blob = firebase.firestore.Blob;
37+
38+
export {
39+
Firestore,
40+
FieldValue,
41+
FieldPath,
42+
Timestamp,
43+
Blob,
44+
GeoPoint
45+
};
46+

packages/firestore/.idea/runConfigurations/firestore_exp_Tests__Emulator__.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/firestore/.idea/runConfigurations/firestore_exp_Tests__Emulator_w__Mock_Persistence_.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/firestore/exp/src/api/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ export function disableNetwork(
289289
export function terminate(
290290
firestore: firestore.FirebaseFirestore
291291
): Promise<void> {
292-
_removeServiceInstance(firestore.app, 'firestore/lite');
292+
_removeServiceInstance(firestore.app, 'firestore-exp');
293293
const firestoreImpl = cast(firestore, Firestore);
294294
return firestoreImpl._terminate();
295295
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import '../../test/integration/api/array_transforms.test';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import '../../test/integration/api/batch_writes.test';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import '../../test/integration/api/cursor.test';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright 2020 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import '../../test/integration/api/database.test';

0 commit comments

Comments
 (0)