gpt4 book ai didi

cordova - 在 Cordova 项目上运行 Karma 时执行 0 of 0 ERROR

转载 作者:行者123 更新时间:2023-12-02 02:23:56 32 4
gpt4 key购买 nike

我有一个 apache cordova 项目设置,我是第一次尝试使用 Karma。我是这样开始这个项目的:

karma start test/karma.conf.js --verbose

但我得到的是:

INFO [karma]: Karma v0.12.36 server started at http://localhost:9876/
INFO [launcher]: Starting browser Chrome
WARN [web-server]: 404: /favicon.ico
INFO [Chrome 43.0.2357 (Windows 8.1 0.0.0)]: Connected on socket 0_IDnS6qvPg4OhGd7oq4 with id 66015767
Chrome 43.0.2357 (Windows 8.1 0.0.0): Executed 0 of 0 ERROR (0.002 secs / 0 secs)

我已经根据 the docs for configuring requirejs for karma 仔细检查了我所做的事情.

karma.conf.js

module.exports = function(config) {
config.set({
basePath: '..',
frameworks: ['jasmine', 'requirejs'],
files: [
{pattern: 'www/lib/ionic/js/*.min.js', included: false},
{pattern: 'www/lib/ionic/js/angular/*.min.js', included: false},
{pattern: 'www/lib/ionic/js/angular-ui/*.min.js', included: false},
{pattern: 'www/js/**/*.js', included: false},
{pattern: 'test/specs/*Spec.js', included: false},
{pattern: 'test/test-app.js', included: true}
],
exclude: [
'www/js/app.js'
],
preprocessors: {
},
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};

test-app.js

var tests = [];
for(var file in window.__karma__.files) {
if(window.__karma__.files.hasOwnProperty(file)) {
if(/Spec\.js$/.test(file)) {
tests.push(file);
}
}
}

requirejs.config({
baseUrl: 'www',
paths: {
'angular': 'lib/ionic/js/angular'
,'angular-ui': 'lib/ionic/js/angular-ui'
},
shim: {
'angular': {exports: 'angular'},
'www/js/controllers': { deps: ['angular']}
},
deps: tests,
callback: window.__karma__.start
})

helloSpec.js

define('helloTests', ['angular'], function() {
describe('UnitTest: Hello', function() {
it('is defined', function() {
expect([1,2,3].length).toEqual(3);
});
});
});

这是生成的debug.html:

<!doctype html>
<html>
<head>
<title>Karma DEBUG RUNNER</title>
<link href="favicon.ico" rel="icon" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<script type="text/javascript">
window.__karma__ = {
info: function(info) {
if (info.dump && window.console) window.console.log(info.dump);
},
complete: function() {
if (window.console) window.console.log('Skipped ' + this.skipped + ' tests');
},
store: function() {},
skipped: 0,
result: window.console ? function(result) {
if (result.skipped) {
this.skipped++;
return;
}
var msg = result.success ? 'SUCCESS ' : 'FAILED ';
window.console.log(msg + result.suite.join(' ') + ' ' + result.description);

for (var i = 0; i < result.log.length; i++) {
window.console.error(result.log[i]);
}
} : function() {},
loaded: function() {
this.start();
}
};

window.__karma__.config = {"args":[],"useIframe":true,"captureConsole":true};


// All served files with the latest timestamps
window.__karma__.files = {
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/requirejs/require.js': 'f9d7ac1ba78c53a51fd346e3901a5f406f060f44',
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-requirejs/lib/adapter.js': 'f2d8d5976c2bbe89ebe046ac51f393f5547bbc3b',
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/jasmine-core/lib/jasmine-core/jasmine.js': '578a1e5ff14db21b04e2d6db7fd0eda37042440c',
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-jasmine/lib/boot.js': '997181251903c5bcc9659d92edc872a2a4abfa7b',
'/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-jasmine/lib/adapter.js': '0a69ad1fa10cc8be0a12b241227d3b834f82db4f',
'/base/www/lib/ionic/js/ionic-angular.min.js': '44040e6eeb17077cc79b0985118b15bf1420217d',
'/base/www/lib/ionic/js/ionic.bundle.min.js': '4a4bfece5434ae5c4cebab055aaae274f82050d9',
'/base/www/lib/ionic/js/ionic.min.js': '3e42a6e6700ba9982583b6b5da48861d202d8cfe',
'/base/www/lib/ionic/js/angular/angular-animate.min.js': '6df7f913a45a779638fd60cce18eee17268460d2',
'/base/www/lib/ionic/js/angular/angular-resource.min.js': 'eca9d7e3b12d62b9da13216f1d3b39fcd411f860',
'/base/www/lib/ionic/js/angular/angular-sanitize.min.js': 'b8cf1b04b40df803c16edda80c431ec422b63ad8',
'/base/www/lib/ionic/js/angular/angular.min.js': '09028d3553206017f5ced7249be5641baaea2020',
'/base/www/lib/ionic/js/angular-ui/angular-ui-router.min.js': '0973f9c46d3be867276e941e2e6af9c662a92333',
'/base/www/js/controllers/game.js': '4b67bf783d76ae9f67ac5d569e78319be4a85321',
'/base/www/js/controllers/setup.js': 'b466bd52a326d35700517383a6ceb5b25b3ab44c',
'/base/www/js/directives.js': 'fbc832e4aa0c55a597a57cd4474aa9435bc17bf1',
'/base/www/js/services.js': 'df5339fa9aa37d92974fe59c392b8fb53a71497d',
'/base/test/specs/helloSpec.js': 'b8f2b498922be08d7ff36bafd094132b9c75d357',
'/base/test/test-app.js': '432128c0bcd0257679fb9f4f31ff75a1060f64db'
};

</script>
<!-- Dynamically replaced with <script> tags -->
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/requirejs/require.js"></script>
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-requirejs/lib/adapter.js"></script>
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/jasmine-core/lib/jasmine-core/jasmine.js"></script>
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-jasmine/lib/boot.js"></script>
<script type="text/javascript" src="/absolutec:/Users/Mark/AppData/Roaming/npm/node_modules/karma-jasmine/lib/adapter.js"></script>
<script type="text/javascript" src="/base/test/test-app.js"></script>
<script type="text/javascript">
window.__karma__.loaded();
</script>
</body>
</html>

我假设所提供的文档列表是由 requirejs 拉入的所有内容,而脚本标签是由 karma 添加的内容。

控制台输出为:

Skipped 0 tests

所以看起来它只是没有看到测试定义。但是当我单步调试并在 requirejs.config 处设置断点时,我可以看到“tests”数组包含我的测试文件:

/base/test/specs/helloSpec.js

我还可以通过查看 Chrome 的网络面板来看到它已加载。其中列出:

debug.html
boot.js
jasmine.js
adapter.js
require.js
test-app.js
adapter.js
helloSpec.js

最佳答案

早些时候我收到了错误:

Mismatched anonymous define() module: ...

所以我改变了定义函数调用

define(['angular'], function(angular) {
....
});

define('helloTests', ['angular'], function(angular) {
....
});

这消除了错误详细信息,但没有修复任何问题。事实证明它也没有帮助,因为我再也看不到错误消息的变化。发布后,我一时兴起尝试将其删除,因为我看不到它在其他地方使用。然后错误信息变为:

Chrome 43.0.2357 (Windows 8.1 0.0.0) ERROR: 'There is no timestamp for www/lib/ionic/js/angular.js!'

WARN [web-server]: 404: /www/lib/ionic/js/angular.js
Chrome 43.0.2357 (Windows 8.1 0.0.0) ERROR
Uncaught Error: Script error for: angular
http://requirejs.org/docs/errors.html#scripterror
at c:/Users/Mark/AppData/Roaming/npm/node_modules/requirejs/require.js:141

由于我使用了 min 文件(通过在文件模式中包含“*.min.js”更容易过滤掉调试版本),我更改了 requirejs.config 路径并附加了“.min”,如下所示:

requirejs.config({
baseUrl: 'www',
paths: {
'angular': 'lib/ionic/js/angular/angular.min'
,'angular-ui': 'lib/ionic/js/angular-ui/angular-ui.min'
},
...
})

此时,错误消息仅更改为 angular.min.js 没有时间戳。此时我注意到路径是相对的并以“base/wwww”开头。就在那时,我终于注意到了我错过的一些东西in the docs 。所以我更改了 requirejs.config 中的“baseUrl”参数以添加“base/”:

requirejs.config({
baseUrl: 'base/www',
...
})

现在错误消失了,测试正在运行:

Chrome 43.0.2357 (Windows 8.1 0.0.0): Executed 1 of 1 SUCCESS (0.015 secs / 0 secs)

编辑:还有一件事,测试开始运行,但我没有注意到我仍然收到“没有时间戳”消息。将我的 requirejs.config baseUrl 参数从相对更改为绝对(在开头添加“/”)修复了它。

requirejs.config({
baseUrl: '/base/www',
...
})

现在我已经启动并运行了。

关于cordova - 在 Cordova 项目上运行 Karma 时执行 0 of 0 ERROR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30666682/

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