@o3r/testing
Version:
The module provides testing (e2e, unit test) utilities to help you build your own E2E pipeline integrating visual testing.
81 lines • 3.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitForOtterStable = waitForOtterStable;
exports.initFetchManager = initFetchManager;
exports.stopFetchManager = stopFetchManager;
var tslib_1 = require("tslib");
var fs = require("node:fs");
var path = require("node:path");
var protractor_1 = require("protractor");
/**
* This function waits for all fetchs calls to be resolved and the page to be stable to resolve the promise.
* It permits to easily run synchronous e2e tests on a flow that uses fetchs calls with protractor.
* This is very useful in the case of Otter calls to backend because protractor synchronization manager do not care
* about fetchs calls.
*
* This function needs the FetchManager to have been initialized and injected in the browser at the beginning of the
* flow with `initFetchManager()`
*
* You can ignore the waiting of fetchs by setting `browser.ignoreSynchronization` to `true`
* @deprecated Will be removed in v13, please use Playwright instead
*/
function waitForOtterStable() {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, protractor_1.browser.waitForAngular()];
case 1:
_a.sent();
if (!!protractor_1.browser.ignoreSynchronization) return [3 /*break*/, 4];
return [4 /*yield*/, protractor_1.browser.executeAsyncScript('window.fetchManager.getInstance().waitForFetchs(arguments[arguments.length - 1]);')];
case 2:
_a.sent();
return [4 /*yield*/, protractor_1.browser.waitForAngular()];
case 3:
_a.sent();
_a.label = 4;
case 4: return [2 /*return*/];
}
});
});
}
/**
* This function initiliaze the FetchManager. Set `window.fetch` variable with a custom behaviour in order to count the
* fetch calls.
* @deprecated Will be removed in v13, please use Playwright instead
*/
function initFetchManager() {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var fetchManager;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
fetchManager = fs.readFileSync(path.resolve(process.cwd(), 'node_modules', '@o3r', 'testing', 'tools', 'protractor', 'fetch-manager', '_fetch-manager.js'), { encoding: 'utf8' });
return [4 /*yield*/, protractor_1.browser.executeScript(fetchManager)];
case 1:
_a.sent();
return [4 /*yield*/, protractor_1.browser.executeScript('window.fetchManager.getInstance().init();')];
case 2:
_a.sent();
return [2 /*return*/];
}
});
});
}
/**
* This function stops the FetchManager. Reset `window.fetch` variable with its native behaviour.
* @deprecated Will be removed in v13, please use Playwright instead
*/
function stopFetchManager() {
return tslib_1.__awaiter(this, void 0, void 0, function () {
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, protractor_1.browser.executeScript('window.fetchManager.getInstance().stop();')];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
}
//# sourceMappingURL=utils.js.map