I'm using karma-(webpack|typescript|jasmine|coverage)
which is working neatly. The only problem is, that html-loader
imports are undefined inside my tests. In other words, the following test is passed successfully:
// index.test.ts
import template from "../src/html/template.html";
describe("test", () => {
it("template", () => {
expect(template).toEqual(undefined);
});
});
Config is looking like this:
// karma.config.js
module.exports = config => config.set({
browsers: ["Chrome", "Firefox"],
files: [
{
pattern: "src/**/*.+(js|ts)",
watched: false,
},
{
pattern: "test/**/*.test.+(js|ts)",
watched: false,
},
],
frameworks: ["jasmine", "karma-typescript", "webpack"],
karmaTypescriptConfig: {
bundlerOptions: {
transforms: [require("karma-typescript-es6-transform")()],
},
compilerOptions: {
allowJs: true,
},
},
preprocessors: {
"src/**/*.+(js|ts)": ["webpack", "karma-typescript", "coverage"],
"test/**/*.test.+(js|ts)": ["webpack", "karma-typescript"],
},
reporters: ["coverage", "kjhtml", "progress"],
webpack: {
module: {
rules: [
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{
test: /\.html$/i,
use: ["html-loader"],
},
],
},
resolve: {
extensions: [".ts", "..."],
},
watch: false,
},
});
Running only webpack
with above config (+ entry
, output
etc.) is working fine, template = "<template></template>"
, which is the content of template.html
.