@wdio/crossbrowsertesting-service
Version:
A WebdriverIO service that manages local tunnel and job metadata for CrossBrowserTesting users.
52 lines (51 loc) • 1.68 kB
JavaScript
import { promisify } from 'node:util';
import { performance, PerformanceObserver } from 'node:perf_hooks';
import cbt from 'cbt_tunnels';
import logger from '@wdio/logger';
const log = logger('@wdio/crossbrowsertesting-service');
export default class CrossBrowserTestingLauncher {
_options;
_caps;
_config;
_isUsingTunnel = false;
_cbtTunnelOpts;
constructor(_options, _caps, _config) {
this._options = _options;
this._caps = _caps;
this._config = _config;
this._cbtTunnelOpts = Object.assign({
username: this._config.user,
authkey: this._config.key,
nokill: true
}, this._options.cbtTunnelOpts);
}
async onPrepare() {
if (!this._options.cbtTunnel) {
return;
}
/**
* measure TestingBot tunnel boot time
*/
const obs = new PerformanceObserver((list) => {
const entry = list.getEntries()[0];
log.info(`CrossBrowserTesting tunnel successfully started after ${entry.duration}ms`);
});
obs.observe({ entryTypes: ['measure'] });
performance.mark('tbTunnelStart');
await promisify(cbt.start)(this._cbtTunnelOpts);
this._isUsingTunnel = true;
performance.mark('tbTunnelEnd');
performance.measure('bootTime', 'tbTunnelStart', 'tbTunnelEnd');
}
onComplete() {
if (!this._isUsingTunnel) {
return;
}
return new Promise((resolve, reject) => cbt.stop((err) => {
if (err) {
return reject(err);
}
return resolve('stopped');
}));
}
}