|
| 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 | +const { resolve } = require('path'); |
| 19 | +const { spawn } = require('child-process-promise'); |
| 20 | + |
| 21 | +const argv = require('yargs').boolean(['emulator', 'persistence']).argv; |
| 22 | + |
| 23 | +const nyc = resolve(__dirname, '../../../node_modules/.bin/nyc'); |
| 24 | +const mocha = resolve(__dirname, '../../../node_modules/.bin/mocha'); |
| 25 | + |
| 26 | +const env = { |
| 27 | + ...process.env, |
| 28 | + TS_NODE_COMPILER_OPTIONS: '{"module":"commonjs"}' |
| 29 | +}; |
| 30 | + |
| 31 | +let args = [ |
| 32 | + nyc, |
| 33 | + mocha, |
| 34 | + '--require', |
| 35 | + argv.main, |
| 36 | + '--config', |
| 37 | + '../../config/mocharc.node.js' |
| 38 | +]; |
| 39 | + |
| 40 | +if (argv.emulator) { |
| 41 | + env.FIRESTORE_EMULATOR_PORT = 8080; |
| 42 | + env.FIRESTORE_EMULATOR_PROJECT_ID = 'test-emulator'; |
| 43 | +} |
| 44 | + |
| 45 | +if (argv.persistence) { |
| 46 | + env.USE_MOCK_PERSISTENCE = 'YES'; |
| 47 | + args.push('--require', 'test/util/node_persistence.ts'); |
| 48 | +} |
| 49 | + |
| 50 | +args = args.concat(argv._); |
| 51 | + |
| 52 | +console.log(args.join(' ')); |
| 53 | + |
| 54 | +process.chdir(process.cwd()); |
| 55 | +const childProcess = spawn(process.execPath, args, { stdio: 'inherit', env }) |
| 56 | + .childProcess; |
| 57 | + |
| 58 | +process.once('exit', () => childProcess.kill()); |
| 59 | +process.once('SIGINT', () => childProcess.kill('SIGINT')); |
| 60 | +process.once('SIGTERM', () => childProcess.kill('SIGTERM')); |
0 commit comments