Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix firestore node tests #5741

Merged
merged 4 commits into from Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/plenty-trains-switch.md
@@ -0,0 +1,6 @@
---
"@firebase/firestore-compat": patch
"@firebase/firestore": patch
---

fix firestore node tests
20 changes: 5 additions & 15 deletions .vscode/launch.json
Expand Up @@ -29,16 +29,12 @@
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
"cwd": "${workspaceRoot}/packages/firestore",
"args": [
"--require", "ts-node/register/type-check",
"--require", "babel-register.js",
"--require", "index.node.ts",
"--timeout", "5000",
"test/{,!(browser|integration)/**/}*.test.ts",
"--exit"
],
"env": {
"TS_NODE_CACHE": "NO",
"TS_NODE_COMPILER_OPTIONS" : "{\"module\":\"commonjs\"}"
},
"sourceMaps": true,
"protocol": "inspector"
},
Expand All @@ -49,17 +45,15 @@
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
"cwd": "${workspaceRoot}/packages/firestore",
"args": [
"--require", "ts-node/register/type-check",
"--require", "babel-register.js",
"--require", "index.node.ts",
"--require", "test/util/node_persistence.ts",
"--timeout", "5000",
"test/{,!(browser|integration)/**/}*.test.ts",
"--exit"
],
"env": {
"USE_MOCK_PERSISTENCE": "YES",
"TS_NODE_CACHE": "NO",
"TS_NODE_COMPILER_OPTIONS" : "{\"module\":\"commonjs\"}"
"USE_MOCK_PERSISTENCE": "YES"
},
"sourceMaps": true,
"protocol": "inspector"
Expand All @@ -71,15 +65,13 @@
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
"cwd": "${workspaceRoot}/packages/firestore",
"args": [
"--require", "ts-node/register/type-check",
"--require", "babel-register.js",
"--require", "index.node.ts",
"--timeout", "5000",
"test/{,!(browser|unit)/**/}*.test.ts",
"--exit"
],
"env": {
"TS_NODE_CACHE": "NO",
"TS_NODE_COMPILER_OPTIONS" : "{\"module\":\"commonjs\"}",
"FIRESTORE_EMULATOR_PORT" : "8080",
"FIRESTORE_EMULATOR_PROJECT_ID" : "test-emulator"
},
Expand All @@ -93,7 +85,7 @@
"program": "${workspaceRoot}/node_modules/.bin/_mocha",
"cwd": "${workspaceRoot}/packages/firestore",
"args": [
"--require", "ts-node/register/type-check",
"--require", "babel-register.js",
"--require", "index.node.ts",
"--require", "test/util/node_persistence.ts",
"--timeout", "5000",
Expand All @@ -102,8 +94,6 @@
],
"env": {
"USE_MOCK_PERSISTENCE": "YES",
"TS_NODE_CACHE": "NO",
"TS_NODE_COMPILER_OPTIONS" : "{\"module\":\"commonjs\"}",
"FIRESTORE_EMULATOR_PORT" : "8080",
"FIRESTORE_EMULATOR_PROJECT_ID" : "test-emulator"
},
Expand Down
5 changes: 5 additions & 0 deletions config/mocharc.node.js
Expand Up @@ -34,4 +34,9 @@ if (process.env.CI) {
config.reporter = 'min';
}

// Firestore uses babel to compile tests in Nodejs
if (process.env.NO_TS_NODE) {
delete config.require;
}

module.exports = config;
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -62,9 +62,12 @@
"repo-scripts/*"
],
"devDependencies": {
"@babel/core": "7.15.5",
"@babel/plugin-transform-modules-commonjs": "7.15.4",
"@babel/preset-env": "7.15.6",
"@babel/core": "7.16.0",
"@babel/plugin-transform-modules-commonjs": "7.16.0",
"@babel/preset-env": "7.16.0",
"@babel/register": "7.16.0",
"@babel/preset-typescript": "7.16.0",
"babel-plugin-transform-import-meta": "2.1.0",
"@changesets/changelog-github": "0.4.1",
"@changesets/cli": "2.17.0",
"@types/chai": "4.2.22",
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore-compat/src/config.ts
Expand Up @@ -84,7 +84,7 @@ export function configureForFirebase(
const firestoreExp = container.getProvider('firestore').getImmediate()!;
return firestoreFactory(app, firestoreExp);
},
ComponentType.PUBLIC
'PUBLIC' as ComponentType.PUBLIC
).setServiceProps({ ...firestoreNamespace })
);
}
2 changes: 1 addition & 1 deletion packages/firestore-compat/src/index.ts
Expand Up @@ -17,7 +17,7 @@

