Skip to content

Commit

Permalink
chore: fix support for webpack v5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Clark committed Dec 6, 2020
1 parent eec6dfc commit 8d7366f
Show file tree
Hide file tree
Showing 4 changed files with 586 additions and 1,268 deletions.
41 changes: 29 additions & 12 deletions README.md
Expand Up @@ -26,6 +26,8 @@ npm i -D karma-webpack

<h2 align="center">Usage</h2>

**Note: it's very important that you include `webpack` as a framework, otherwise your tests will not run.**

**karma.conf.js**
```js
module.exports = (config) => {
Expand All @@ -34,6 +36,11 @@ module.exports = (config) => {

// add webpack to your list of frameworks
frameworks: ['mocha', 'webpack'],

plugins: [
'karma-webpack',
'karma-mocha',
],

files: [
// all files ending in ".test.js"
Expand All @@ -43,8 +50,7 @@ module.exports = (config) => {

preprocessors: {
// add webpack as preprocessor
'test/*_test.js': [ 'webpack' ],
'test/**/*_test.js': [ 'webpack' ]
'test/**/*.test.js': [ 'webpack' ]
},

webpack: {
Expand Down Expand Up @@ -150,19 +156,30 @@ webpack: {
}
```

<h2 align="center">Options</h2>

This is the full list of options you can specify in your `karma.conf.js`

|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|[**`webpack`**](#webpack)|`{Object}`|`{}`|Pass `webpack.config.js` to `karma`|
<h2 align="center">Maintainers</h2>

### `webpack`
<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars0.githubusercontent.com/u/7922109?v=4&s=150">
<br>
<a href="https://github.com/ryanclark">Ryan Clark</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/2045543?v=4&s=150">
<br>
<a href="https://github.com/AprilArcus">April Arcus</a>
</td>
</tr>
<tbody>
</table>

`webpack` configuration (`webpack.config.js`).
<h2 align="center">Previous Maintainers</h2>

<h2 align="center">Maintainers</h2>
Previous maintainers of the `karma-webpack` plugin that have done such amazing work to get it to where it is today.

<table>
<tbody>
Expand Down
9 changes: 6 additions & 3 deletions lib/karma-webpack.js
Expand Up @@ -113,10 +113,13 @@ function preprocessorFactory(config, emitter) {
return async function processFile(content, file, done) {
await controller.bundle();

file.path = normalize(transformPath(file.path)); // eslint-disable-line no-param-reassign
file.path = normalize(file.path); // eslint-disable-line no-param-reassign

const transformedFilePath = transformPath(getPathKey(file.path, true));
const bundleContent = controller.bundlesContent[transformedFilePath];

file.path = transformedFilePath;

const bundleContent =
controller.bundlesContent[getPathKey(file.path, true)];
done(null, bundleContent);
};
}
Expand Down

0 comments on commit 8d7366f

Please sign in to comment.