Skip to content

Commit 7ecfec8

Browse files
Add test runner script
1 parent 8a631e2 commit 7ecfec8

File tree

8 files changed

+173
-17
lines changed

8 files changed

+173
-17
lines changed

packages/firestore/exp-types/index.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,7 @@ export function getDocFromServer<T>(
374374
reference: DocumentReference<T>
375375
): Promise<DocumentSnapshot<T>>;
376376
export function getDocs<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
377-
export function getDocsFromCache<T>(
378-
query: Query<T>
379-
): Promise<QuerySnapshot<T>>;
377+
export function getDocsFromCache<T>(query: Query<T>): Promise<QuerySnapshot<T>>;
380378
export function getDocsFromServer<T>(
381379
query: Query<T>
382380
): Promise<QuerySnapshot<T>>;

packages/firestore/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@
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",
26+
"test:lite":"node ./scripts/run-tests.js --emulator --main=lite/index.ts 'lite/test/**/*.test.ts'",
2727
"test:lite:browser": "karma start --single-run --lite",
2828
"test:lite:browser:debug": "karma start --single-run --lite --auto-watch",
29-
"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",
30-
"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",
29+
"test:exp": "node ./scripts/run-tests.js --emulator --main=exp/index.ts test/integration/api/*.test.ts",
30+
"test:exp:persistence":"node ./scripts/run-tests.js --emulator --persistence --main=exp/index.ts test/integration/api/*.test.ts",
3131
"test:exp:browser": "karma start --single-run --exp",
3232
"test:exp:browser:debug": "karma start --single-run --exp --auto-watch",
3333
"test": "run-s lint test:all",
3434
"test:ci": "node ../../scripts/run_tests_in_ci.js",
3535
"test:all": "run-p test:browser test:lite:browser test:exp:browser test:travis test:minified test:exp test:lite",
3636
"test:browser": "karma start --single-run",
3737
"test:browser:debug": "karma start --browsers=Chrome --auto-watch",
38-
"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",
39-
"test:node:prod": "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",
40-
"test:node:persistence": "FIRESTORE_EMULATOR_PORT=8080 FIRESTORE_EMULATOR_PROJECT_ID=test-emulator 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",
41-
"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",
38+
"test:node": "node ./scripts/run-tests.js --main=index.node.ts --emulator 'test/{,!(browser)/**/}*.test.ts'",
39+
"test:node:prod": "node ./scripts/run-tests.js --main=index.node.ts 'test/{,!(browser)/**/}*.test.ts'",
40+
"test:node:persistence": "node ./scripts/run-tests.js --main=index.node.ts --persistence --emulator 'test/{,!(browser)/**/}*.test.ts'",
41+
"test:node:persistence:prod": "node ./scripts/run-tests.js --main=index.node.ts --persistence 'test/{,!(browser)/**/}*.test.ts'",
4242
"test:travis": "ts-node --compiler-options='{\"module\":\"commonjs\"}' ../../scripts/emulator-testing/firestore-test-runner.ts",
4343
"test:minified": "(cd ../../integration/firestore ; yarn test)",
4444
"prepare": "yarn build:release"

packages/firestore/scripts/build-bundle.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ var rollup_1 = require('rollup');
154154
var typescriptPlugin = require('rollup-plugin-typescript2');
155155
var alias = require('@rollup/plugin-alias');
156156
var json = require('rollup-plugin-json');
157-
var rollup_shared_1 = require('../rollup.shared');
157+
var util = require('../rollup.shared');
158158
var argv = yargs.options({
159159
input: {
160160
type: 'string',
@@ -185,18 +185,18 @@ function buildBundle(input, output) {
185185
rollup_1.rollup({
186186
input: input,
187187
plugins: [
188-
alias(rollup_shared_1.generateAliasConfig('node')),
188+
alias(util.generateAliasConfig('node')),
189189
typescriptPlugin({
190190
tsconfigOverride: {
191191
compilerOptions: {
192192
target: 'es2017'
193193
}
194194
},
195-
transformers: rollup_shared_1.removeAssertTransformer
195+
transformers: util.removeAssertTransformer
196196
}),
197197
json({ preferConst: true })
198198
],
199-
external: rollup_shared_1.resolveNodeExterns
199+
external: util.resolveNodeExterns
200200
})
201201
];
202202
case 1:
@@ -209,4 +209,5 @@ function buildBundle(input, output) {
209209
});
210210
});
211211
}
212+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
212213
buildBundle(argv.input, argv.output);

