angularjs - 警告 [网络服务器] : 404:/views/nav/offline. html

标签 angularjs gruntjs karma-runner

任何人都知道如何解决/删除这个非常烦人的警告?

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.23 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket rrNTMtmcd322dIl7A9fa with id 95590782
WARN [web-server]: 404: /views/nav/offline.html
WARN [web-server]: 404: /views/scan/scan.qr.html  

karma.conf.js
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2014-08-26 using
// generator-karma 0.8.3

module.exports = function (config) {
    'use strict';

    config.set({
        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,

        // 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: [
            'bower_components/angular/angular.js',
            'bower_components/angular-mocks/angular-mocks.js',
            'bower_components/angular-animate/angular-animate.js',
            'bower_components/angular-cookies/angular-cookies.js',
            'bower_components/angular-resource/angular-resource.js',
            'bower_components/angular-route/angular-route.js',
            'bower_components/angular-sanitize/angular-sanitize.js',
            'bower_components/angular-touch/angular-touch.js',
            'bower_components/angular-ui-router/release/angular-ui-router.js',
            'bower_components/angular-local-storage/angular-local-storage.js',
            'bower_components/ionic/release/js/ionic.js',
            'bower_components/ionic/release/js/ionic-angular.js',
            'app/scripts/**/*.js',
            'test/spec/**/*.js'

        ],

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

        // web server port
        port: 8080,

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

        // Which plugins to enable
        plugins: [
            'karma-phantomjs-launcher',
            'karma-jasmine'
        ],

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

        colors: true,

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

        // Uncomment the following lines if you are using grunt's server to run the tests
        // proxies: {
        //   '/': 'http://localhost:9000/'
        // },
        // URL root prevent conflicts with the site root
        // urlRoot: '_karma_'
    });
};  

enter image description here

app.js
.config(function ($stateProvider, $urlRouterProvider) {

    $stateProvider

        // ACCOUNT
        .state('account', {
            abstract: true,
            url: '/account',
            templateUrl: 'index.html'
        })
        .state('account.main', {
            url: '',
            templateUrl: 'views/account/account.main.html'
        })
        .
        .
        .

        // MENU
        .state('menu', {
            abstract: true,
            url: '/menu',
            templateUrl: 'views/nav/menu.html'
        })
        .state('menu.main', {
            url: '/main',
            views: {
                'menuContent': {
                    templateUrl: 'views/dash/dash.main.html'
                }
            }
        })
        .
        .
        .

        // OFFLINE MENU
        .state('offline', {
            abstract: true,
            url: '/offline',
            templateUrl: 'views/nav/offline.html'
        })
        .state('offline.product', {
            url: '/product',
            views: {
                'menuContent': {
                    templateUrl: 'views/product/product.list.html'
                }
            }
        })
        .state('offline.qr', {
            url: '/qr',
            views: {
                'menuContent': {
                    templateUrl: 'views/scan/scan.qr.html'
                }
            }
        })
        .state('offline.cart', {
            url: '/cart',
            views: {
                'menuContent': {
                    templateUrl: 'views/cart/cart.list.html'
                }
            }
        })
    ;

    $urlRouterProvider.otherwise('/account');

})

我也试过这个相关的问题:
how to fix 404 warnings for images during karma unit testing
没有运气。

更多信息

我还尝试了以下方法:
1)添加html路径:
'app/scripts/**/*.js',
'app/views/**/*.html',
'test/spec/**/*.js'  

2)创建模式:
'app/scripts/**/*.js',            
'test/spec/**/*.js',
{pattern: 'app/views/**', watched: false, included: false, served: true}  

3)排除html文件的路径:
// list of files / patterns to exclude
exclude: ['app/views/**'],

但没有任何作用,警告仍然存在。我假设这可能是一个错误?

编辑 1

我只是按照 Chad Robinson 说的做了,下一个警告是关于失踪 index.html .
所以我所做的是这样的:
proxies: {
    '/views/': '/app/views/',
    '/index.html': '/app/index.html'
}  

但是还是有警告:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Grabhut.MobileApp\Grabhut>grunt
Running "newer:jshint" (newer) task

Running "newer:jshint:all" (newer) task
No newer files to process.

Running "newer:jshint:test" (newer) task
No newer files to process.

Running "clean:server" (clean) task
Cleaning .tmp...OK

Running "concurrent:test" (concurrent) task

Running "compass:dist" (compass) task
directory .tmp/styles
        write .tmp/styles/icomoon.css (0.007s)
        write .tmp/styles/override.css (0.055s)

Running "compass:server" (compass) task

Done, without errors.

Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/icomoon.css created.

C:\Grabhut.MobileApp\Grabhut>grunt
Running "newer:jshint" (newer) task

Running "newer:jshint:all" (newer) task
No newer files to process.

Running "newer:jshint:test" (newer) task
No newer files to process.

Running "clean:server" (clean) task
Cleaning .tmp...OK

Running "concurrent:test" (concurrent) task

Running "compass:dist" (compass) task
directory .tmp/styles
        write .tmp/styles/icomoon.css (0.007s)
        write .tmp/styles/override.css (0.054s)

Running "compass:server" (compass) task

Done, without errors.

Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/icomoon.css created.
File .tmp/styles/override.css created.

Running "connect:test" (connect) task
Started connect web server on http://localhost:9001

Running "karma:unit" (karma) task

C:\Grabhut.MobileApp\Grabhut\test\karma.conf.js:73

