在Phantom中运行业力测试工作正常,但在Chrome中没有。我在karma.config中的所有变化都是browsers: ['PhantomJS'],
到browsers: ['Chrome'],
。
如果我更改它,我会执行0次测试并Test failed
。
这是我的karma.config.js
// Karma configuration
// Generated on Mon Jan 16 2017 13:32:24 GMT+0100 (Środkowoeuropejski czas stand.)
var webpackConfig = require('./webpack.config.js');
var webpack = require('webpack');
var path = require('path');
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['mocha', 'chai', 'sinon', 'fixture'],
files: [
'spec/**/*.spec.ts',
'spec/fixtures/**/*.html',
],
exclude: [],
webpack: {
module: webpackConfig.module,
resolve: webpackConfig.resolve,
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
"window.jQuery": "jquery",
Tether: 'tether',
"window.Tether": 'tether'
})
],
},
preprocessors: {
"spec/**/*.ts": ['webpack'],
'spec/**/*.html': ['html2js'],
'spec/**/*.json': ['json_fixtures']
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
// browsers: ['Chrome'],
browsers: ['PhantomJS'],
singleRun: true,
concurrency: Infinity
})
};
并打包:
"devDependencies": {
"@types/chai": "^3.4.34",
"@types/jquery": "^2.0.34",
"@types/karma-fixture": "^0.2.2",
"@types/mocha": "^2.2.37",
"@types/raty": "^2.7.26",
"@types/sinon": "^1.16.34",
"chai": "^3.5.0",
"css-loader": "^0.26.1",
"extract-text-webpack-plugin": "^2.0.0-beta.4",
"file-loader": "^0.9.0",
"karma": "^1.4.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.0.0",
"karma-fixture": "^0.2.6",
"karma-html2js-preprocessor": "^1.1.0",
"karma-json-fixtures-preprocessor": "0.0.6",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.1",
"karma-phantomjs-launcher": "^1.0.2",
"karma-sinon": "^1.0.5",
"karma-typescript": "^2.1.6",
"karma-typescript-preprocessor2": "^1.2.1",
"karma-webpack": "^2.0.1",
"less": "^2.7.2",
"mocha": "^3.2.0",
"node-sass": "^4.0.0",
"phantomjs-prebuilt": "^2.1.14",
"sass-loader": "^4.0.2",
"sinon": "^1.17.7",
"style-loader": "^0.13.1",
"ts-loader": "^1.2.2",
"typescript": "^2.0.10",
"url-loader": "^0.5.7",
"webpack": "^2.2.0-rc.6"
}
答案 0 :(得分:4)
向karma.conf添加mime配置为我修复了类似的问题:
要在Chrome中调试,请在karma配置中定义:
autowatch:true
并定义:
singleRun: false
开始您的业力测试并在Chrome中打开一个页面到karma-server。
控制台中显示以下错误:
Refused to execute script from
'http://localhost:9876/base/src/app/search-persons/search-
persons.component.spec.ts?fe78e0d6a85c32fb65115ec3fd4e171b9f39ded7'
because its MIME type ('video/mp2t') is not executable.
为我修复此问题的mime配置:
mime: {
'text/x-typescript': ['ts']
},