Skip to content

Commit

Permalink
Port Compat tests to v9 API (#5844)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Jan 12, 2022
1 parent 3c20727 commit 3105541
Show file tree
Hide file tree
Showing 48 changed files with 2,831 additions and 2,949 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
7 changes: 5 additions & 2 deletions integration/firestore/package.json
Expand Up @@ -6,16 +6,19 @@
"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",
"test:persistence:debug": "yarn build:persistence; karma start --auto-watch --browsers Chrome",
"test:memory": "yarn build:memory; karma start --single-run",
"test:memory:debug": "yarn build:memory; karma start --auto-watch --browsers Chrome"
},
"devDependencies": {
"dependencies": {
"@firebase/app": "0.7.12",
"@firebase/firestore-compat": "0.1.11",
"@firebase/firestore": "3.4.2"
},
"devDependencies": {
"@types/mocha": "9.0.0",
"gulp": "4.0.2",
"gulp-filter": "7.0.0",
Expand Down
34 changes: 17 additions & 17 deletions packages/firestore-compat/test/validation.test.ts
Expand Up @@ -813,12 +813,12 @@ apiDescribe('Validation:', (persistence: boolean) => {
);
expect(() => query.startAt('foo/bar')).to.throw(
'Invalid query. When querying a collection and ordering by ' +
'FieldPath.documentId(), the value passed to Query.startAt() ' +
'documentId(), the value passed to Query.startAt() ' +
"must be a plain document ID, but 'foo/bar' contains a slash."
);
expect(() => cgQuery.startAt('foo')).to.throw(
'Invalid query. When querying a collection group and ordering by ' +
'FieldPath.documentId(), the value passed to Query.startAt() ' +
'documentId(), the value passed to Query.startAt() ' +
"must result in a valid document path, but 'foo' is not because " +
'it contains an odd number of segments.'
);
Expand Down Expand Up @@ -1208,42 +1208,42 @@ apiDescribe('Validation:', (persistence: boolean) => {
expect(() =>
collection.where(FieldPath.documentId(), '>=', '')
).to.throw(
'Invalid query. When querying with FieldPath.documentId(), you ' +
'Invalid query. When querying with documentId(), you ' +
'must provide a valid document ID, but it was an empty string.'
);
expect(() =>
collection.where(FieldPath.documentId(), '>=', 'foo/bar/baz')
).to.throw(
`Invalid query. When querying a collection by ` +
`FieldPath.documentId(), you must provide a plain document ID, but ` +
`Invalid query. When querying a collection by documentId(), ` +
`you must provide a plain document ID, but ` +
`'foo/bar/baz' contains a '/' character.`
);
expect(() =>
collection.where(FieldPath.documentId(), '>=', 1)
).to.throw(
'Invalid query. When querying with FieldPath.documentId(), you must ' +
'Invalid query. When querying with documentId(), you must ' +
'provide a valid string or a DocumentReference, but it was: 1.'
);
expect(() =>
db.collectionGroup('foo').where(FieldPath.documentId(), '>=', 'foo')
).to.throw(
`Invalid query. When querying a collection group by ` +
`FieldPath.documentId(), the value provided must result in a valid document path, ` +
`Invalid query. When querying a collection group by documentId(), ` +
`the value provided must result in a valid document path, ` +
`but 'foo' is not because it has an odd number of segments (1).`
);

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

expect(() =>
collection.where(FieldPath.documentId(), 'array-contains-any', 1)
).to.throw(
"Invalid Query. You can't perform 'array-contains-any' queries on " +
'FieldPath.documentId().'
'documentId().'
);
}
);
Expand All @@ -1261,30 +1261,30 @@ apiDescribe('Validation:', (persistence: boolean) => {
expect(() =>
collection.where(FieldPath.documentId(), 'in', [''])
).to.throw(
'Invalid query. When querying with FieldPath.documentId(), you ' +
'Invalid query. When querying with documentId(), you ' +
'must provide a valid document ID, but it was an empty string.'
);

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

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

expect(() =>
db.collectionGroup('foo').where(FieldPath.documentId(), 'in', ['foo'])
).to.throw(
`Invalid query. When querying a collection group by ` +
`FieldPath.documentId(), the value provided must result in a valid document path, ` +
`Invalid query. When querying a collection group by documentId(), ` +
`the value provided must result in a valid document path, ` +
`but 'foo' is not because it has an odd number of segments (1).`
);
}
Expand Down
5 changes: 1 addition & 4 deletions packages/firestore/package.json
Expand Up @@ -8,7 +8,7 @@
"author": "Firebase <firebase-support@google.com> (https://firebase.google.com/)",
"scripts": {
"bundle": "rollup -c",
"prebuild": "yarn test:prepare && tsc --emitDeclarationOnly --declaration -p tsconfig.json; yarn api-report",
"prebuild": "tsc --emitDeclarationOnly --declaration -p tsconfig.json; yarn api-report",
"build": "run-p build:lite build:main",
"build:release": "yarn build && yarn typings:public",
"build:scripts": "tsc -moduleResolution node --module commonjs scripts/*.ts && ls scripts/*.js | xargs -I % sh -c 'terser % -o %'",
Expand All @@ -25,8 +25,6 @@
"test:lite:prod": "node ./scripts/run-tests.js --platform node_lite --main=lite/index.ts 'test/lite/**/*.test.ts'",
"test:lite:browser": "karma start --single-run --lite",
"test:lite:browser:debug": "karma start --browsers=Chrome --lite --auto-watch",
"pretest": "yarn test:prepare",
"pretest:ci": "yarn pretest",
"test": "run-s lint test:all",
"test:ci": "node ../../scripts/run_tests_in_ci.js -s test:all:ci",
"test:all:ci": "run-p test:browser test:lite:browser test:travis",
Expand All @@ -44,7 +42,6 @@
"api-report:api-json": "rm -rf temp && api-extractor run --local --verbose",
"api-report": "run-s api-report:main api-report:lite && yarn api-report:api-json",
"doc": "api-documenter markdown --input temp --output docs",
"test:prepare": "node ./scripts/prepare-test.js",
"typings:public": "node ../../scripts/build/use_typings.js ./dist/index.d.ts"
},
"exports": {
Expand Down
18 changes: 0 additions & 18 deletions packages/firestore/scripts/prepare-test.js

This file was deleted.

84 changes: 0 additions & 84 deletions packages/firestore/scripts/prepare-test.ts

This file was deleted.

0 comments on commit 3105541

Please sign in to comment.