UNPKG

@intuitionrobotics/thunderstorm

Version:
90 lines 4.17 kB
"use strict"; /* * Thunderstorm is a full web app framework! * * Typescript & Express backend infrastructure that natively runs on firebase function * Typescript & React frontend infrastructure * * Copyright (C) 2020 Intuition Robotics * * 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. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.StormTester = void 0; const ts_common_1 = require("@intuitionrobotics/ts-common"); const BaseStorm_1 = require("../app-backend/core/BaseStorm"); const fs = require("fs"); const backend_1 = require("@intuitionrobotics/firebase/backend"); const testelot_1 = require("@intuitionrobotics/testelot"); class StormTester extends BaseStorm_1.BaseStorm { constructor() { super(); this.reporter = new testelot_1.Reporter(); this.prepare = () => { backend_1.FirebaseModule_Class.localAdminConfigId = "test-permissions"; let pathToServiceAccount = process.env.npm_config_service_account || process.argv.find((arg) => arg.startsWith("--service-account=")); if (!pathToServiceAccount) throw new ts_common_1.ImplementationMissingException("could not find path to service account!!!"); pathToServiceAccount = pathToServiceAccount.replace("--service-account=", ""); const key = JSON.parse(fs.readFileSync(pathToServiceAccount, "utf8")); backend_1.FirebaseModule.setDefaultConfig({ "test-permissions": key }); }; this.runTestsImpl = () => __awaiter(this, void 0, void 0, function* () { if (!this.scenario) throw new ts_common_1.ImplementationMissingException("No test specified!!"); this.prepare(); this.init(); this.reporter.init(); testelot_1.Action.resolveTestsToRun(); const scenario = (0, testelot_1.__scenario)("root", this.reporter); scenario.add(this.scenario); yield scenario.run(); }); this.setEnvironment("test-permissions"); } setScenario(scenario) { this.scenario = scenario; return this; } build() { const pwd = process.env.PWD; let packageName; if (pwd) packageName = pwd.substring(pwd.lastIndexOf("/") + 1); this.runTestsImpl() .then(() => { const errorCount = this.reporter.summary.Error; if (errorCount > 0) { this.logError(`Package: ${packageName} - Tests ended with ${errorCount} ${errorCount === 1 ? "error" : "errors"}`); process.exit(2); } this.logInfo(`Package: ${packageName} - Tests completed successfully`); process.exit(0); }) .catch(reason => { this.logError(`Package: ${packageName} - Tests failed`, reason); process.exit(3); }); } } exports.StormTester = StormTester; //# sourceMappingURL=StormTester.js.map