orphic-cypress
Version:
Set of utilities and typescript transformers to cover storybook stories with cypress component tests
91 lines • 3.14 kB
JavaScript
/**
* @module bundlers
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.cypressWebpackConfigMdx = void 0;
const mdUse = (skipCsf) => [
{
loader: "babel-loader",
options: {
babelrc: false,
configFile: false,
presets: ["@babel/preset-env", "@babel/preset-react"],
},
},
{
loader: require.resolve("@storybook/mdx1-csf/loader"),
options: { skipCsf },
},
];
/**
* This is likely a highly specialized use case for adding mdx functionality
* and code coverage in the cypress.config.ts file. It assumes that you've
* already added ts-loader to the webpack config file proper.
*/
const cypressWebpackConfigMdx = (
/** webpack config to be updated */
config,
/** add coverage via babel-loader + istanbul */
coverage = true) => {
var _a;
const rules = ((_a = config.module) === null || _a === void 0 ? void 0 : _a.rules) || [];
let indexOfTsLoader = -1;
let tsLoaderRule = {};
let tsLoaderUse = {};
rules === null || rules === void 0 ? void 0 : rules.some((rule, i) => {
var _a;
const loaderUse = (_a = rule === null || rule === void 0 ? void 0 : rule.use) === null || _a === void 0 ? void 0 : _a.find((useItem) => useItem.loader === "ts-loader");
if (loaderUse) {
indexOfTsLoader = i;
tsLoaderRule = rule;
tsLoaderUse = loaderUse;
return true;
}
return false;
});
if (indexOfTsLoader >= 0 && (tsLoaderRule === null || tsLoaderRule === void 0 ? void 0 : tsLoaderRule.use) !== undefined) {
const tsLoaderRuleWithCoverage = coverage
? {
...tsLoaderRule,
use: [
{
loader: "babel-loader",
options: {
plugins: ["istanbul"],
babelrc: false,
configFile: false,
},
},
...tsLoaderRule.use,
],
}
: tsLoaderRule;
return {
...config,
module: {
...config.module,
rules: [
...[
...rules.slice(0, indexOfTsLoader),
tsLoaderRuleWithCoverage,
...rules.slice(indexOfTsLoader + 1),
],
// Required to support arbitary mdx imports in csf and mdx test files
{
test: /\.mdx$/,
use: [tsLoaderUse, ...mdUse(false)],
},
{
test: /\.md$/,
use: mdUse(true),
},
],
},
};
}
console.error("cypressWebpackConfigMdx found no rule that used ts-loader, config will remain unchanged");
return config;
};
exports.cypressWebpackConfigMdx = cypressWebpackConfigMdx;
//# sourceMappingURL=webpack.js.map
;