gpt4 book ai didi

npm - WebStorm:Karma 服务器未启动,类型错误:未定义不是 server.start() 上的函数;

转载 作者:行者123 更新时间:2023-12-04 16:59:34 24 4
gpt4 key购买 nike

我有最新版本的 WebStorm (10.0.4)。今天我想在我的项目中包含 karma,所以我安装了 Python 并运行:

npm install -g karma
npm install karma
npm install karma-jasmine
npm install karma-chrome-launcher
npm install karma-phantomjs-launcher

我尝试了两个不同的配置文件,一个用于我的项目,一个用于 super 配置,但都抛出相同的错误。这是基本配置:
// Karma configuration
// Generated on Fri Jul 17 2015 14:05:46 GMT+0200 (Mitteleuropäische Sommerzeit)

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',


// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],


// list of files / patterns to load in the browser
files: [
'test/**/*Spec.js'
],


// list of files to exclude
exclude: [
],


// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
},


// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],


// web server port
port: 9876,


// enable / disable colors in the output (reporters and logs)
colors: true,


// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,


// enable / disable watching file and executing tests whenever any file changes
autoWatch: true,


// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['Chrome'],


// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
})
}

然后我创建了一个新的“Karma”运行配置,但是当我点击运行时,它说:
"C:\Program Files\nodejs\node.exe" "C:\Program Files (x86)\JetBrains\WebStorm 10.0.4\plugins\js-karma\js_reporter\karma-intellij\lib\intellijServer.js" --karmaPackageDir=C:\workspace\full_ui\node_modules\karma --configFile=C:\workspace\full_ui\tests\karma.conf_messages.js --browsers=Chrome
C:\Program Files (x86)\JetBrains\WebStorm 10.0.4\plugins\js-karma\js_reporter\karma-intellij\lib\intellijServer.js:10
server.start(cliOptions);
^
TypeError: undefined is not a function
at Object.<anonymous> (C:\Program Files (x86)\JetBrains\WebStorm 10.0.4\plugins\js-karma\js_reporter\karma-intellij\lib\intellijServer.js:10:8)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3

Process finished with exit code 1

我真的不知道是什么导致了这个问题。我错过了什么要安装的东西吗?我以前从未使用过 karma,所以我可能在某处有一些基本错误,但我不知道是什么。

最佳答案

我认为这可能是由 9 天前对 karma lib 的最新更新引起的

https://github.com/karma-runner/karma/commits/master/lib/server.js

可能是 intellijServer.js 现在已经过时,需要更改。我通过更新 intellijServer.js(直到 intellij 修复它)来让它工作:

  var cli = require('./intellijCli.js')
, Server = cli.requireKarmaModule('lib/server.js')
, cliOptions = { configFile: require.resolve('./intellij.conf.js') };

var browsers = cli.getBrowsers();
if (browsers != null) {
cliOptions.browsers = browsers;
}

var server=new Server(cliOptions);
server.start();

// Prevent karma server from being an orphan process.
// For example, if WebStorm is killed using SIGKILL, karma server will still be alive.
// When WebStorm is terminated, karma server's standard input is closed automatically.
process.stdin.resume();
process.stdin.on('close', function () {
// terminating orphan process
process.exit(123);
});

一旦我让服务器位工作,我遇到了另一个问题 没有“框架: Jasmine ”的提供者! (但是,这似乎是影响我的一个单独的无关问题,因为我没有完全设置 karma)。
这是通过以下方式解决的:
npm install karma-jasmine --save-dev
npm install karma-chrome-launcher --save-dev

其次是
npm install

关于npm - WebStorm:Karma 服务器未启动,类型错误:未定义不是 server.start() 上的函数;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31475225/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com