javascript - Coverage.json 不是用 Jasmine RequireJS 和 Istanbul 生成的

标签 javascript gruntjs requirejs jasmine istanbul

我尝试使用 grunt-template-jasmine-istanbul 从 grunt 生成覆盖率报告。规范已正确执行,但未生成覆盖率报告。

下面是我在配置文件中的代码:

var name = 'SuperAccounts';
//*** Configure grunt
console.log(jasmine);
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),
    jshint: jshint,
    durandal: durandal,
    jasmine: {
        coverage : {

            src: [
               '../../../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
            ],
            options: {
                template: require('grunt-template-jasmine-istanbul'),
                specs: [
                        //'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
                        //'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
                        '../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
                ],
                helpers: [
                        'Assets/scripts/ato/helperscript.js'

                        //'Legacy/Shared/common/constants.js'
                ],
                vendor: jasmine.SuperAccounts,
                templateOptions: {
                    //files: 'src/assets/js/app/**/*.js',
                    coverage: 'bin/coverage/coverage.json',
                    report: 'bin/coverage',
                    thresholds: {
                        lines: 75,
                        statements: 75,
                        branches: 75,
                        functions: 90
                    },
                    replace: false,
                    template: require('grunt-template-jasmine-requirejs'),
                    templateOptions: {
                        requireConfig: {
                            baseUrl: 'SinglePageApplications/' + name,
                            //waitSeconds: 30,
                            paths: mixIn({
                                'knockout-editables': '../../Assets/scripts/vendor/ko.editables-0.9.0',
                                'knockout-validation': '../../Assets/scripts/vendor/knockout.validation-1.0.2',
                                'bignumber': '../../Assets/scripts/vendor/bignumber-1.4.1',
                                'testutils': '../../../Test.UnitTest.JS/Utils',
                                'shared': '../../Legacy/Shared',
                                'testdata': '../../../Test.UnitTest.JS/UnitTests/' + name + '/testdata'
                            }, addConfigurationPaths(config.SuperAccounts))

                        }
                    },
                    helpers: [
                        'Assets/scripts/ato/helperscript.js'

                        //'Legacy/Shared/common/constants.js'
                    ],
                    specs: [
                        //'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
                        //'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
                        '../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
                    ],
                    //junit: {
                    //    path: 'build/junit/' + name + '/'
                    //},
                    timeout: 100000,
                    vendor: jasmine.SuperAccounts
                }
            }
            ,
            //specs : 'src/test/js/unit-headless.html',

            phantomjs: {
                'ignore-ssl-errors': true
            },


        }

    },
    uglify: uglify,
    cssmin: cssmin,
    autoprefixer: {
        options: {
            diff: true,
            map: true,
            browsers: ['last 2 versions', 'ie 8', 'ie 9']
        },
        multiple_files: {
            expand: true,
            flatten: true,
            src: 'ui/styles/ato/**/*.css',
            dest: 'ui/styles/ato/autoprefix'
        },
    },
    compress: {
        main: {
            options: {
                archive: staticsZip,
                level: 9
            },
            files: [
                { src: ['ui/**'], dest: '/', filter: 'isFile' }
            ]
    }
    }
});

//*** Loading plugins
grunt.loadNpmTasks('grunt-autoprefixer');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-durandal');
grunt.loadNpmTasks('grunt-contrib-jasmine');

最佳答案

我意识到问题出在没有正确引用 Src 文件。像下面这样更改配置解决了问题:

jasmine: {
    coverage : {

        src: [
           'SinglePageApplications/' + name + '/**/*.js'
        ],
        options: {
            template: require('grunt-template-jasmine-istanbul'),
            specs: [
                    //'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
                    //'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
                    '../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
            ],
            helpers: [
                    'Assets/scripts/ato/helperscript.js'

                    //'Legacy/Shared/common/constants.js'
            ],
            vendor: jasmine.SuperAccounts,
            templateOptions: {
                //files: 'src/assets/js/app/**/*.js',
                coverage: 'bin/coverage/coverage.json',
                report: 'bin/coverage',
                thresholds: {
                    lines: 75,
                    statements: 75,
                    branches: 75,
                    functions: 90
                },
                replace: false,
                template: require('grunt-template-jasmine-requirejs'),
                templateOptions: {
                    requireConfig: {
                        baseUrl: 'SinglePageApplications/' + name,
                        //waitSeconds: 30,
                        paths: mixIn({
                            'knockout-editables': '../../Assets/scripts/vendor/ko.editables-0.9.0',
                            'knockout-validation': '../../Assets/scripts/vendor/knockout.validation-1.0.2',
                            'bignumber': '../../Assets/scripts/vendor/bignumber-1.4.1',
                            'testutils': '../../../Test.UnitTest.JS/Utils',
                            'shared': '../../Legacy/Shared',
                            'testdata': '../../../Test.UnitTest.JS/UnitTests/' + name + '/testdata'
                        }, addConfigurationPaths(config.SuperAccounts))

                    }
                },
                helpers: [
                    'Assets/scripts/ato/helperscript.js'

                    //'Legacy/Shared/common/constants.js'
                ],
                specs: [
                    //'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
                    //'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
                    '../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
                ],
                //junit: {
                //    path: 'build/junit/' + name + '/'
                //},
                timeout: 100000,
                vendor: jasmine.SuperAccounts
            }
        }
        ,
        //specs : 'src/test/js/unit-headless.html',

        phantomjs: {
            'ignore-ssl-errors': true
        },


    }

}

关于javascript - Coverage.json 不是用 Jasmine RequireJS 和 Istanbul 生成的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36053992/

相关文章:

javascript - Facebook 爬虫目前是否在解析 DOM 之前解释 javascript?

javascript - Python/Selenium 在执行 Javascript 时不会切换 Chrome 78 的页面

javascript - 使用已定义的选项值定义 grunt 别名

css - 在 Less 中为 CSS 类中的 Sprite 从宽度转换为背景宽度

Javascript 对象原型(prototype)混淆(使用 require.js 和 Three.js)

javascript - 让 Magnific Popup 与 RequireJS 一起使用

javascript - React 组件在屏幕上打印两次

javascript - ReactJS:在 JQuery 事件监听器函数中调用 'this'

handlebars.js - 使用 Assemble 从不同的集合中获取 "pages"

javascript - 使用 ReactJS 时数据表 Bootstrap 主题不适用