Karma Test Adapter for Visual Studio,使用时不需要工作



我在使用应用程序/单元测试的需求时遇到了一种情况,使用这里提供的方法https://karma-runner.github.io/0.8/plus/RequireJS.html。

当尝试使用Karma VS测试适配器(https://visualstudiogallery.msdn.microsoft.com/4cd59e4a-82e8-4b4e-8302-d102fc81b090)时,我遇到以下错误,在VS输出窗口

[Karma] [Discover] 1 tests discovered in 1 test containers
========== Discover test finished: 1 found (0:00:01.678) ==========
------ Run test started ------
An exception occurred while invoking executor 'executor://karmatestadapter/': One or more errors occurred.
Value cannot be null.
Parameter name: values
========== Run test finished: 0 run (0:00:00.083) ==========

和在浏览器(如chrome)

require.js:165 Uncaught Error: Module name "../App/Password/password" has not been loaded yet for context: _. Use require([])(…)makeError @ require.js:165localRequire @ require.js:1429requirejs @ require.js:1791(anonymous function) @ TestUnitTests.js:3
main.test.js:35 load complete
我main.test.js

var allTestFiles = [];
var TEST_REGEXP = /UnitTests/.*.js$/;
var pathToModule = function (path) {
var returnValue = path.replace(/^/base//, '').replace(/.js$/, '');
return returnValue;
};
Object.keys(window.karma.files).forEach(function (file) {
if (TEST_REGEXP.test(file)) {
// Normalize paths to RequireJS module names.
allTestFiles.push(pathToModule(file));
}
});
requirejs.config({
// Karma serves files from '/base'
baseUrl: '/base',
deps: allTestFiles,
paths: {
    'jquery.mockjax': 'Libraries/jquery.mockjax/jquery.mockjax'
},
shim: {
    'jquery.mockjax': {
        deps: ['jquery'],
        init: function (m) { }
    }
},
// start test run, once Require.js is done
callback: function () {
    console.log('load complete');
    window.__karma__.start();
}
});

我认为正在发生的是VS插件正在启动karma服务器,当代码(main.test.js)期望在require回调中手动执行时。

我已经交叉张贴在github项目以及https://github.com/MortenHoustonLudvigsen/KarmaTestAdapter/issues/60

我想知道是否有人遇到过这个问题,或者已经能够使类似的情况与他的插件工作。

我有一个类似的随机问题,所有的测试不会执行一次,但他们会在下一次。所以我在Visual Studio 2015扩展和更新对话框中禁用了"Karma Test Adapter"扩展。这解决了我的问题。

最新更新