Skip to content

Commit 2894484

Browse files
CI
1 parent e63bea7 commit 2894484

File tree

13 files changed

+48
-130
lines changed

13 files changed

+48
-130
lines changed

packages/firestore/exp/test/bootstrap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import '../register';
2424
* https://github.com/webpack-contrib/karma-webpack#alternative-usage
2525
*/
2626

27+
process.env.TEST_PLATFORM = 'browser';
28+
2729
// 'context()' definition requires additional dependency on webpack-env package.
2830
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2931
const testsContext = (require as any).context(

packages/firestore/lite/test/bootstrap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import '../register';
2424
* https://github.com/webpack-contrib/karma-webpack#alternative-usage
2525
*/
2626

27+
process.env.TEST_PLATFORM = 'node-lite';
28+
2729
// 'context()' definition requires additional dependency on webpack-env package.
2830
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2931
const testsContext = (require as any).context('.', true, /^.*\.test.*$/);

packages/firestore/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"gendeps:exp": "../../scripts/exp/extract-deps.sh --types ./exp-types/index.d.ts --bundle ./dist/exp/tmp.js --output ./exp/dependencies.json",
2525
"pregendeps:lite": "node scripts/build-bundle.js --input ./lite/index.ts --output ./dist/lite/tmp.js",
2626
"gendeps:lite": "../../scripts/exp/extract-deps.sh --types ./lite-types/index.d.ts --bundle ./dist/lite/tmp.js --output ./lite/dependencies.json",
27-
"test:lite": "node ./scripts/run-tests.js --emulator --main=lite/index.ts 'lite/test/**/*.test.ts'",
27+
"test:lite": "node ./scripts/run-tests.js --emulator --platform node_lite --main=lite/index.ts 'lite/test/**/*.test.ts'",
2828
"test:lite:browser": "karma start --single-run --lite",
2929
"test:lite:browser:debug": "karma start --single-run --lite --auto-watch",
3030
"test:exp": "node ./scripts/run-tests.js --emulator --main=exp/index.ts test/integration/api/*.test.ts",

packages/firestore/scripts/run-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
17-
*/exports.__esModule=true;var yargs=require("yargs");var path_1=require("path");var child_process_promise_1=require("child-process-promise");var argv=yargs.options({main:{type:"string",demandOption:true},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"}';var args=[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")}));
17+
*/exports.__esModule=true;var yargs=require("yargs");var path_1=require("path");var child_process_promise_1=require("child-process-promise");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=[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")}));

packages/firestore/scripts/run-tests.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const argv = yargs.options({
2424
type: 'string',
2525
demandOption: true
2626
},
27+
platform: {
28+
type: 'string',
29+
default: 'node'
30+
},
2731
emulator: {
2832
type: 'boolean'
2933
},
@@ -37,6 +41,7 @@ const mocha = resolve(__dirname, '../../../node_modules/.bin/mocha');
3741

3842
process.env.TS_NODE_CACHE = 'NO';
3943
process.env.TS_NODE_COMPILER_OPTIONS = '{"module":"commonjs"}';
44+
process.env.TEST_PLATFORM = argv.platform;
4045

4146
let args = [
4247
mocha,

packages/firestore/src/platform/base64.ts

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,21 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { isNode, isReactNative } from '@firebase/util';
19-
20-
import * as node from './node/base64';
21-
import * as rn from './rn/base64';
22-
import * as browser from './browser/base64';
18+
// This file is only used under ts-node.
19+
// eslint-disable-next-line @typescript-eslint/no-require-imports
20+
const platform = require(`${process.env.TEST_PLATFORM}/base64`);
2321

2422
/** Converts a Base64 encoded string to a binary string. */
2523
export function decodeBase64(encoded: string): string {
26-
if (isNode()) {
27-
return node.decodeBase64(encoded);
28-
} else if (isReactNative()) {
29-
return rn.decodeBase64(encoded);
30-
} else {
31-
return browser.decodeBase64(encoded);
32-
}
24+
return platform.decodeBase64(encoded);
3325
}
3426

3527
/** Converts a binary string to a Base64 encoded string. */
3628
export function encodeBase64(raw: string): string {
37-
if (isNode()) {
38-
return node.encodeBase64(raw);
39-
} else if (isReactNative()) {
40-
return rn.encodeBase64(raw);
41-
} else {
42-
return browser.encodeBase64(raw);
43-
}
29+
return platform.encodeBase64(raw);
4430
}
4531

4632
/** True if and only if the Base64 conversion functions are available. */
4733
export function isBase64Available(): boolean {
48-
if (isNode()) {
49-
return node.isBase64Available();
50-
} else if (isReactNative()) {
51-
return rn.isBase64Available();
52-
} else {
53-
return browser.isBase64Available();
54-
}
34+
return platform.isBase64Available();
5535
}

packages/firestore/src/platform/connection.ts

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,18 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
import {ConnectivityMonitor} from "../remote/connectivity_monitor";
18+
import {DatabaseInfo} from "../core/database_info";
19+
import {Connection} from "../remote/connection";
1720

18-
// This file is only used in when the client is run under ts-node
19-
// eslint-disable-next-line import/no-extraneous-dependencies
20-
import { _components } from '@firebase/app-exp';
21-
22-
import { isNode, isReactNative } from '@firebase/util';
23-
import { ConnectivityMonitor } from '../remote/connectivity_monitor';
24-
import { DatabaseInfo } from '../core/database_info';
25-
import { Connection } from '../remote/connection';
26-
import * as node from './node/connection';
27-
import * as nodeLite from './node_lite/connection';
28-
import * as rn from './rn/connection';
29-
import * as browser from './browser/connection';
30-
import * as browserLite from './browser_lite/connection';
31-
32-
function isLite(): boolean {
33-
return _components.has('firestore/lite');
34-
}
21+
// This file is only used under ts-node.
22+
// eslint-disable-next-line @typescript-eslint/no-require-imports
23+
const platform = require(`${process.env.TEST_PLATFORM}/base64`);
3524

3625
export function newConnectivityMonitor(): ConnectivityMonitor {
37-
if (isNode()) {
38-
return node.newConnectivityMonitor();
39-
} else if (isReactNative()) {
40-
return rn.newConnectivityMonitor();
41-
} else {
42-
return browser.newConnectivityMonitor();
43-
}
26+
return platform.newConnectivityMonitor();
4427
}
4528

4629
export function newConnection(databaseInfo: DatabaseInfo): Promise<Connection> {
47-
if (isNode()) {
48-
return isLite()
49-
? nodeLite.newConnection(databaseInfo)
50-
: node.newConnection(databaseInfo);
51-
} else if (isReactNative()) {
52-
return rn.newConnection(databaseInfo);
53-
} else {
54-
return isLite()
55-
? browserLite.newConnection(databaseInfo)
56-
: browser.newConnection(databaseInfo);
57-
}
30+
return platform.newConnection(databaseInfo);
5831
}

packages/firestore/src/platform/dom.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,16 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { isNode, isReactNative } from '@firebase/util';
19-
import * as node from './node/dom';
20-
import * as rn from './rn/dom';
21-
import * as browser from './browser/dom';
18+
// This file is only used under ts-node.
19+
// eslint-disable-next-line @typescript-eslint/no-require-imports
20+
const platform = require(`${process.env.TEST_PLATFORM}/base64`);
2221

2322
/** The Platform's 'window' implementation or null if not available. */
2423
export function getWindow(): Window | null {
25-
if (isNode()) {
26-
return node.getWindow();
27-
} else if (isReactNative()) {
28-
return rn.getWindow();
29-
} else {
30-
return browser.getWindow();
31-
}
24+
return platform.getWindow();
3225
}
3326

3427
/** The Platform's 'document' implementation or null if not available. */
3528
export function getDocument(): Document | null {
36-
if (isNode()) {
37-
return node.getDocument();
38-
} else if (isReactNative()) {
39-
return rn.getDocument();
40-
} else {
41-
return browser.getDocument();
42-
}
29+
return platform.getDocument();
4330
}

packages/firestore/src/platform/format_json.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,11 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { isNode, isReactNative } from '@firebase/util';
19-
import * as node from './node/format_json';
20-
import * as rn from './rn/format_json';
21-
import * as browser from './browser/format_json';
18+
// This file is only used under ts-node.
19+
// eslint-disable-next-line @typescript-eslint/no-require-imports
20+
const platform = require(`${process.env.TEST_PLATFORM}/base64`);
2221

2322
/** Formats an object as a JSON string, suitable for logging. */
2423
export function formatJSON(value: unknown): string {
25-
if (isNode()) {
26-
return node.formatJSON(value);
27-
} else if (isReactNative()) {
28-
return rn.formatJSON(value);
29-
} else {
30-
return browser.formatJSON(value);
31-
}
24+
return platform.formatJSON(value);
3225
}

packages/firestore/src/platform/random_bytes.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,15 @@
1515
* limitations under the License.
1616
*/
1717

18-
import { isNode, isReactNative } from '@firebase/util';
19-
import * as node from './node/random_bytes';
20-
import * as rn from './rn/random_bytes';
21-
import * as browser from './browser/random_bytes';
18+
// This file is only used under ts-node.
19+
// eslint-disable-next-line @typescript-eslint/no-require-imports
20+
const platform = require(`${process.env.TEST_PLATFORM}/base64`);
2221

2322
/**
2423
* Generates `nBytes` of random bytes.
2524
*
2625
* If `nBytes < 0` , an error will be thrown.
2726
*/
2827
export function randomBytes(nBytes: number): Uint8Array {
29-
if (isNode()) {
30-
return node.randomBytes(nBytes);
31-
} else if (isReactNative()) {
32-
return rn.randomBytes(nBytes);
33-
} else {
34-
return browser.randomBytes(nBytes);
35-
}
28+
return platform.randomBytes(nBytes);
3629
}

packages/firestore/src/platform/serializer.ts

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,13 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
import {DatabaseId} from "../core/database_info";
18+
import {JsonProtoSerializer} from "../remote/serializer";
1719

18-
// This file is only used in when the client is run under ts-node
19-
// eslint-disable-next-line import/no-extraneous-dependencies
20-
import { _components } from '@firebase/app-exp';
21-
22-
import { isNode, isReactNative } from '@firebase/util';
23-
import * as node from './node/serializer';
24-
import * as nodeLite from './node_lite/serializer';
25-
import * as rn from './rn/serializer';
26-
import * as browser from './browser/serializer';
27-
import * as browserLite from './browser_lite/serializer';
28-
import { DatabaseId } from '../core/database_info';
29-
import { JsonProtoSerializer } from '../remote/serializer';
30-
31-
function isLite(): boolean {
32-
return _components.has('firestore/lite');
33-
}
20+
// This file is only used under ts-node.
21+
// eslint-disable-next-line @typescript-eslint/no-require-imports
22+
const platform = require(`${process.env.TEST_PLATFORM}/serializer`);
3423

3524
export function newSerializer(databaseId: DatabaseId): JsonProtoSerializer {
36-
if (isNode()) {
37-
return isLite()
38-
? nodeLite.newSerializer(databaseId)
39-
: node.newSerializer(databaseId);
40-
} else if (isReactNative()) {
41-
return rn.newSerializer(databaseId);
42-
} else {
43-
return isLite()
44-
? browserLite.newSerializer(databaseId)
45-
: browser.newSerializer(databaseId);
46-
}
25+
return platform.newSerializer(databaseId);
4726
}

packages/firestore/test/integration/bootstrap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import '../../index';
2424
* https://github.com/webpack-contrib/karma-webpack#alternative-usage
2525
*/
2626

27+
process.env.TEST_PLATFORM = 'browser';
28+
2729
// 'context()' definition requires additional dependency on webpack-env package.
2830
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2931
const testsContext = (require as any).context(

packages/firestore/test/unit/bootstrap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* https://github.com/webpack-contrib/karma-webpack#alternative-usage
2323
*/
2424

25+
process.env.TEST_PLATFORM = 'browser';
26+
2527
// 'context()' definition requires additional dependency on webpack-env package.
2628
// eslint-disable-next-line @typescript-eslint/no-explicit-any
2729
const testsContext = (require as any).context(

0 commit comments

Comments
 (0)