Skip to content

Commit 1598fa6

Browse files
authored
fix(config): force default output.filename (#477)
this prevents karma-webpack from failing and also prints out a useful error message explaining why the webpack output.filename is ignored. Fixes N/A
1 parent d603679 commit 1598fa6

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

lib/karma-webpack/controller.js

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class KW_Controller {
2121
}
2222

2323
updateWebpackOptions(newOptions) {
24+
if (newOptions.output && newOptions.output.filename) {
25+
console.warn(
26+
`
27+
karma-webpack does not currently support customized filenames via
28+
webpack output.filename, if this is something you need consider opening a ticket.
29+
defaulting ${newOptions.output.filename} to file[id].`.trim()
30+
);
31+
delete newOptions.output.filename;
32+
}
33+
2434
this.webpackOptions = merge(this.webpackOptions, newOptions);
2535
}
2636

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
const fs = require('fs');
10+
11+
process.env.CHROME_BIN = require('puppeteer').executablePath();
12+
13+
const path = require('path');
14+
15+
const karmaWebpack = require('../../../../lib/index');
16+
17+
// The karma server integration tests take longer than the jest 5 sec default,
18+
// we will give them 30 seconds to complete.
19+
const KARMA_SERVER_TIMEOUT = 30 * 1000;
20+
const KARMA_CUSTOM_PATH = '/tmp/karma_webpack__custom_file_path';
21+
22+
describe('A basic karma-webpack setup', () => {
23+
let scenario;
24+
25+
const TEST_PATH = path.resolve(__dirname, './index.scenario.js');
26+
27+
const config = {
28+
frameworks: ['mocha', 'chai', 'webpack'],
29+
files: [{ pattern: TEST_PATH }],
30+
preprocessors: { [TEST_PATH]: ['webpack'] },
31+
webpack: {
32+
devtool: false,
33+
output: {
34+
path: KARMA_CUSTOM_PATH,
35+
filename: 'hi_[id].js',
36+
}
37+
},
38+
browsers: ['ChromeHeadless'],
39+
// Explicitly turn off reporters so the simulated test results are not confused with the actual results.
40+
reporters: [],
41+
plugins: [karmaWebpack, karmaChromeLauncher, karmaMocha, karmaChai],
42+
port: 2389,
43+
logLevel: 'ERROR',
44+
singleRun: true
45+
};
46+
47+
beforeAll((done) => {
48+
Scenario.run(config)
49+
.then((res) => {
50+
scenario = res;
51+
})
52+
.catch((err) => console.error('Integration Scenario Failed: ', err))
53+
.finally(() => done());
54+
}, KARMA_SERVER_TIMEOUT);
55+
56+
it('should have an exit code of 1 because it contains a failing test', () => {
57+
expect(scenario.exitCode).toBe(1);
58+
})
59+
60+
it('should have three successful test runs', () => {
61+
expect(scenario.success).toBe(3);
62+
});
63+
64+
it('should have one failed test run', () => {
65+
expect(scenario.failed).toBe(1);
66+
});
67+
68+
it('should complete with no errors', () => {
69+
expect(scenario.error).toBe(false);
70+
});
71+
72+
it('should create the custom karma_webpack__custom_file_path directory', () => {
73+
expect(fs.existsSync(KARMA_CUSTOM_PATH)).toBe(true);
74+
})
75+
76+
it('should contain the generated commons file', () => {
77+
expect(fs.existsSync(`${KARMA_CUSTOM_PATH}/commons.js`)).toBe(true)
78+
})
79+
80+
it('should contain the generated runtime file', () => {
81+
expect(fs.existsSync(`${KARMA_CUSTOM_PATH}/runtime.js`)).toBe(true)
82+
})
83+
84+
});

0 commit comments

Comments
 (0)