Skip to content

Commit 3105541

Browse files
Port Compat tests to v9 API (#5844)
1 parent 3c20727 commit 3105541

Some content is hidden

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

48 files changed

+2831
-2949
lines changed

integration/firestore/firebase_export.ts

+12-35
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
* limitations under the License.
1616
*/
1717

18-
import firebase from '@firebase/app-compat';
19-
import '@firebase/firestore-compat';
20-
import { FirebaseApp } from '@firebase/app-types';
21-
import { Settings, FirebaseFirestore } from '@firebase/firestore-types';
18+
import { FirebaseApp, initializeApp } from '@firebase/app';
19+
import {
20+
Firestore,
21+
FirestoreSettings,
22+
initializeFirestore
23+
} from '@firebase/firestore';
2224

2325
// This file replaces "packages/firestore/test/integration/util/firebase_export"
2426
// and depends on the minified sources.
@@ -28,43 +30,18 @@ let appCount = 0;
2830
export function newTestFirestore(
2931
projectId: string,
3032
nameOrApp?: string | FirebaseApp,
31-
settings?: Settings
32-
): FirebaseFirestore {
33+
settings?: FirestoreSettings
34+
): Firestore {
3335
if (nameOrApp === undefined) {
3436
nameOrApp = 'test-app-' + appCount++;
3537
}
3638
const app =
3739
typeof nameOrApp === 'string'
38-
? firebase.initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
40+
? initializeApp({ apiKey: 'fake-api-key', projectId }, nameOrApp)
3941
: nameOrApp;
40-
41-
const firestore = firebase.firestore(app);
42-
if (settings) {
43-
firestore.settings(settings);
44-
}
45-
return firestore;
42+
return initializeFirestore(app, settings || {});
4643
}
4744

48-
export function usesFunctionalApi(): false {
49-
return false;
50-
}
51-
52-
const Blob = firebase.firestore.Blob;
53-
const DocumentReference = firebase.firestore.DocumentReference;
54-
const FieldPath = firebase.firestore.FieldPath;
55-
const FieldValue = firebase.firestore.FieldValue;
56-
const Firestore = firebase.firestore.Firestore;
57-
const GeoPoint = firebase.firestore.GeoPoint;
58-
const QueryDocumentSnapshot = firebase.firestore.QueryDocumentSnapshot;
59-
const Timestamp = firebase.firestore.Timestamp;
45+
export * from '@firebase/firestore';
6046

61-
export {
62-
Blob,
63-
DocumentReference,
64-
FieldPath,
65-
FieldValue,
66-
Firestore,
67-
GeoPoint,
68-
QueryDocumentSnapshot,
69-
Timestamp
70-
};
47+
export type PrivateSettings = Record<string, any>;

integration/firestore/gulpfile.js

+10-17
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,18 @@ function copyTests() {
5353
.pipe(
5454
replace(
5555
/**
56-
* This regex is designed to match the following statement used in our
57-
* firestore integration test suites:
58-
*
59-
* import * as firebaseExport from '../../util/firebase_export';
60-
*
61-
* It will handle variations in whitespace, single/double quote
62-
* differences, as well as different paths to a valid firebase_export
56+
* This regex is designed to match the Firebase import in our
57+
* integration tests.
6358
*/
64-
/import\s+\* as firebaseExport\s+from\s+('|")[^\1]+firebase_export\1;?/,
65-
`import * as firebaseExport from '${resolve(
66-
__dirname,
67-
'./firebase_export'
68-
)}';
59+
/\s+from '\.(\.\/util)?\/firebase_export';/,
60+
` from '${resolve(__dirname, './firebase_export')}';
6961
70-
if (typeof process === 'undefined') {
71-
process = { env: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
72-
} else {
73-
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
74-
}`
62+
if (typeof process === 'undefined') {
63+
process = { env: { INCLUDE_FIRESTORE_PERSISTENCE: '${isPersistenceEnabled()}' } } as any;
64+
} else {
65+
process.env.INCLUDE_FIRESTORE_PERSISTENCE = '${isPersistenceEnabled()}';
66+
}
67+
`
7568
)
7669
)
7770
.pipe(

integration/firestore/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66
"build:deps": "lerna run --scope @firebase/'{app,firestore}' --include-dependencies build",
77
"build:persistence": "INCLUDE_FIRESTORE_PERSISTENCE=true gulp compile-tests",
88
"build:memory": "INCLUDE_FIRESTORE_PERSISTENCE=false gulp compile-tests",
9+
"prettier": "prettier --write '*.js' '*.ts'",
910
"test": "yarn build:memory; karma start --single-run; yarn build:persistence; karma start --single-run;",
1011
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test",
1112
"test:persistence": " yarn build:persistence; karma start --single-run",
1213
"test:persistence:debug": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
1314
"test:memory": "yarn build:memory; karma start --single-run",
1415
"test:memory:debug": "yarn build:memory; karma start --auto-watch --browsers Chrome"
1516
},
16-
"devDependencies": {
17+
"dependencies": {
1718
"@firebase/app": "0.7.12",
18-
"@firebase/firestore-compat": "0.1.11",
19+
"@firebase/firestore": "3.4.2"
20+
},
21+
"devDependencies": {
1922
"@types/mocha": "9.0.0",
2023
"gulp": "4.0.2",
2124
"gulp-filter": "7.0.0",

packages/firestore-compat/test/validation.test.ts

+17-17
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,12 @@ apiDescribe('Validation:', (persistence: boolean) => {
813813
);
814814
expect(() => query.startAt('foo/bar')).to.throw(
815815
'Invalid query. When querying a collection and ordering by ' +
816-
'FieldPath.documentId(), the value passed to Query.startAt() ' +
816+
'documentId(), the value passed to Query.startAt() ' +
817817
"must be a plain document ID, but 'foo/bar' contains a slash."
818818
);
819819
expect(() => cgQuery.startAt('foo')).to.throw(
820820
'Invalid query. When querying a collection group and ordering by ' +
821-
'FieldPath.documentId(), the value passed to Query.startAt() ' +
821+
'documentId(), the value passed to Query.startAt() ' +
822822
"must result in a valid document path, but 'foo' is not because " +
823823
'it contains an odd number of segments.'
824824
);
@@ -1208,42 +1208,42 @@ apiDescribe('Validation:', (persistence: boolean) => {
12081208
expect(() =>
12091209
collection.where(FieldPath.documentId(), '>=', '')
12101210
).to.throw(
1211-
'Invalid query. When querying with FieldPath.documentId(), you ' +
1211+
'Invalid query. When querying with documentId(), you ' +
12121212
'must provide a valid document ID, but it was an empty string.'
12131213
);
12141214
expect(() =>
12151215
collection.where(FieldPath.documentId(), '>=', 'foo/bar/baz')
12161216
).to.throw(
1217-
`Invalid query. When querying a collection by ` +
1218-
`FieldPath.documentId(), you must provide a plain document ID, but ` +
1217+
`Invalid query. When querying a collection by documentId(), ` +
1218+
`you must provide a plain document ID, but ` +
12191219
`'foo/bar/baz' contains a '/' character.`
12201220
);
12211221
expect(() =>
12221222
collection.where(FieldPath.documentId(), '>=', 1)
12231223
).to.throw(
1224-
'Invalid query. When querying with FieldPath.documentId(), you must ' +
1224+
'Invalid query. When querying with documentId(), you must ' +
12251225
'provide a valid string or a DocumentReference, but it was: 1.'
12261226
);
12271227
expect(() =>
12281228
db.collectionGroup('foo').where(FieldPath.documentId(), '>=', 'foo')
12291229
).to.throw(
1230-
`Invalid query. When querying a collection group by ` +
1231-
`FieldPath.documentId(), the value provided must result in a valid document path, ` +
1230+
`Invalid query. When querying a collection group by documentId(), ` +
1231+
`the value provided must result in a valid document path, ` +
12321232
`but 'foo' is not because it has an odd number of segments (1).`
12331233
);
12341234

12351235
expect(() =>
12361236
collection.where(FieldPath.documentId(), 'array-contains', 1)
12371237
).to.throw(
12381238
"Invalid Query. You can't perform 'array-contains' queries on " +
1239-
'FieldPath.documentId().'
1239+
'documentId().'
12401240
);
12411241

12421242
expect(() =>
12431243
collection.where(FieldPath.documentId(), 'array-contains-any', 1)
12441244
).to.throw(
12451245
"Invalid Query. You can't perform 'array-contains-any' queries on " +
1246-
'FieldPath.documentId().'
1246+
'documentId().'
12471247
);
12481248
}
12491249
);
@@ -1261,30 +1261,30 @@ apiDescribe('Validation:', (persistence: boolean) => {
12611261
expect(() =>
12621262
collection.where(FieldPath.documentId(), 'in', [''])
12631263
).to.throw(
1264-
'Invalid query. When querying with FieldPath.documentId(), you ' +
1264+
'Invalid query. When querying with documentId(), you ' +
12651265
'must provide a valid document ID, but it was an empty string.'
12661266
);
12671267

12681268
expect(() =>
12691269
collection.where(FieldPath.documentId(), 'in', ['foo/bar/baz'])
12701270
).to.throw(
1271-
`Invalid query. When querying a collection by ` +
1272-
`FieldPath.documentId(), you must provide a plain document ID, but ` +
1273-
`'foo/bar/baz' contains a '/' character.`
1271+
`Invalid query. When querying a collection by documentId(), you ` +
1272+
`must provide a plain document ID, but 'foo/bar/baz' contains a ` +
1273+
`'/' character.`
12741274
);
12751275

12761276
expect(() =>
12771277
collection.where(FieldPath.documentId(), 'in', [1, 2])
12781278
).to.throw(
1279-
'Invalid query. When querying with FieldPath.documentId(), you must ' +
1279+
'Invalid query. When querying with documentId(), you must ' +
12801280
'provide a valid string or a DocumentReference, but it was: 1.'
12811281
);
12821282

12831283
expect(() =>
12841284
db.collectionGroup('foo').where(FieldPath.documentId(), 'in', ['foo'])
12851285
).to.throw(
1286-
`Invalid query. When querying a collection group by ` +
1287-
`FieldPath.documentId(), the value provided must result in a valid document path, ` +
1286+
`Invalid query. When querying a collection group by documentId(), ` +
1287+
`the value provided must result in a valid document path, ` +
12881288
`but 'foo' is not because it has an odd number of segments (1).`
12891289
);
12901290
}

packages/firestore/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
99
"scripts": {
1010
"bundle": "rollup -c",
11-
"prebuild": "yarn test:prepare && tsc --emitDeclarationOnly --declaration -p tsconfig.json; yarn api-report",
11+
"prebuild": "tsc --emitDeclarationOnly --declaration -p tsconfig.json; yarn api-report",
1212
"build": "run-p build:lite build:main",
1313
"build:release": "yarn build && yarn typings:public",
1414
"build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'",
@@ -25,8 +25,6 @@
2525
"test:lite:prod": "node ./scripts/run-tests.js --platform node_lite --main=lite/index.ts 'test/lite/**/*.test.ts'",
2626
"test:lite:browser": "karma start --single-run --lite",
2727
"test:lite:browser:debug": "karma start --browsers=Chrome --lite --auto-watch",
28-
"pretest": "yarn test:prepare",
29-
"pretest:ci": "yarn pretest",
3028
"test": "run-s lint test:all",
3129
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all:ci",
3230
"test:all:ci": "run-p test:browser test:lite:browser test:travis",
@@ -44,7 +42,6 @@
4442
"api-report:api-json": "rm -rf temp && api-extractor run --local --verbose",
4543
"api-report": "run-s api-report:main api-report:lite && yarn api-report:api-json",
4644
"doc": "api-documenter markdown --input temp --output docs",
47-
"test:prepare": "node ./scripts/prepare-test.js",
4845
"typings:public": "node ../../scripts/build/use_typings.js ./dist/index.d.ts"
4946
},
5047
"exports": {

packages/firestore/scripts/prepare-test.js

-18
This file was deleted.

packages/firestore/scripts/prepare-test.ts

-84
This file was deleted.

0 commit comments

Comments
 (0)