Skip to content

Commit 8ee2bed

Browse files
committed
feat: add webpack support for karma.conf.js
1 parent f4605e9 commit 8ee2bed

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/services/test-execution-service.ts

+2
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ export class TestExecutionService implements ITestExecutionService {
208208
}
209209

210210
karmaConfig.projectDir = projectData.projectDir;
211+
karmaConfig.bundle = this.$options.bundle;
212+
karmaConfig.platform = platform.toLowerCase();
211213
this.$logger.debug(JSON.stringify(karmaConfig, null, 4));
212214

213215
return karmaConfig;

resources/test/karma.conf.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = function(config) {
2-
config.set({
2+
const options = {
33

44
// base path that will be used to resolve all patterns (eg. files, exclude)
55
basePath: '',
@@ -73,5 +73,33 @@ module.exports = function(config) {
7373
// Continuous Integration mode
7474
// if true, Karma captures browsers, runs the tests and exits
7575
singleRun: false
76-
})
76+
};
77+
78+
setWebpackPreprocessor(config, options);
79+
setWebpack(config, options);
80+
81+
config.set(options);
82+
}
83+
84+
function setWebpackPreprocessor(config, options) {
85+
if (config && config.bundle) {
86+
if (!options.preprocessors) {
87+
options.preprocessors = {};
88+
}
89+
90+
options.files.forEach(file => {
91+
if (!options.preprocessors[file]) {
92+
options.preprocessors[file] = [];
93+
}
94+
options.preprocessors[file].push('webpack');
95+
});
96+
}
97+
}
98+
99+
function setWebpack(config, options) {
100+
if (config && config.bundle) {
101+
const env = {};
102+
env[config.platform] = true;
103+
options.webpack = require('./webpack.config')(env);
104+
}
77105
}

0 commit comments

Comments
 (0)