@azure/microsoft-playwright-testing
Version:
Package to integrate your Playwright test suite with Microsoft Playwright Testing service
51 lines • 2.44 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const constants_1 = require("../common/constants");
const logger_1 = require("../common/logger");
const entraIdAccessToken_1 = require("../common/entraIdAccessToken");
class PlaywrightServiceEntra {
set entraIdAccessToken(credential) {
this._entraIdAccessToken = new entraIdAccessToken_1.EntraIdAccessToken(credential);
}
constructor() {
this.globalSetup = async () => {
logger_1.coreLogger.info("Entra id access token setup start");
await this._entraIdAccessToken.fetchEntraIdAccessToken();
this.entraIdGlobalSetupRotationHandler();
};
this.globalTeardown = () => {
logger_1.coreLogger.info("Entra id access token teardown start");
if (this._entraIdAccessTokenRotationInterval) {
clearInterval(this._entraIdAccessTokenRotationInterval);
logger_1.coreLogger.info("Entra id access token roation interval cleared");
}
};
this.entraIdGlobalSetupRotationHandler = () => {
this._entraIdAccessTokenRotationInterval = setInterval(this.entraIdAccessTokenRotation, constants_1.EntraIdAccessTokenConstants.ROTATION_INTERVAL_PERIOD_IN_MINUTES * 60 * 1000);
logger_1.coreLogger.info("Entra id access token rotation handler setup done");
};
this.entraIdAccessTokenRotation = async () => {
logger_1.coreLogger.info("Entra id access token rotation handler");
try {
if (this._entraIdAccessToken.doesEntraIdAccessTokenNeedRotation()) {
await this._entraIdAccessToken.fetchEntraIdAccessToken();
}
}
catch (err) {
logger_1.coreLogger.error(err); // log error and continue if it's an intermittent issue (optimistic approach)
}
};
this._entraIdAccessToken = new entraIdAccessToken_1.EntraIdAccessToken();
}
}
PlaywrightServiceEntra.getInstance = () => {
if (!PlaywrightServiceEntra.instance) {
PlaywrightServiceEntra.instance = new PlaywrightServiceEntra();
}
return PlaywrightServiceEntra.instance;
};
const instance = PlaywrightServiceEntra.getInstance();
exports.default = instance;
//# sourceMappingURL=playwrightServiceEntra.js.map