Reputation: 74595
I am trying to use karma-webpack to build my typescript tests for use with karma.
Recently my tests have stopped running. In the developer console, there are lines like this, corresponding to each of the files containing my tests:
Script from “http://localhost:9876/base/tests/testFile.ts?[HASH]” was blocked because of a disallowed MIME type
There are script tags like this which are generated by karma:
<script type="text/javascript" src="/base/tests/testFile.ts?[HASH]" crossorigin="anonymous"></script>
(In both cases, [HASH]
corresponds to a timestamp)
If I look inside the files related to the error messages, it looks like the compilation is successful - each file contains the JS generated by the typescript compiler, along with all of the webpack-related stuff.
My karma config looks like this:
module.exports = function (config) {
config.set({
plugins: [
require('karma-firefox-launcher'),
require('karma-webpack'),
require('karma-tap')
],
basePath: '',
frameworks: ['tap'],
files: ['tests/**/*.ts'],
preprocessors: {
'tests/**/*.ts': ['webpack']
},
webpack: {
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
"babel-loader",
"ts-loader"
]
}
]
},
resolve: {
extensions: [".webpack.js", ".web.js", ".js", ".ts", ".tsx", ".css"]
},
node: {
fs: 'empty'
}
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Firefox'],
singleRun: false
});
};
I have tried using Chromium instead of Firefox but I get a similar error, so I guess that the issue isn't browser-specific.
How can I prevent the scripts from being blocked and get my tests running again?
Package versions:
"karma": "1.4.1",
"karma-firefox-launcher": "1.0.0",
"karma-tap": "3.1.1",
"karma-webpack": "2.0.2",
"ts-loader": "2.0.0",
"typescript": "2.2.0",
"webpack": "2.2.1",
Upvotes: 1
Views: 405
Reputation: 74595
I found a couple of issues which suggested to add this to the karma config file:
mime: {
"text/x-typescript": ["ts", "tsx"]
}
Now my tests run again in Firefox and Chrome.
Upvotes: 5