UNPKG

@johnf/react-native-owl

Version:
147 lines (144 loc) 5.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.runIOS = exports.runHandler = exports.runAndroid = exports.restoreIOSUI = void 0; var _path = _interopRequireDefault(require("path")); var _execa = _interopRequireDefault(require("execa")); var _fs = require("fs"); var _screenshot = require("../screenshot.js"); var _report = require("../report.js"); var _config = require("./config.js"); var _logger = require("../logger.js"); var _waitFor = require("../utils/wait-for.js"); var _adb = require("../utils/adb.js"); var _xcrun = require("../utils/xcrun.js"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } const runIOS = async config => { if (!config.ios) { return; } await (0, _xcrun.xcrunStatusBar)({ debug: config.debug, device: config.ios.device, configuration: config.ios.configuration, binaryPath: config.ios.binaryPath }); await (0, _xcrun.xcrunInstall)({ debug: config.debug, device: config.ios.device, configuration: config.ios.configuration, binaryPath: config.ios.binaryPath, scheme: config.ios.scheme }); await (0, _xcrun.xcrunLaunch)({ debug: config.debug, device: config.ios.device, configuration: config.ios.configuration, binaryPath: config.ios.binaryPath, scheme: config.ios.scheme }); await (0, _waitFor.waitFor)(1000); // Workaround to force the virtual home button's color to become consistent await (0, _xcrun.xcrunUi)({ debug: config.debug, device: config.ios.device, configuration: config.ios.configuration, binaryPath: config.ios.binaryPath }); }; exports.runIOS = runIOS; const restoreIOSUI = async (config, logger) => { if (!config.ios) { return; } await (0, _xcrun.xcrunRestore)({ debug: config.debug, device: config.ios.device, configuration: config.ios.configuration, binaryPath: config.ios.binaryPath }); logger.print(`[OWL - CLI] Restored status bar time`); }; exports.restoreIOSUI = restoreIOSUI; const runAndroid = async config => { if (!config.android) { return; } await (0, _adb.adbInstall)({ debug: config.debug, buildType: config.android.buildType, binaryPath: config.android.binaryPath }); await (0, _adb.adbLaunch)({ debug: config.debug, packageName: config.android.packageName }); await (0, _waitFor.waitFor)(500); }; exports.runAndroid = runAndroid; const runHandler = async args => { const cwd = process.cwd(); const config = await (0, _config.getConfig)(args.config); const logger = new _logger.Logger(config.debug); const runProject = args.platform === 'ios' ? runIOS : runAndroid; const restoreSimulatorUI = args.platform === 'ios' && restoreIOSUI; // Remove old report and screenshots await (0, _report.cleanupReport)(); await (0, _screenshot.cleanupScreenshots)(); logger.print(`[OWL - CLI] Starting websocket server.`); const webSocketProcess = _execa.default.command('node scripts/websocket-server.js', { stdio: 'inherit', cwd: _path.default.join(__dirname, '..', '..', '..'), env: { OWL_DEBUG: String(!!config.debug) } }); logger.print(`[OWL - CLI] Running tests on ${args.platform}.`); await runProject(config); const jestCommandArgs = ['jest', `--testMatch="**/?(*.)+(owl).[jt]s?(x)"`, '--verbose', `--roots=${cwd}`, '--runInBand', `--globals='${JSON.stringify({ OWL_CLI_ARGS: args })}'`]; if (args.testPathPattern) { jestCommandArgs.push('--testPathPattern="' + args.testPathPattern + '"'); } if (config.report) { const reportDirPath = _path.default.join(cwd, '.owl', 'report'); const outputFile = _path.default.join(reportDirPath, 'jest-report.json'); await _fs.promises.mkdir(reportDirPath, { recursive: true }); jestCommandArgs.push(`--json --outputFile=${outputFile}`); } const jestCommand = jestCommandArgs.join(' '); logger.print(`[OWL - CLI] ${args.update ? '(Update mode) Updating baseline images' : '(Tests mode) Will compare latest images with the baseline'}.`); logger.info(`[OWL - CLI] Will set the jest root to ${process.cwd()}.`); try { await _execa.default.commandSync(jestCommand, { stdio: 'inherit', env: { OWL_PLATFORM: args.platform, OWL_DEBUG: String(!!config.debug), OWL_UPDATE_BASELINE: String(!!args.update), OWL_IOS_SIMULATOR: config.ios?.device } }); } catch (error) { // Throw the error again, so that ci will fail when the jest tests fail throw error; } finally { if (config.report) { await (0, _report.generateReport)(logger, args.platform); } webSocketProcess.kill(); if (restoreSimulatorUI) { await restoreSimulatorUI(config, logger); } logger.print(`[OWL - CLI] Tests completed on ${args.platform}.`); if (args.update) { logger.print(`[OWL - CLI] All baseline images for ${args.platform} have been updated successfully.`); } } }; exports.runHandler = runHandler; //# sourceMappingURL=run.js.map