Skip to content

Commit

Permalink
STCLI-231: Adjust finding in webpack config in order to fix coverage (#…
Browse files Browse the repository at this point in the history
…326)

* STCLI-231: Adjust finding  in webpack config in order to fix coverage

* Move set

* Cleanup
  • Loading branch information
mkuklis authored May 25, 2023
1 parent 5e08fe1 commit 470fbd4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
15 changes: 3 additions & 12 deletions lib/test/webpack-config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const path = require('path');
const { set } = require('lodash');

const { enableCoverage } = require('../webpack-common');

// TODO: Move this to stripes-core and expose as part of the Stripes Node API
// Generates a webpack config for Stripes independent of build or serve
Expand Down Expand Up @@ -31,17 +32,7 @@ module.exports = function getStripesWebpackConfig(stripeCore, stripesConfig, opt

// Inject babel-plugin-istanbul when coverage is enabled
if (options.coverage) {
const babelLoaderConfigIndex = config.module.rules.findIndex((rule) => {
return rule?.oneOf?.[1]?.use?.[0].loader === 'babel-loader';
});

if (!config.module.rules[babelLoaderConfigIndex]?.oneOf?.[1].use[0].options?.plugins) {
set(config.module.rules[babelLoaderConfigIndex], 'oneOf[1].use[0].options.plugins', []);
}

config.module.rules[babelLoaderConfigIndex].oneOf[1].use[0].options.plugins.push(
require.resolve('babel-plugin-istanbul')
);
enableCoverage(config);
}

// Remove HMR plugin during testing
Expand Down
12 changes: 8 additions & 4 deletions lib/webpack-common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const fs = require('fs');
const path = require('path');
const { set } = require('lodash');
const webpack = require('webpack');
const logger = require('./cli/logger')('webpack');

Expand Down Expand Up @@ -83,14 +84,17 @@ function limitChunks(maxChunks) {

function enableCoverage(config) {
const babelLoaderConfigIndex = config.module.rules.findIndex((rule) => {
return rule.loader === 'babel-loader';
return rule?.oneOf?.[1]?.use?.[0].loader === 'babel-loader';
});
if (!config.module.rules[babelLoaderConfigIndex].options.plugins) {
config.module.rules[babelLoaderConfigIndex].options.plugins = [];

if (!config.module.rules[babelLoaderConfigIndex]?.oneOf?.[1].use[0].options?.plugins) {
set(config.module.rules[babelLoaderConfigIndex], 'oneOf[1].use[0].options.plugins', []);
}
config.module.rules[babelLoaderConfigIndex].options.plugins.push(

config.module.rules[babelLoaderConfigIndex].oneOf[1].use[0].options.plugins.push(
require.resolve('babel-plugin-istanbul')
);

return config;
}

Expand Down

0 comments on commit 470fbd4

Please sign in to comment.