Skip to content

Commit 71fc63a

Browse files
authored
fix(config): ignore entry options (#479)
karma-webpack will no longer crash when an entry option is set in webpack config, instead a warning will be thrown and the property will be ignored for the time being. Fixes N/A
1 parent 05cfa79 commit 71fc63a

File tree

3 files changed

+79
-1
lines changed

3 files changed

+79
-1
lines changed

lib/karma-webpack/controller.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class KW_Controller {
2525
console.warn(
2626
`
2727
karma-webpack does not currently support customized filenames via
28-
webpack output.filename, if this is something you need consider opening a ticket.
28+
webpack output.filename, if this is something you need consider opening an issue.
2929
defaulting ${newOptions.output.filename} to [name].js.`.trim()
3030
);
3131
delete newOptions.output.filename;

lib/karma-webpack/preprocessor.js

+10
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ function KW_Preprocessor(config, emitter) {
5959
entry: configToWebpackEntries(config),
6060
watch: config.autoWatch,
6161
});
62+
63+
if (config.webpack.entry) {
64+
console.warn(`
65+
karma-webpack does not currently support custom entries, if this is something you need,
66+
consider opening an issue.
67+
ignoring attempt to set the entry option...
68+
`);
69+
delete config.webpack.entry;
70+
}
71+
6272
controller.updateWebpackOptions(config.webpack);
6373
controller.karmaEmitter = emitter;
6474
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* eslint-disable prettier/prettier */
2+
3+
import karmaChromeLauncher from 'karma-chrome-launcher';
4+
import karmaMocha from 'karma-mocha';
5+
import karmaChai from 'karma-chai';
6+
7+
import Scenario from '../../utils/scenario';
8+
9+
process.env.CHROME_BIN = require('puppeteer').executablePath();
10+
11+
const path = require('path');
12+
13+
const karmaWebpack = require('../../../../lib/index');
14+
15+
// The karma server integration tests take longer than the jest 5 sec default,
16+
// we will give them 30 seconds to complete.
17+
const KARMA_SERVER_TIMEOUT = 30 * 1000;
18+
19+
describe('A basic karma-webpack setup', () => {
20+
let scenario;
21+
22+
const TEST_PATH = path.resolve(__dirname, './index.scenario.js');
23+
24+
const config = {
25+
frameworks: ['mocha', 'chai', 'webpack'],
26+
files: [{ pattern: TEST_PATH }],
27+
preprocessors: { [TEST_PATH]: ['webpack'] },
28+
webpack: {
29+
devtool: false,
30+
entry: './test.js',
31+
},
32+
browsers: ['ChromeHeadless'],
33+
// Explicitly turn off reporters so the simulated test results are not confused with the actual results.
34+
reporters: [],
35+
plugins: [karmaWebpack, karmaChromeLauncher, karmaMocha, karmaChai],
36+
port: 2389,
37+
logLevel: 'ERROR',
38+
singleRun: true
39+
};
40+
41+
beforeAll((done) => {
42+
Scenario.run(config)
43+
.then((res) => {
44+
scenario = res;
45+
})
46+
.catch((err) => console.error('Integration Scenario Failed: ', err))
47+
.finally(() => done());
48+
}, KARMA_SERVER_TIMEOUT);
49+
50+
// karma-webpack should ignore the entry option and throw a warning.
51+
52+
it('should have an exit code of 1 because it contains a failing test', () => {
53+
expect(scenario.exitCode).toBe(1);
54+
})
55+
56+
it('should have three successful test runs', () => {
57+
expect(scenario.success).toBe(3);
58+
});
59+
60+
it('should have one failed test run', () => {
61+
expect(scenario.failed).toBe(1);
62+
});
63+
64+
it('should complete with no errors', () => {
65+
expect(scenario.error).toBe(false);
66+
});
67+
68+
});

0 commit comments

Comments
 (0)