gpt4 book ai didi

javascript - Karma/Chrome 的警告和错误

转载 作者:行者123 更新时间:2023-11-29 21:55:24 27 4
gpt4 key购买 nike

现在就通过 O'Reilly 的“AngularJS Up and Running”一书学习 angularjs。学习了有关使用 Karma & Jasmine 进行单元测试的章节,但无法使其正常工作

编辑:将 logLevel 更改为 config.LOG_DEBUG 现在可以正确匹配文件模式。但最后我仍然遇到最终的“适配器”错误。

运行“karma start”命令会得到以下信息:

DEBUG [plugin]: Loading karma-* from /Work/[lab]/angularjs-up-and-running/chapter3/node_modules
DEBUG [plugin]: Loading plugin /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma-chrome-launcher.
DEBUG [plugin]: Loading plugin /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma-jasmine.
INFO [karma]: Karma v0.12.16 server started at http://localhost:8080/
INFO [launcher]: Starting browser Chrome
DEBUG [temp-dir]: Creating temp dir at /var/folders/dw/qt56vk_s4cz5h6hg8qddvmrm0000gn/T/karma-24748311
DEBUG [launcher]: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome --user-data-dir=/var/folders/dw/qt56vk_s4cz5h6hg8qddvmrm0000gn/T/karma-24748311 --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate http://localhost:8080/?id=24748311
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma-jasmine/lib/jasmine.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/angular-mocks.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma-jasmine/lib/adapter.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/angular.min.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/simpleSpec.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/controller.js" does not match any file.
WARN [watcher]: Pattern "/Work/[lab]/angularjs-up-and-running/chapter3/controllerSpec.js" does not match any file.
DEBUG [watcher]: Resolved files:

DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/angular.min.js"
DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/angular-mocks.js"
DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/controller.js"
DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/simpleSpec.js"
DEBUG [watcher]: Watching "/Work/[lab]/angularjs-up-and-running/chapter3/controllerSpec.js"
DEBUG [web-server]: serving: /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma/static/client.html
DEBUG [web-server]: serving: /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma/static/karma.js
DEBUG [web-server]: upgrade /socket.io/1/websocket/YVK_k4vczJIuLIdg5a_f
DEBUG [karma]: A browser has connected on socket YVK_k4vczJIuLIdg5a_f
INFO [Chrome 38.0.2125 (Mac OS X 10.10.0)]: Connected on socket YVK_k4vczJIuLIdg5a_f with id 24748311
DEBUG [launcher]: Chrome (id 24748311) captured in 5.575 secs
DEBUG [karma]: All browsers are ready, executing
DEBUG [web-server]: serving: /Work/[lab]/angularjs-up-and-running/chapter3/node_modules/karma/static/context.html
Chrome 38.0.2125 (Mac OS X 10.10.0) ERROR
You need to include some adapter that implements __karma__.start method!

所以首先它会警告查找文件,但是所有这些文件都存在于该位置。

我的 karma.conf.js 文件如下所示:

module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',

// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['jasmine'],

// list of files / patterns to load in the browser
files: [
'angular.min.js',
'angular-mocks.js',
'controller.js',
'simpleSpec.js',
'controllerSpec.js'
],

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

// web server port
port: 8080,

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


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

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],


// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};

karma 安装在我的项目文件夹中(karma.conf.js 所在的位置)

我真的不知道出了什么问题,也找不到联系本书作者的方法。谢谢!

最佳答案

我遇到了同样的问题,我的思想快要爆炸了。我在任何地方都找不到任何东西,所有配置都没有问题,似乎没有任何问题。你的问题是我能找到的最接近的问题。

我意识到,您的项目文件路径和我的项目文件路径都包含方括号(.../[lab]/... 在您的项目中),这可能就是原因。众所周知,特殊字符有时会很麻烦。

我从我的文件路径中删除了方括号,所有测试都运行良好。

如果您注意调试行,jasmine.js 和 adapter.js 没有解析。

希望对您有所帮助。

关于javascript - Karma/Chrome 的警告和错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26661613/

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