@fpjs-incubator/broyster
Version:
55 lines (54 loc) • 2.23 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeLocalIdentifier = exports.makeBrowserStackLocalManagerFactory = exports.BrowserStackLocalManager = void 0;
const browserStack = require("browserstack-local");
const util_1 = require("util");
class BrowserStackLocalManager {
constructor(credentials, localIdentifier) {
this.credentials = credentials;
this.localIdentifier = localIdentifier;
this.isRunning = false;
this.bsLocal = new browserStack.Local();
this.switchPromise = Promise.resolve();
}
run(logger) {
if (!this.isRunning) {
this.isRunning = true;
const bsLocalArgs = {
key: this.credentials.accessKey,
localIdentifier: this.localIdentifier,
forceLocal: true,
force: true,
};
logger.debug('Starting BrowserStackLocal');
this.switchPromise = (0, util_1.promisify)(this.bsLocal.start)
.bind(this.bsLocal)(bsLocalArgs)
.then(() => {
logger.debug('Started BrowserStackLocal');
});
}
return this.switchPromise;
}
kill(logger) {
if (this.isRunning) {
logger.debug('Stopping BrowserStackLocal');
this.isRunning = false;
this.switchPromise = (0, util_1.promisify)(this.bsLocal.stop)
.bind(this.bsLocal)()
.then(() => {
logger.debug('Stopped BrowserStackLocal');
});
}
return this.switchPromise;
}
}
exports.BrowserStackLocalManager = BrowserStackLocalManager;
function makeBrowserStackLocalManagerFactory(browserStackCredentials, localIdentifier) {
return new BrowserStackLocalManager(browserStackCredentials, localIdentifier);
}
exports.makeBrowserStackLocalManagerFactory = makeBrowserStackLocalManagerFactory;
function makeLocalIdentifier(config) {
var _a, _b;
return (_b = (_a = config.browserStack) === null || _a === void 0 ? void 0 : _a.localIdentifier) !== null && _b !== void 0 ? _b : Math.random().toString(36).slice(2);
}
exports.makeLocalIdentifier = makeLocalIdentifier;
;