Skip to content

Commit 18e5dea

Browse files
Add Browser tests for Lite and Exp (#3448)
1 parent e50be1c commit 18e5dea

File tree

11 files changed

+184
-60
lines changed

11 files changed

+184
-60
lines changed

packages/firestore/exp/index.ts

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

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

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

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

105102
export { refEqual, queryEqual } from '../lite/src/api/reference';
106-
107-
export function registerFirestore(): void {
108-
_registerComponent(
109-
new Component(
110-
'firestore-exp',
111-
container => {
112-
const app = container.getProvider('app-exp').getImmediate()!;
113-
return ((app, auth) => new Firestore(app, auth))(
114-
app,
115-
container.getProvider('auth-internal')
116-
);
117-
},
118-
ComponentType.PUBLIC
119-
)
120-
);
121-
registerVersion('firestore-exp', version, 'node');
122-
}
123-
124-
registerFirestore();

packages/firestore/exp/register.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 { _registerComponent, registerVersion } from '@firebase/app-exp';
19+
import { Component, ComponentType } from '@firebase/component';
20+
21+
import { Firestore } from './src/api/database';
22+
import { version } from '../package.json';
23+
24+
export function registerFirestore(): void {
25+
_registerComponent(
26+
new Component(
27+
'firestore-exp',
28+
container => {
29+
const app = container.getProvider('app-exp').getImmediate()!;
30+
return ((app, auth) => new Firestore(app, auth))(
31+
app,
32+
container.getProvider('auth-internal')
33+
);
34+
},
35+
ComponentType.PUBLIC
36+
)
37+
);
38+
registerVersion('firestore-exp', version, 'node');
39+
}
40+
41+
registerFirestore();
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 '../register';
19+
20+
/**
21+
* This will include all of the test files and compile them as needed
22+
*
23+
* Taken from karma-webpack source:
24+
* https://github.com/webpack-contrib/karma-webpack#alternative-usage
25+
*/
26+
27+
// 'context()' definition requires additional dependency on webpack-env package.
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29+
const testsContext = (require as any).context(
30+
'../../test/integration/api',
31+
true,
32+
/^.*\.test\.ts$/
33+
);
34+
const browserTests = testsContext.keys();
35+
browserTests.forEach(testsContext);

packages/firestore/karma.conf.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ module.exports = function (config) {
2323
// files to load into karma
2424
files: getTestFiles(argv),
2525

26+
preprocessors: {
27+
'exp/test/**/*.ts': ['webpack', 'sourcemap'],
28+
'lite/test/**/*.ts': ['webpack', 'sourcemap'],
29+
'test/**/*.ts': ['webpack', 'sourcemap']
30+
},
31+
2632
// frameworks to use
2733
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
2834
frameworks: ['mocha'],
@@ -41,13 +47,22 @@ module.exports = function (config) {
4147
*/
4248
function getTestFiles(argv) {
4349
const unitTests = 'test/unit/bootstrap.ts';
44-
const integrationTests = 'test/integration/bootstrap.ts';
50+
const legcayIntegrationTests = 'test/integration/bootstrap.ts';
51+
const liteIntegrationTests = 'lite/test/bootstrap.ts';
52+
const expIntegrationTests = 'exp/test/bootstrap.ts';
4553
if (argv.unit) {
4654
return [unitTests];
4755
} else if (argv.integration) {
48-
return [integrationTests];
56+
return [legcayIntegrationTests];
57+
} else if (argv.lite) {
58+
return [liteIntegrationTests];
59+
} else if (argv.exp) {
60+
return [expIntegrationTests];
4961
} else {
50-
return [unitTests, integrationTests];
62+
// Note that we cannot include both the firestore-exp and the legacy SDK
63+
// as the test runners modify the global namespace cannot be both included
64+
// in the same bundle.
65+
return [unitTests, legcayIntegrationTests];
5166
}
5267
}
5368

packages/firestore/lite/index.ts

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

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

2320
export {
2421
Firestore as FirebaseFirestore,
@@ -86,22 +83,3 @@ export { Blob } from '../src/api/blob';
8683
export { GeoPoint } from '../src/api/geo_point';
8784

8885
export { Timestamp } from '../src/api/timestamp';
89-
90-
export function registerFirestore(): void {
91-
_registerComponent(
92-
new Component(
93-
'firestore/lite',
94-
container => {
95-
const app = container.getProvider('app-exp').getImmediate()!;
96-
return ((app, auth) => new Firestore(app, auth))(
97-
app,
98-
container.getProvider('auth-internal')
99-
);
100-
},
101-
ComponentType.PUBLIC
102-
)
103-
);
104-
registerVersion('firestore-lite', version, 'node');
105-
}
106-
107-
registerFirestore();

packages/firestore/lite/register.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 { _registerComponent, registerVersion } from '@firebase/app-exp';
19+
import { Component, ComponentType } from '@firebase/component';
20+
21+
import { Firestore } from './src/api/database';
22+
import { version } from '../package.json';
23+
24+
export function registerFirestore(): void {
25+
_registerComponent(
26+
new Component(
27+
'firestore/lite',
28+
container => {
29+
const app = container.getProvider('app-exp').getImmediate()!;
30+
return ((app, auth) => new Firestore(app, auth))(
31+
app,
32+
container.getProvider('auth-internal')
33+
);
34+
},
35+
ComponentType.PUBLIC
36+
)
37+
);
38+
registerVersion('firestore-lite', version, 'node');
39+
}
40+
41+
registerFirestore();

packages/firestore/lite/src/api/reference.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,11 @@ export function parent<T>(
526526
if (parentPath.isEmpty()) {
527527
return null;
528528
} else {
529-
return new DocumentReference(child.firestore, /* converter= */ null, parentPath);
529+
return new DocumentReference(
530+
child.firestore,
531+
/* converter= */ null,
532+
parentPath
533+
);
530534
}
531535
} else {
532536
const doc = cast<DocumentReference<T>>(child, DocumentReference);
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 '../register';
19+
20+
/**
21+
* This will include all of the test files and compile them as needed
22+
*
23+
* Taken from karma-webpack source:
24+
* https://github.com/webpack-contrib/karma-webpack#alternative-usage
25+
*/
26+
27+
// 'context()' definition requires additional dependency on webpack-env package.
28+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
29+
const testsContext = (require as any).context('.', true, /^.*\.test.*$/);
30+
const browserTests = testsContext.keys();
31+
browserTests.forEach(testsContext);

packages/firestore/package.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323
"gendeps:exp": "../../scripts/exp/extract-deps.sh --types ./exp-types/index.d.ts --bundle ./dist/exp/tmp.js --output ./exp/dependencies.json",
2424
"pregendeps:lite" : "node scripts/build-bundle.js --input ./lite/index.ts --output ./dist/lite/tmp.js",
2525
"gendeps:lite": "../../scripts/exp/extract-deps.sh --types ./lite-types/index.d.ts --bundle ./dist/lite/tmp.js --output ./lite/dependencies.json",
26+
"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",
27+
"test:lite:browser": "karma start --single-run --lite",
28+
"test:lite:browser:debug": "karma start --single-run --lite --auto-watch",
2629
"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",
2730
"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",
31+
"test:exp:browser": "karma start --single-run --exp",
32+
"test:exp:browser:debug": "karma start --single-run --exp --auto-watch",
2833
"test": "run-s lint test:all",
2934
"test:ci": "node ../../scripts/run_tests_in_ci.js",
30-
"test:all": "run-p test:browser test:travis test:minified test:exp test:lite",
35+
"test:all": "run-p test:browser test:lite:browser test:exp:browser test:travis test:minified test:exp test:lite",
3136
"test:browser": "karma start --single-run",
3237
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
3338
"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",
@@ -36,7 +41,6 @@
3641
"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",
3742
"test:travis": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts",
3843
"test:minified": "(cd ../../integration/firestore ; yarn test)",
39-
"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",
4044
"prepare": "yarn build:release"
4145
},
4246
"main": "dist/index.node.cjs.js",

packages/firestore/scripts/build-bundle.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@ const typescriptPlugin = require('rollup-plugin-typescript2');
2222
const alias = require('@rollup/plugin-alias');
2323
const json = require('rollup-plugin-json');
2424

25-
import {
26-
removeAssertTransformer,
27-
resolveNodeExterns,
28-
generateAliasConfig
29-
} from '../rollup.shared';
25+
const util = require('../rollup.shared');
3026

3127
const argv = yargs.options({
3228
input: {
@@ -52,18 +48,18 @@ async function buildBundle(input: string, output: string): Promise<void> {
5248
const bundle = await rollup({
5349
input,
5450
plugins: [
55-
alias(generateAliasConfig('node')),
51+
alias(util.generateAliasConfig('node')),
5652
typescriptPlugin({
5753
tsconfigOverride: {
5854
compilerOptions: {
5955
target: 'es2017'
6056
}
6157
},
62-
transformers: removeAssertTransformer
58+
transformers: util.removeAssertTransformer
6359
}),
6460
json({ preferConst: true })
6561
],
66-
external: resolveNodeExterns
62+
external: util.resolveNodeExterns
6763
});
6864
await bundle.write({ file: output, format: 'es' });
6965
}

packages/firestore/src/platform/browser/webchannel_connection.ts

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const RPC_URL_VERSION = 'v1';
6262
const RPC_NAME_REST_MAPPING: { [key: string]: string } = {};
6363
RPC_NAME_REST_MAPPING['BatchGetDocuments'] = 'batchGet';
6464
RPC_NAME_REST_MAPPING['Commit'] = 'commit';
65+
RPC_NAME_REST_MAPPING['RunQuery'] = 'runQuery';
6566

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

0 commit comments

Comments
 (0)