UNPKG

tm-perfomance-check

Version:

Check page perfomance metrics on test machine

125 lines (124 loc) 3.99 kB
#! /usr/bin/env node 'use strict'; require('babel-polyfill'); var _isomorphicFetch = require('isomorphic-fetch'), _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch), _commandLineArgs = require('command-line-args'), _commandLineArgs2 = _interopRequireDefault(_commandLineArgs); function _interopRequireDefault(a) { return a && a.__esModule ? a : { default: a }; } function _asyncToGenerator(a) { return function() { var b = a.apply(this, arguments); return new Promise(function(a, c) { function d(e, f) { try { var g = b[e](f), h = g.value; } catch (a) { return void c(a); } return g.done ? void a(h) : Promise.resolve(h).then( function(a) { d('next', a); }, function(a) { d('throw', a); }, ); } return d('next'); }); }; } var Spinner = require('cli-spinner').Spinner, timeout = 6e5, config = require('../config/config.json'), optionDefinitions = [ { name: 'verbose', alias: 'v', type: String }, { name: 'fps', type: String }, { name: 'dom', type: String }, { name: 'load', type: String }, { name: 'error', type: String }, { name: 'url', alias: 'u', type: String }, { name: 'serviceURL', alias: 's', type: String, defaultValue: 'http://192.168.44.253:3001/' }, ], options = (0, _commandLineArgs2.default)(optionDefinitions); options.serviceURL !== void 0 && (config.serviceURL = options.serviceURL), options.url === void 0 && (void 0, process.exit(5)); var spinner = new Spinner('Testing url performance: %s'); spinner.setSpinnerString('|/-\\'), spinner.start(); function logFPS(a) { Math.ceil; a.framesPerSec_raf < config.framesPerSec_raf ? (void 0, options.error !== void 0 && process.exit(2)) : void 0; } function logLoad(a) { a.loadTime > config.loadTime ? (void 0, options.error !== void 0 && process.exit(3)) : void 0; } function logDOM(a) { a.domReadyTime > config.domReadyTime ? (void 0, options.error !== void 0 && process.exit(4)) : void 0; } _asyncToGenerator( regeneratorRuntime.mark(function a() { var b, c; return regeneratorRuntime.wrap( function(a) { for (;;) switch ((a.prev = a.next)) { case 0: return ( (b = void 0), (c = void 0), (a.prev = 2), (a.next = 5), (0, _isomorphicFetch2.default)(config.serviceURL + '?url=' + options.url, { method: 'GET', headers: { ciphers: 'DES-CBC3-SHA', 'User-Agent': 'Chrome/59.0.3071.115', Connection: 'keep-alive', }, timeout: timeout, }) ); case 5: (b = a.sent), (a.next = 12); break; case 8: (a.prev = 8), (a.t0 = a['catch'](2)), process.exit(1); case 12: return ( b.ok || process.exit(1), spinner.stop(), (a.prev = 15), (a.next = 18), b.json() ); case 18: (c = a.sent), (a.next = 25); break; case 21: (a.prev = 21), (a.t1 = a['catch'](15)), process.exit(1); case 25: void 0 === c.framesPerSec_raf && process.exit(1), void 0 !== options.verbose && process.exit(0), void 0 === options.fps ? void 0 === options.load ? void 0 === options.dom ? (logFPS(c), logLoad(c), logDOM(c)) : logDOM(c) : logLoad(c) : logFPS(c), process.exit(0); case 29: case 'end': return a.stop(); } }, a, void 0, [[2, 8], [15, 21]], ); }), )();