@testplane/storybook
Version:
Testplane plugin that enables runtime screenshot storybook tests autogeneration
76 lines • 3.01 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.disableTestplaneIsolation = exports.patchTestplaneBaseUrl = exports.patchTestplaneSets = exports.patchSystemExtensions = exports.getStorybookPathEndingWith = void 0;
const lodash_1 = __importDefault(require("lodash"));
const constants_1 = require("./constants");
const trimUrlEnding = (urlObj, ending) => {
const pathName = lodash_1.default.trimEnd(urlObj.pathname, "/");
if (pathName.endsWith(ending)) {
urlObj.pathname = pathName.slice(0, -ending.length);
}
};
const getFilteredBrowserIds = (config, browserIds) => {
const allBrowserIds = config.getBrowserIds();
if (lodash_1.default.isEmpty(browserIds)) {
return allBrowserIds;
}
return allBrowserIds.filter(browserId => {
return browserIds.some(id => {
if (lodash_1.default.isString(id)) {
return id === browserId;
}
return id.test(browserId);
});
});
};
const getStorybookPathEndingWith = (url, pathEnding) => {
const urlObj = new URL(url);
constants_1.STORYBOOK_KNOWN_PATH_ENDINGS.forEach(ending => trimUrlEnding(urlObj, ending));
urlObj.pathname = lodash_1.default.trimEnd(urlObj.pathname, "/") + `/${pathEnding}`;
return urlObj.toString();
};
exports.getStorybookPathEndingWith = getStorybookPathEndingWith;
const patchSystemExtensions = (config) => {
if (!config.system.fileExtensions.includes(".js")) {
config.system.fileExtensions.push(".js");
}
};
exports.patchSystemExtensions = patchSystemExtensions;
const patchTestplaneSets = (config, { browserIds, files, unsafeAllowOtherTests = false, }) => {
const browsers = getFilteredBrowserIds(config, browserIds);
const autoStorybookSet = { browsers, files };
if (unsafeAllowOtherTests) {
config.sets = config.sets || {};
config.sets[constants_1.STORYBOOK_SET_NAME] = autoStorybookSet;
}
else {
config.sets = {
[constants_1.STORYBOOK_SET_NAME]: {
browsers,
files,
},
};
}
};
exports.patchTestplaneSets = patchTestplaneSets;
const patchTestplaneBaseUrl = (config, baseUrl) => {
config.baseUrl = baseUrl;
config.getBrowserIds().forEach(browserId => {
const browserConfig = config.forBrowser(browserId);
browserConfig.baseUrl = baseUrl;
});
};
exports.patchTestplaneBaseUrl = patchTestplaneBaseUrl;
const disableTestplaneIsolation = (config, browserIds) => {
const browsers = getFilteredBrowserIds(config, browserIds);
config.isolation = false;
browsers.forEach(browserId => {
const browserConfig = config.forBrowser(browserId);
browserConfig.isolation = false;
});
};
exports.disableTestplaneIsolation = disableTestplaneIsolation;
//# sourceMappingURL=utils.js.map