C:\Grabhut.MobileApp\Grabhut>grunt
Running "newer:jshint" (newer) task

Running "newer:jshint:all" (newer) task
No newer files to process.

Running "newer:jshint:test" (newer) task
No newer files to process.

Running "clean:server" (clean) task
Cleaning .tmp...OK

Running "concurrent:test" (concurrent) task

Running "compass:dist" (compass) task
directory .tmp/styles
        write .tmp/styles/icomoon.css (0.007s)
        write .tmp/styles/override.css (0.054s)

Running "compass:server" (compass) task

Done, without errors.

Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/icomoon.css created.

C:\Grabhut.MobileApp\Grabhut>grunt
Running "newer:jshint" (newer) task

Running "newer:jshint:all" (newer) task
No newer files to process.

Running "newer:jshint:test" (newer) task
No newer files to process.

Running "clean:server" (clean) task
Cleaning .tmp...OK

Running "concurrent:test" (concurrent) task

Running "compass:dist" (compass) task
directory .tmp/styles
        write .tmp/styles/icomoon.css (0.007s)
        write .tmp/styles/override.css (0.055s)

Running "compass:server" (compass) task

Done, without errors.

Running "autoprefixer:dist" (autoprefixer) task
File .tmp/styles/icomoon.css created.
File .tmp/styles/override.css created.

Running "connect:test" (connect) task
Started connect web server on http://localhost:9001

Running "karma:unit" (karma) task
INFO [karma]: Karma v0.12.23 server started at http://localhost:8080/
INFO [launcher]: Starting browser PhantomJS
INFO [PhantomJS 1.9.7 (Windows 7)]: Connected on socket PFqYQtg4gwm4psBKKJ5T with id 70053285
PhantomJS 1.9.7 (Windows 7): Executed 0 of 0 ERROR (0.001 secs / 0 secs)
Warning: Task "karma:unit" failed. Use --force to continue.

Aborted due to warnings.


Execution Time (2014-09-29 02:06:16 UTC)
concurrent:test     6.3s  ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 78%
autoprefixer:dist   97ms  ■■ 1%
connect:test       433ms  ■■■■■■■■■ 5%
karma:unit          1.2s  ■■■■■■■■■■■■■■■■■■■■■■■ 15%
Total 8.1s


C:\Grabhut.MobileApp\Grabhut>       

Karma 有什么问题?

编辑 2
Karma.conf.js

请参阅底部的 karama 配置更新:
// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2014-08-26 using
// generator-karma 0.8.3

module.exports = function (config) {
    'use strict';

    config.set({
        // enable / disable watching file and executing tests whenever any file changes
        autoWatch: true,

        // 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: [
            'bower_components/angular/angular.js',
            'bower_components/angular-mocks/angular-mocks.js',
            'bower_components/angular-animate/angular-animate.js',
            'bower_components/angular-cookies/angular-cookies.js',
            'bower_components/angular-resource/angular-resource.js',
            'bower_components/angular-route/angular-route.js',
            'bower_components/angular-sanitize/angular-sanitize.js',
            'bower_components/angular-touch/angular-touch.js',
            'bower_components/angular-ui-router/release/angular-ui-router.js',
            'bower_components/angular-local-storage/angular-local-storage.js',
            'bower_components/ionic/release/js/ionic.js',
            'bower_components/ionic/release/js/ionic-angular.js',
            'app/scripts/**/*.js',
            'test/spec/**/*.js'

        ],

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

        // web server port
        port: 8080,

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

        // Which plugins to enable
        plugins: [
            'karma-phantomjs-launcher',
            'karma-jasmine'
        ],

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

        colors: true,

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

        // Uncomment the following lines if you are using grunt's server to run the tests
        proxies: {
            '/views/': '/app/views/',
            '/index.html': '/app/index.html'
        }
        // URL root prevent conflicts with the site root
        // urlRoot: '_karma_'
    });
};

最佳答案

根据您的 Karma 配置,您似乎是从项目的根级别运行它。但是您的申请在 app/ ,并且您的模板相对于该路径...也就是说,您正在访问 /views/nav/offline.html ,不是 /app/views/nav/offline.html . Karma 不知道该怎么办。

尝试代理:

proxies =  {
  '/views/': '/app/views/'
};

这将告诉 Karma 将/views/* 请求视为针对/app/views/* 的请求。或者,您可以将 Karma 的配置向下移动一个级别,进入 app/本身。然后将包含路径和其他相关项目更改为正确的 URL,问题就会消失。 (这就是我所做的。)

关于angularjs - 警告 [网络服务器] : 404:/views/nav/offline. html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26065270/

相关文章:

AngularJS 指令 - 如何在异步数据加载后刷新模板

javascript - Grunt-Contrib-Copy,如何在不覆盖目标文件夹中现有文件/文件夹的情况下复制保持相同文件夹结构的目录内容?

javascript - 为什么 Grunt 在 node_modules 中安装这么多文件夹?

javascript - 无法让 Jasmine 测试成功调用注入(inject)的服务

javascript - 使用 Karma + ES6 + jspm 导入产量未定义

css - 单击时自定义复选框更改位置

JavaScript/AngularJS - 选中复选框时执行功能

css - Grunt 在 usemin block 中包含 bower_components

angular - 使用 jasmine 和 karma 进行测试时,声明的全局范围变量未在测试规范中定义

angularjs - Angular Material Design 中的固定表格标题