Skip to content

Commit

Permalink
Add Browser tests for Lite and Exp (#3448)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian committed Jul 23, 2020
1 parent e50be1c commit 18e5dea
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 60 deletions.
24 changes: 1 addition & 23 deletions packages/firestore/exp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
* limitations under the License.
*/

import { version } from '../package.json';
import { _registerComponent, registerVersion } from '@firebase/app-exp';
import { Component, ComponentType } from '@firebase/component';
import { Firestore } from './src/api/database';
import './register';

export { FieldPath, documentId } from '../lite/src/api/field_path';

Expand Down Expand Up @@ -103,22 +100,3 @@ export { GeoPoint } from '../src/api/geo_point';
export { Timestamp } from '../src/api/timestamp';

export { refEqual, queryEqual } from '../lite/src/api/reference';

export function registerFirestore(): void {
_registerComponent(
new Component(
'firestore-exp',
container => {
const app = container.getProvider('app-exp').getImmediate()!;
return ((app, auth) => new Firestore(app, auth))(
app,
container.getProvider('auth-internal')
);
},
ComponentType.PUBLIC
)
);
registerVersion('firestore-exp', version, 'node');
}

registerFirestore();
41 changes: 41 additions & 0 deletions packages/firestore/exp/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @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 { _registerComponent, registerVersion } from '@firebase/app-exp';
import { Component, ComponentType } from '@firebase/component';

import { Firestore } from './src/api/database';
import { version } from '../package.json';

export function registerFirestore(): void {
_registerComponent(
new Component(
'firestore-exp',
container => {
const app = container.getProvider('app-exp').getImmediate()!;
return ((app, auth) => new Firestore(app, auth))(
app,
container.getProvider('auth-internal')
);
},
ComponentType.PUBLIC
)
);
registerVersion('firestore-exp', version, 'node');
}

registerFirestore();
35 changes: 35 additions & 0 deletions packages/firestore/exp/test/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @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 '../register';

/**
* This will include all of the test files and compile them as needed
*
* Taken from karma-webpack source:
* https://github.com/webpack-contrib/karma-webpack#alternative-usage
*/

// 'context()' definition requires additional dependency on webpack-env package.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const testsContext = (require as any).context(
'../../test/integration/api',
true,
/^.*\.test\.ts$/
);
const browserTests = testsContext.keys();
browserTests.forEach(testsContext);
21 changes: 18 additions & 3 deletions packages/firestore/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ module.exports = function (config) {
// files to load into karma
files: getTestFiles(argv),

preprocessors: {
'exp/test/**/*.ts': ['webpack', 'sourcemap'],
'lite/test/**/*.ts': ['webpack', 'sourcemap'],
'test/**/*.ts': ['webpack', 'sourcemap']
},

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha'],
Expand All @@ -41,13 +47,22 @@ module.exports = function (config) {
*/
function getTestFiles(argv) {
const unitTests = 'test/unit/bootstrap.ts';
const integrationTests = 'test/integration/bootstrap.ts';
const legcayIntegrationTests = 'test/integration/bootstrap.ts';
const liteIntegrationTests = 'lite/test/bootstrap.ts';
const expIntegrationTests = 'exp/test/bootstrap.ts';
if (argv.unit) {
return [unitTests];
} else if (argv.integration) {
return [integrationTests];
return [legcayIntegrationTests];
} else if (argv.lite) {
return [liteIntegrationTests];
} else if (argv.exp) {
return [expIntegrationTests];
} else {
return [unitTests, integrationTests];
// Note that we cannot include both the firestore-exp and the legacy SDK
// as the test runners modify the global namespace cannot be both included
// in the same bundle.
return [unitTests, legcayIntegrationTests];
}
}

Expand Down
24 changes: 1 addition & 23 deletions packages/firestore/lite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
* limitations under the License.
*/

import { registerVersion, _registerComponent } from '@firebase/app-exp';
import { Firestore } from './src/api/database';
import { version } from '../package.json';
import { Component, ComponentType } from '@firebase/component';
import './register';

export {
Firestore as FirebaseFirestore,
Expand Down Expand Up @@ -86,22 +83,3 @@ export { Blob } from '../src/api/blob';
export { GeoPoint } from '../src/api/geo_point';

export { Timestamp } from '../src/api/timestamp';

export function registerFirestore(): void {
_registerComponent(
new Component(
'firestore/lite',
container => {
const app = container.getProvider('app-exp').getImmediate()!;
return ((app, auth) => new Firestore(app, auth))(
app,
container.getProvider('auth-internal')
);
},
ComponentType.PUBLIC
)
);
registerVersion('firestore-lite', version, 'node');
}

registerFirestore();
41 changes: 41 additions & 0 deletions packages/firestore/lite/register.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* @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 { _registerComponent, registerVersion } from '@firebase/app-exp';
import { Component, ComponentType } from '@firebase/component';

import { Firestore } from './src/api/database';
import { version } from '../package.json';

export function registerFirestore(): void {
_registerComponent(
new Component(
'firestore/lite',
container => {
const app = container.getProvider('app-exp').getImmediate()!;
return ((app, auth) => new Firestore(app, auth))(
app,
container.getProvider('auth-internal')
);
},
ComponentType.PUBLIC
)
);
registerVersion('firestore-lite', version, 'node');
}

registerFirestore();
6 changes: 5 additions & 1 deletion packages/firestore/lite/src/api/reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,11 @@ export function parent<T>(
if (parentPath.isEmpty()) {
return null;
} else {
return new DocumentReference(child.firestore, /* converter= */ null, parentPath);
return new DocumentReference(
child.firestore,
/* converter= */ null,
parentPath
);
}
} else {
const doc = cast<DocumentReference<T>>(child, DocumentReference);
Expand Down
31 changes: 31 additions & 0 deletions packages/firestore/lite/test/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @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 '../register';

/**
* This will include all of the test files and compile them as needed
*
* Taken from karma-webpack source:
* https://github.com/webpack-contrib/karma-webpack#alternative-usage
*/

// 'context()' definition requires additional dependency on webpack-env package.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const testsContext = (require as any).context('.', true, /^.*\.test.*$/);
const browserTests = testsContext.keys();
browserTests.forEach(testsContext);
8 changes: 6 additions & 2 deletions packages/firestore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@
"gendeps:exp": "../../scripts/exp/extract-deps.sh --types ./exp-types/index.d.ts --bundle ./dist/exp/tmp.js --output ./exp/dependencies.json",
"pregendeps:lite" : "node scripts/build-bundle.js --input ./lite/index.ts --output ./dist/lite/tmp.js",
"gendeps:lite": "../../scripts/exp/extract-deps.sh --types ./lite-types/index.d.ts --bundle ./dist/lite/tmp.js --output ./lite/dependencies.json",
"test:lite": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'lite/test/**/*.test.ts' --require ts-node/register --file lite/index.ts --config ../../config/mocharc.node.js",
"test:lite:browser": "karma start --single-run --lite",
"test:lite:browser:debug": "karma start --single-run --lite --auto-watch",
"test:exp": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/integration/api/*.test.ts' --file exp/index.ts --config ../../config/mocharc.node.js",
"test:exp:persistence": "USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/integration/api/*.test.ts' --require ts-node/register --require exp/index.ts --require test/util/node_persistence.ts --config ../../config/mocharc.node.js",
"test:exp:browser": "karma start --single-run --exp",
"test:exp:browser:debug": "karma start --single-run --exp --auto-watch",
"test": "run-s lint test:all",
"test:ci": "node ../../scripts/run_tests_in_ci.js",
"test:all": "run-p test:browser test:travis test:minified test:exp test:lite",
"test:all": "run-p test:browser test:lite:browser test:exp:browser test:travis test:minified test:exp test:lite",
"test:browser": "karma start --single-run",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"test:node": "FIRESTORE_EMULATOR_PORT=8080 FIRESTORE_EMULATOR_PROJECT_ID=test-emulator TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --file index.node.ts --config ../../config/mocharc.node.js",
Expand All @@ -36,7 +41,6 @@
"test:node:persistence:prod": "USE_MOCK_PERSISTENCE=YES TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'test/{,!(browser)/**/}*.test.ts' --require ts-node/register --require index.node.ts --require test/util/node_persistence.ts --config ../../config/mocharc.node.js",
"test:travis": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts",
"test:minified": "(cd ../../integration/firestore ; yarn test)",
"test:lite": "TS_NODE_CACHE=NO TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' nyc --reporter lcovonly -- mocha 'lite/test/**/*.test.ts' --require ts-node/register --file lite/index.ts --config ../../config/mocharc.node.js",
"prepare": "yarn build:release"
},
"main": "dist/index.node.cjs.js",
Expand Down
12 changes: 4 additions & 8 deletions packages/firestore/scripts/build-bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ const typescriptPlugin = require('rollup-plugin-typescript2');
const alias = require('@rollup/plugin-alias');
const json = require('rollup-plugin-json');

import {
removeAssertTransformer,
resolveNodeExterns,
generateAliasConfig
} from '../rollup.shared';
const util = require('../rollup.shared');

const argv = yargs.options({
input: {
Expand All @@ -52,18 +48,18 @@ async function buildBundle(input: string, output: string): Promise<void> {
const bundle = await rollup({
input,
plugins: [
alias(generateAliasConfig('node')),
alias(util.generateAliasConfig('node')),
typescriptPlugin({
tsconfigOverride: {
compilerOptions: {
target: 'es2017'
}
},
transformers: removeAssertTransformer
transformers: util.removeAssertTransformer
}),
json({ preferConst: true })
],
external: resolveNodeExterns
external: util.resolveNodeExterns
});
await bundle.write({ file: output, format: 'es' });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const RPC_URL_VERSION = 'v1';
const RPC_NAME_REST_MAPPING: { [key: string]: string } = {};
RPC_NAME_REST_MAPPING['BatchGetDocuments'] = 'batchGet';
RPC_NAME_REST_MAPPING['Commit'] = 'commit';
RPC_NAME_REST_MAPPING['RunQuery'] = 'runQuery';

// TODO(b/38203344): The SDK_VERSION is set independently from Firebase because
// we are doing out-of-band releases. Once we release as part of Firebase, we
Expand Down

0 comments on commit 18e5dea

Please sign in to comment.