因果报应错误“没有时间戳记" [英] karma error 'There is no timestamp for'

查看:105
本文介绍了因果报应错误“没有时间戳记"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图使业力与requirejs一起使用.我不明白为什么在运行Karma时会遇到所有这些错误:

Trying to get karma working with requirejs. I don't understand why I am getting all of these errors when running Karma:

ERROR: 'There is no timestamp for /base/test/mainSpec.js?bust=1387739317116!'
ERROR: 'There is no timestamp for /base/app/main.js?bust=1387739317116!'
ERROR: 'There is no timestamp for /base/bower_components/jquery/jquery.js?bust=1387739317116!'

当我进入检查器中的网络"选项卡时,所有文件都没有404.

When I go to the network tab in inspector, all of the files are there with no 404s.

我有点困惑,因为业力似乎正在寻找基本"目录,但是我的项目中没有基本"目录.根据业力文档:

I'm a little confused because karma seems to be looking for a 'base' directory but there is no 'base' directory in my project. According to the karma docs:

Karma在/base目录下提供文件.因此,在服务器上 对文件的请求将在 http://localhost:9876/base/*. baseUrl的Require.js配置提供 加载相对路径的模块的起始上下文.什么时候 为Karma服务器设置此值,它首先需要 /根据.我们希望测试的baseUrl与 我们在src/main.js中拥有的基本网址,因此 来源无需更改.因此,因为我们希望我们的基本网址位于 src/,我们需要编写/base/src.

Karma serves files under the /base directory. So, on the server requests to files will be served up under http://localhost:9876/base/*. The Require.js config for baseUrl gives a starting context for modules that load with relative paths. When setting this value for the Karma server it will need to start with /base. We want the baseUrl for our tests to be the same folder as the base url we have in src/main.js, so that relative requires in the source won’t need to change. So, as we want our base url to be at src/, we need to write /base/src.

这至少可以说令人困惑.我应该在main.js文件中有一个指向'/base'的baseUrl配置吗?

This confusing to say the least. Am I supposed to have a baseUrl configuration in my main.js file that points to '/base'?

推荐答案

注意:这篇文章由Karma在2014年1月16日有效.我不确定该lib的当前状态,也许他们修复了奇怪的问题配置逻辑并添加了有意义的错误消息.如果没有,那么通过修复与Karma相关的配置问题,这篇文章可能会非常有帮助.

这类错误是由于配置错误而发生的.您应该将测试使用的所有内容添加到配置文件中的文件pattern中.

These kind of errors occur by misconfiguration. You should add everything your test uses to the file patterns in your config file.

例如:

module.exports = function (config) {
    config.set({
        basePath: './',
        frameworks: ['jasmine', 'requirejs'],
        files: [
            {pattern: 'test/bootstrap.js', included: true},
            {pattern: 'test/**/*.js', included: false},
            {pattern: 'src/**/*.js', included: false},
            {pattern: 'vendor/**/*.js', included: false}
        ],
        exclude: [

        ],
        reporters: ['progress'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Firefox'],
        captureTimeout: 6000,
        singleRun: false
    });
};

在此示例中, bootstrap.js 是HTML中Karma唯一的文件其他文件是依赖项 bootstrap.js 中的代码加载.模式顺序非常重要,可惜它与逻辑相差甚远:下一个模式不会覆盖前一个模式.因此,如果我将test/**/*.js模式作为第一个,而将test/bootstrap.js作为第二个,则它将不起作用,因为将不包含引导程序.在这些情况下,业力会向您发送"empty testsuite"消息,如果您不知道如何配置它,这将是无用的...

In this example the bootstrap.js is the only file included by Karma in the HTML, the other files are dependencies which are loaded by the code in the bootstrap.js. The pattern order is very important and sadly it is far from logical: the next pattern does not override the previous one. So if I'd give the test/**/*.js pattern as first and test/bootstrap.js as second, it would not work because the bootstrap would not be included. In these cases Karma sends you an "empty testsuite" message, which is useless if you don't know how to configure it...

如果您的测试尝试使用Karma配置文件中提供的模式未涵盖的文件,则您将收到"There is no timestamp for xy"错误消息,该消息与前面提到的"empty testsuite"非常相似.如果您不了解系统,就不会有任何线索,这意味着什么,或者为了解决该问题而必须做什么...

If your tests try to use a file which is not covered by the patterns you gave in your Karma configuration file, then you will get the "There is no timestamp for xy" error message, which is very similar to the previously mentioned "empty testsuite". If you don't know the system you won't have a clue, what it means, or what you have to do in order to fix it ...

配置对象的exclude部分用于文件,这些文件已添加到文件模式以包含在内,但是您不想在测试中包含或使用它们.例如,这些可以是用于开发和生产环境的 requirejs 配置文件,等等.

The exclude part of the configuration object is for files, which have been added to the file patterns for inclusion, but you don't want to include or use them in your tests. These can be for example requirejs configuration files for development and production environments, etc...

这篇关于因果报应错误“没有时间戳记"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