packages/firestore/scripts/extract-api.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
exports.__esModule = true;
1919
exports.extractPublicIdentifiers = void 0;
20-
// eslint-disable-next-line import/no-extraneous-dependencies
2120
var ts = require('typescript');
2221
var fs = require('fs');
2322
function extractIdentifiersFromNodeAndChildren(node, symbols) {

packages/firestore/scripts/remove-asserts.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
exports.__esModule = true;
1919
exports.removeAsserts = void 0;
20-
// eslint-disable-next-line import/no-extraneous-dependencies
2120
var ts = require('typescript');
2221
// Location of file that includes the asserts
2322
var ASSERT_LOCATION = 'packages/firestore/src/util/assert.ts';

packages/firestore/scripts/rename-internals.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
*/
1818
exports.__esModule = true;
1919
exports.renameInternals = void 0;
20-
// eslint-disable-next-line import/no-extraneous-dependencies
2120
var ts = require('typescript');
2221
// `undefined` is treated as an identifier by TSC, but not part of any externs.
2322
var blacklist = ['undefined'];
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
'use strict';
2+
/**
3+
* @license
4+
* Copyright 2020 Google LLC
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
var __assign =
19+
(this && this.__assign) ||
20+
function () {
21+
__assign =
22+
Object.assign ||
23+
function (t) {
24+
for (var s, i = 1, n = arguments.length; i < n; i++) {
25+
s = arguments[i];
26+
for (var p in s)
27+
if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
28+
}
29+
return t;
30+
};
31+
return __assign.apply(this, arguments);
32+
};
33+
exports.__esModule = true;
34+
var yargs = require('yargs');
35+
var path_1 = require('path');
36+
var child_process_promise_1 = require('child-process-promise');
37+
var argv = yargs.options({
38+
main: {
39+
type: 'string',
40+
demandOption: true
41+
},
42+
emulator: {
43+
type: 'boolean'
44+
},
45+
persistence: {
46+
type: 'boolean'
47+
}
48+
}).argv;
49+
var nyc = path_1.resolve(__dirname, '../../../node_modules/.bin/nyc');
50+
var mocha = path_1.resolve(__dirname, '../../../node_modules/.bin/mocha');
51+
var env = __assign(__assign({}, process.env), {
52+
TS_NODE_CACHE: 'NO',
53+
TS_NODE_COMPILER_OPTIONS: '{"module":"commonjs"}'
54+
});
55+
var args = [
56+
mocha,
57+
'--require',
58+
'ts-node/register',
59+
'--require',
60+
argv.main,
61+
'--config',
62+
'../../config/mocharc.node.js'
63+
];
64+
if (argv.emulator) {
65+
env.FIRESTORE_EMULATOR_PORT = '8080';
66+
env.FIRESTORE_EMULATOR_PROJECT_ID = 'test-emulator';
67+
}
68+
if (argv.persistence) {
69+
env.USE_MOCK_PERSISTENCE = 'YES';
70+
args.push('--require', 'test/util/node_persistence.ts');
71+
}
72+
args = args.concat(argv._);
73+
var childProcess = child_process_promise_1.spawn(nyc, args, {
74+
stdio: 'inherit',
75+
env: env,
76+
cwd: process.cwd()
77+
}).childProcess;
78+
process.once('exit', function () {
79+
return childProcess.kill();
80+
});
81+
process.once('SIGINT', function () {
82+
return childProcess.kill('SIGINT');
83+
});
84+
process.once('SIGTERM', function () {
85+
return childProcess.kill('SIGTERM');
86+
});
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 * as yargs from 'yargs';
19+
import { resolve } from 'path';
20+
import { spawn } from 'child-process-promise';
21+
22+
const argv = yargs.options({
23+
main: {
24+
type: 'string',
25+
demandOption: true
26+
},
27+
emulator: {
28+
type: 'boolean'
29+
},
30+
persistence: {
31+
type: 'boolean'
32+
}
33+
}).argv;
34+
35+
const nyc = resolve(__dirname, '../../../node_modules/.bin/nyc');
36+
const mocha = resolve(__dirname, '../../../node_modules/.bin/mocha');
37+
38+
const env: { [key: string]: string } = {
39+
...process.env,
40+
TS_NODE_CACHE: 'NO',
41+
TS_NODE_COMPILER_OPTIONS: '{"module":"commonjs"}'
42+
};
43+
44+
let args = [
45+
mocha,
46+
'--require',
47+
'ts-node/register',
48+
'--require',
49+
argv.main,
50+
'--config',
51+
'../../config/mocharc.node.js'
52+
];
53+
54+
if (argv.emulator) {
55+
env.FIRESTORE_EMULATOR_PORT = '8080';
56+
env.FIRESTORE_EMULATOR_PROJECT_ID = 'test-emulator';
57+
}
58+
59+
if (argv.persistence) {
60+
env.USE_MOCK_PERSISTENCE = 'YES';
61+
args.push('--require', 'test/util/node_persistence.ts');
62+
}
63+
64+
args = args.concat(argv._);
65+
66+
const childProcess = spawn(nyc, args, {
67+
stdio: 'inherit',
68+
env,
69+
cwd: process.cwd()
70+
}).childProcess;
71+
72+
process.once('exit', () => childProcess.kill());
73+
process.once('SIGINT', () => childProcess.kill('SIGINT'));
74+
process.once('SIGTERM', () => childProcess.kill('SIGTERM'));

0 commit comments

Comments
 (0)