// eslint-disable-next-line import/no-extraneous-dependencies
import firebase from '@firebase/app-compat';
import { FirebaseNamespace } from '@firebase/app-types';
import type { FirebaseNamespace } from '@firebase/app-types';
import * as types from '@firebase/firestore-types';

import { name, version } from '../package.json';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions packages/firestore/.idea/runConfigurations/Unit_Tests.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions packages/firestore/babel-register.js
@@ -0,0 +1,18 @@
/**
* @license
* Copyright 2021 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.
*/

require('@babel/register')({ extensions: ['.js', '.ts'] });
7 changes: 7 additions & 0 deletions packages/firestore/babel.config.json
@@ -0,0 +1,7 @@
{
"presets": [
"@babel/preset-typescript",
["@babel/preset-env", {"targets": {"node": "10"}, "modules": "cjs"}]
],
"plugins": ["babel-plugin-transform-import-meta"]
}
2 changes: 1 addition & 1 deletion packages/firestore/lite/register.ts
Expand Up @@ -50,7 +50,7 @@ export function registerFirestore(): void {
}
return firestoreInstance;
},
ComponentType.PUBLIC
'PUBLIC' as ComponentType.PUBLIC
)
);
// RUNTIME_ENV and BUILD_TARGET are replaced by real values during the compilation
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/package.json
Expand Up @@ -34,7 +34,7 @@
"test:browser": "karma start --single-run",
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
"test:node": "node ./scripts/run-tests.js --main=test/register.ts --emulator 'test/{,!(browser|lite)/**/}*.test.ts'",
"test:node:prod": "ts-node-script ./scripts/run-tests.ts --main=test/register.ts 'test/{,!(browser|lite)/**/}*.test.ts'",
"test:node:prod": "node ./scripts/run-tests.js --main=test/register.ts 'test/{,!(browser|lite)/**/}*.test.ts'",
"test:node:persistence": "node ./scripts/run-tests.js --main=test/register.ts --persistence --emulator 'test/{,!(browser|lite)/**/}*.test.ts'",
"test:node:persistence:prod": "node ./scripts/run-tests.js --main=test/register.ts --persistence 'test/{,!(browser|lite)/**/}*.test.ts'",
"test:travis": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/scripts/run-tests.js
Expand Up @@ -14,4 +14,4 @@
* 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.
*/exports.__esModule=true;var path_1=require("path");var child_process_promise_1=require("child-process-promise");var yargs=require("yargs");var argv=yargs.options({main:{type:"string",demandOption:true},platform:{type:"string",default:"node"},emulator:{type:"boolean"},persistence:{type:"boolean"}}).argv;var nyc=path_1.resolve(__dirname,"../../../node_modules/.bin/nyc");var mocha=path_1.resolve(__dirname,"../../../node_modules/.bin/mocha");process.env.TS_NODE_CACHE="NO";process.env.TS_NODE_COMPILER_OPTIONS='{"module":"commonjs"}';process.env.TEST_PLATFORM=argv.platform;var args=["--reporter","lcovonly",mocha,"--require","ts-node/register","--require",argv.main,"--config","../../config/mocharc.node.js"];if(argv.emulator){process.env.FIRESTORE_EMULATOR_PORT="8080";process.env.FIRESTORE_EMULATOR_PROJECT_ID="test-emulator"}if(argv.persistence){process.env.USE_MOCK_PERSISTENCE="YES";args.push("--require","test/util/node_persistence.ts")}args=args.concat(argv._);var childProcess=child_process_promise_1.spawn(nyc,args,{stdio:"inherit",cwd:process.cwd()}).childProcess;process.once("exit",(function(){return childProcess.kill()}));process.once("SIGINT",(function(){return childProcess.kill("SIGINT")}));process.once("SIGTERM",(function(){return childProcess.kill("SIGTERM")}));
*/exports.__esModule=true;var path_1=require("path");var child_process_promise_1=require("child-process-promise");var yargs=require("yargs");var argv=yargs.options({main:{type:"string",demandOption:true},platform:{type:"string",default:"node"},emulator:{type:"boolean"},persistence:{type:"boolean"}}).parseSync();var nyc=path_1.resolve(__dirname,"../../../node_modules/.bin/nyc");var mocha=path_1.resolve(__dirname,"../../../node_modules/.bin/mocha");var babel=path_1.resolve(__dirname,"../babel-register.js");process.env.NO_TS_NODE="true";process.env.TEST_PLATFORM=argv.platform;var args=["--reporter","lcovonly",mocha,"--require",babel,"--require",argv.main,"--config","../../config/mocharc.node.js"];if(argv.emulator){process.env.FIRESTORE_EMULATOR_PORT="8080";process.env.FIRESTORE_EMULATOR_PROJECT_ID="test-emulator"}if(argv.persistence){process.env.USE_MOCK_PERSISTENCE="YES";args.push("--require","test/util/node_persistence.ts")}args=args.concat(argv._);var childProcess=child_process_promise_1.spawn(nyc,args,{stdio:"inherit",cwd:process.cwd()}).childProcess;process.once("exit",(function(){return childProcess.kill()}));process.once("SIGINT",(function(){return childProcess.kill("SIGINT")}));process.once("SIGTERM",(function(){return childProcess.kill("SIGTERM")}));
7 changes: 4 additions & 3 deletions packages/firestore/scripts/run-tests.ts
Expand Up @@ -39,17 +39,18 @@ const argv = yargs.options({

const nyc = resolve(__dirname, '../../../node_modules/.bin/nyc');
const mocha = resolve(__dirname, '../../../node_modules/.bin/mocha');
const babel = resolve(__dirname, '../babel-register.js');

process.env.TS_NODE_CACHE = 'NO';
process.env.TS_NODE_COMPILER_OPTIONS = '{"module":"commonjs"}';
// used in '../../config/mocharc.node.js' to disable ts-node
process.env.NO_TS_NODE = "true";
process.env.TEST_PLATFORM = argv.platform;

let args = [
'--reporter',
'lcovonly',
mocha,
'--require',
'ts-node/register',
babel,
'--require',
argv.main,
'--config',
Expand Down
4 changes: 2 additions & 2 deletions packages/firestore/src/platform/node/grpc_connection.ts
Expand Up @@ -40,9 +40,9 @@ import { Deferred } from '../../util/promise';

// This is a hack fix for Node ES modules to use `require`.
// @ts-ignore To avoid using `--module es2020` flag.
const require = module.createRequire(import.meta.url);
const requireInESM = module.createRequire(import.meta.url);
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { version: grpcVersion } = require('@grpc/grpc-js/package.json');
const { version: grpcVersion } = requireInESM('@grpc/grpc-js/package.json');

const LOG_TAG = 'Connection';
const X_GOOG_API_CLIENT_VALUE = `gl-node/${process.versions.node} fire/${SDK_VERSION} grpc/${grpcVersion}`;
Expand Down
6 changes: 3 additions & 3 deletions packages/firestore/src/platform/node/load_protos.ts
Expand Up @@ -20,8 +20,8 @@ import { fileURLToPath } from 'url';

// __filename and __dirname globals are unavailable in ES modules
// @ts-ignore To avoid using `--module es2020` flag.
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const __filenameInESM = fileURLToPath(import.meta.url);
const __dirnameInESM = dirname(__filenameInESM);

import { loadPackageDefinition, GrpcObject } from '@grpc/grpc-js';
import { loadSync } from '@grpc/proto-loader';
Expand All @@ -44,7 +44,7 @@ export const protoLoaderOptions: IConversionOptions = {
*/
export function loadProtos(): GrpcObject {
const root = resolve(
__dirname,
__dirnameInESM,
process.env.FIRESTORE_PROTO_ROOT || '../../protos'
);
const firestoreProtoFile = join(root, 'google/firestore/v1/firestore.proto');
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/src/register.ts
Expand Up @@ -49,7 +49,7 @@ export function registerFirestore(
firestoreInstance._setSettings(settings);
return firestoreInstance;
},
ComponentType.PUBLIC
'PUBLIC' as ComponentType.PUBLIC
)
);
registerVersion(name, version, variant);
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/test/unit/specs/describe_spec.ts
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

import * as stringify from 'json-stable-stringify';
import stringify from 'json-stable-stringify';
import { ExclusiveTestFunction, PendingTestFunction } from 'mocha';

import { queryEquals, QueryImpl } from '../../../src/core/query';
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/test/util/node_persistence.ts
Expand Up @@ -19,7 +19,7 @@ import * as fs from 'fs';
import * as os from 'os';

// @ts-ignore: There are no types for indexeddbshim.
import * as registerIndexedDBShim from 'indexeddbshim';
import registerIndexedDBShim from 'indexeddbshim';

import { FakeWindow, SharedFakeWebStorage } from './test_platform';

Expand Down