Skip to content

Commit 8d7366f

Browse files
author
Ryan Clark
committed
chore: fix support for webpack v5
1 parent eec6dfc commit 8d7366f

File tree

4 files changed

+586
-1268
lines changed

4 files changed

+586
-1268
lines changed

README.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ npm i -D karma-webpack
2626

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

29+
**Note: it's very important that you include `webpack` as a framework, otherwise your tests will not run.**
30+
2931
**karma.conf.js**
3032
```js
3133
module.exports = (config) => {
@@ -34,6 +36,11 @@ module.exports = (config) => {
3436

3537
// add webpack to your list of frameworks
3638
frameworks: ['mocha', 'webpack'],
39+
40+
plugins: [
41+
'karma-webpack',
42+
'karma-mocha',
43+
],
3744

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

4451
preprocessors: {
4552
// add webpack as preprocessor
46-
'test/*_test.js': [ 'webpack' ],
47-
'test/**/*_test.js': [ 'webpack' ]
53+
'test/**/*.test.js': [ 'webpack' ]
4854
},
4955

5056
webpack: {
@@ -150,19 +156,30 @@ webpack: {
150156
}
151157
```
152158

153-
<h2 align="center">Options</h2>
154-
155-
This is the full list of options you can specify in your `karma.conf.js`
156-
157-
|Name|Type|Default|Description|
158-
|:--:|:--:|:-----:|:----------|
159-
|[**`webpack`**](#webpack)|`{Object}`|`{}`|Pass `webpack.config.js` to `karma`|
159+
<h2 align="center">Maintainers</h2>
160160

161-
### `webpack`
161+
<table>
162+
<tbody>
163+
<tr>
164+
<td align="center">
165+
<img width="150" height="150"
166+
src="https://avatars0.githubusercontent.com/u/7922109?v=4&s=150">
167+
<br>
168+
<a href="https://github.com/ryanclark">Ryan Clark</a>
169+
</td>
170+
<td align="center">
171+
<img width="150" height="150"
172+
src="https://avatars3.githubusercontent.com/u/2045543?v=4&s=150">
173+
<br>
174+
<a href="https://github.com/AprilArcus">April Arcus</a>
175+
</td>
176+
</tr>
177+
<tbody>
178+
</table>
162179

163-
`webpack` configuration (`webpack.config.js`).
180+
<h2 align="center">Previous Maintainers</h2>
164181

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

167184
<table>
168185
<tbody>

lib/karma-webpack.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,13 @@ function preprocessorFactory(config, emitter) {
113113
return async function processFile(content, file, done) {
114114
await controller.bundle();
115115

116-
file.path = normalize(transformPath(file.path)); // eslint-disable-line no-param-reassign
116+
file.path = normalize(file.path); // eslint-disable-line no-param-reassign
117+
118+
const transformedFilePath = transformPath(getPathKey(file.path, true));
119+
const bundleContent = controller.bundlesContent[transformedFilePath];
120+
121+
file.path = transformedFilePath;
117122

118-
const bundleContent =
119-
controller.bundlesContent[getPathKey(file.path, true)];
120123
done(null, bundleContent);
121124
};
122125
}

0 commit comments

Comments
 (0)