【问题标题】:Exporting jasmine test results in json format from grunt从 grunt 以 json 格式导出 jasmine 测试结果
【发布时间】:2016-07-01 19:24:53
【问题描述】:

我正在使用 Jasmine 从 Grunt 任务中执行测试。我想以 JSON 格式输出测试用例的结果。下面是茉莉花的配置。此配置在 junit 文件夹下生成 XML 文件。

var conf = {

        src: [
           // '../../../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
        ],
        options: {
            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(app))

                }
            },
            helpers: [
                'Assets/scripts/ato/helperscript.js'
            ],
            specs: [
                       '../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
            ],
            junit: {
                path: 'build/junit/' + name + '/'
            },
            timeout: 100000,
            vendor: arr
        }
            ,
        //specs : 'src/test/js/unit-headless.html',

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

我希望结果以 JSON 格式显示,所以我使用 npm 安装了 jasmine-json-test-reporter 并尝试在我当前的配置中实现它,如下所示:

 var conf = {

        src: [
           // '../../../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
        ],
        options: {
            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(app))

                }
            },
            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: arr
        }
            ,
        //specs : 'src/test/js/unit-headless.html',

        phantomjs: {
            'ignore-ssl-errors': true
        },
        onPrepare: function () {
            var JSONReporter = require('jasmine-json-test-reporter');
            var jasmine = require('jasmine');
            return browser.getProcessedConfig().then(function (config) {
                browser.params['browsername'] = config.capabilities.browserName.toUpperCase();
                browser.params['version'] = config.capabilities.version || 'latest stable';
                browser.params['platform'] = config.capabilities.os + '-' + config.capabilities.os_version;
                jasmine.getEnv().addReporter(new JSONReporter({
                    file: 'results/' + browser.params.platform + '-' + browser.params.version + '.' + browser.params.browsername + '.json',
                    beautify: true,
                    indentationLevel: 2 // used if beautify === true 
                }));
            });
        }

    }

此代码未生成任何 json 文件。我不太确定在当前的 jasmine 配置中使用 jasmine-json-test-reporter。

【问题讨论】:

    标签: json gruntjs jasmine


    【解决方案1】:

    我设法让它工作。源文件未指向正确的位置。更改以下行修复了它:

    src: [
                    'SinglePageApplications/' + name + '/common/**/*.js',
                    'SinglePageApplications/' + name + '/viewmodels/**/*.js',
                    'SinglePageApplications/' + name + '/views/**/*.js',
                    'SinglePageApplications/' + name + '/main.js'
                ],
    

    【讨论】:

      猜你喜欢
      • 2018-03-22
      • 2018-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-26
      • 1970-01-01
      • 2015-07-19
      • 2014-09-02
      相关资源
      最近更新 更多