UNPKG

aye-spy

Version:
158 lines (104 loc) 6.27 kB
#!/usr/bin/env node 'use strict'; var _commander = require('commander'); var _commander2 = _interopRequireDefault(_commander); var _path = require('path'); var _path2 = _interopRequireDefault(_path); var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs); var _logger = require('../logger'); var _logger2 = _interopRequireDefault(_logger); var _snapshotter = require('../snapshotter'); var _snapshotter2 = _interopRequireDefault(_snapshotter); var _getScreenshots = require('../getScreenshots'); var _getScreenshots2 = _interopRequireDefault(_getScreenshots); var _updateBaselineShots = require('../updateBaselineShots'); var _updateBaselineShots2 = _interopRequireDefault(_updateBaselineShots); var _generateReport = require('../generateReport'); var _remoteActions = require('../remoteActions'); var _comparisonActions = require('../comparisonActions'); var _scenarioFilter = require('../scenarioFilter'); var _scenarioFilter2 = _interopRequireDefault(_scenarioFilter); var _configValidator = require('../configValidator'); var _configValidator2 = _interopRequireDefault(_configValidator); var _reporter = require('../reporter'); var _reporter2 = _interopRequireDefault(_reporter); var _init = require('../init'); var _init2 = _interopRequireDefault(_init); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } (0, _logger.setupLogger)(); function handleError(err) { _logger2.default.error('run', '☠️️️️️️️ ☠️ ️️️️️️☠️️️️️️️ ☠️️️️️️️ ☠️️️️️️️ ☠️️️ ERROR FOUND ☠️️️️️️️ ☠️️️️️️️ ☠️️️️️️️ ☠️️️️️️️ ☠️️️️️️️ ☠️️️'); console.error(err); process.exitCode = 1; } _commander2.default.version('0.0.1').command('snap').option('-b, --browser [browser]', 'Select the browser to run your tests on. E.G. chrome, firefox, etc.').option('c, --config [config]', 'Path to your config').option('--run [optional]', 'Filter scenarios based on label name').option('r, --remote', 'Upload new baseline to remote storage').option('br, --branch [branch]', 'Specific branch for generating reports').action(async options => { try { const config = require(_path2.default.resolve(options.config)); // eslint-disable-line import/no-dynamic-require if (options.browser) config.browser = options.browser; options.branch ? config.branch = options.branch : config.branch = 'default'; (0, _configValidator2.default)(config, options.remote); if (options.run) config.scenarios = (0, _scenarioFilter2.default)(config, options.run); _logger2.default.info('run', 'Getting snapshots... 📸 '); await (0, _comparisonActions.createDirectories)(_fs2.default, config); await (0, _comparisonActions.createBucket)(config); await (0, _getScreenshots2.default)(_snapshotter2.default, config); console.log(''); // eslint-disable-line no-console // space for progress bar if (options.remote) await (0, _remoteActions.uploadRemoteKeys)('latest', config); _logger2.default.info('run', 'Finished getting snapshots 👀'); } catch (err) { handleError(err); } }); _commander2.default.command('update-baseline').option('-b, --browser [browser]', 'Select the browser to run your tests on. E.G. chrome, firefox, etc.').option('c, --config [config]', 'Path to your config').option('--run [optional]', 'Filter scenarios based on label name').option('r, --remote', 'Upload new baseline to remote storage').action(async options => { try { const config = require(_path2.default.resolve(options.config)); // eslint-disable-line import/no-dynamic-require if (options.browser) config.browser = options.browser; config.branch = 'default'; (0, _configValidator2.default)(config, options.remote); if (options.run) config.scenarios = (0, _scenarioFilter2.default)(config, options.run); (0, _comparisonActions.createDirectories)(_fs2.default, config); await (0, _updateBaselineShots2.default)(_fs2.default, config).catch(error => { _logger2.default.error('run', error); }); if (options.remote) await (0, _remoteActions.uploadRemoteKeys)('baseline', config); } catch (err) { handleError(err); } }); _commander2.default.command('compare').option('-b, --browser [browser]', 'Select the browser to run your tests on. E.G. chrome, firefox, etc.').option('c, --config [config]', 'Path to your config').option('--run [optional]', 'Filter scenarios based on label name').option('r, --remote', 'Upload new baseline to remote storage').option('br, --branch [branch]', 'Specific branch for generating reports').action(async options => { try { const config = require(_path2.default.resolve(options.config)); // eslint-disable-line import/no-dynamic-require const reporter = new _reporter2.default(); if (options.browser) config.browser = options.browser; options.branch ? config.branch = options.branch : config.branch = 'default'; config.remote = options.remote; (0, _configValidator2.default)(config, config.remote); if (options.run) config.scenarios = (0, _scenarioFilter2.default)(config, options.run); (0, _comparisonActions.createDirectories)(_fs2.default, config); (0, _comparisonActions.clearDirectories)(_fs2.default, config); await (0, _comparisonActions.createBucket)(config); await (0, _comparisonActions.fetchRemoteComparisonImages)(config); await (0, _comparisonActions.createComparisons)(_fs2.default, config, reporter); if (reporter.state.failed.count) { const generateReport = config.remote ? _generateReport.generateRemoteReport : _generateReport.generateLocalReport; generateReport(config); process.exitCode = 1; } else { process.exitCode = 0; } } catch (err) { handleError(err); } }); _commander2.default.command('init').action(_init2.default); _commander2.default.on('command:*', () => { _commander2.default.help(); process.exitCode = 1; }); _commander2.default.parse(process.argv); const NO_COMMAND_SPECIFIED = _commander2.default.args.length === 0; if (NO_COMMAND_SPECIFIED) { _commander2.default.help(); process.exitCode = 1; }