Intellij中具有业力的空测试套件

时间:2018-08-01 13:58:01

标签: angularjs unit-testing intellij-idea jasmine karma-runner

我正在使用业力运行angularjs单元测试。 我有2种方法可以做到这一点:

  1. 使用咕unt声
  2. 使用intellij(带有编辑器左侧的播放图标)

直到现在一切正常,但现在只有咕unt声真正在运行测试。 Intellij给我这个输出:

  

空的测试套件。

     

以退出代码0结束的过程

我不知道是因为我最近更新了Intellij,还是因为我删除了node_modules并重新安装它。.

这是我的karma.conf.js文件:

// Karma configuration
// http://karma-runner.github.io/0.12/config/configuration-file.html
// Generated on 2016-01-01 using
// generator-karma 1.0.1

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/...)
        // as well as any additional frameworks (requirejs/chai/sinon/...)
        frameworks: [
            'jasmine-jquery',
            'jasmine'
        ],

        reporters: ['progress', 'coverage'],


        preprocessors: {
            'app/**/*.html': ['ng-html2js'],
            'test/**/*.es6': ['babel'],
            'app/**/*.js': ['coverage']
        },

        // list of files / patterns to load in the browser
        files: [
            // bower:js
            'bower_components/jquery/dist/jquery.js',
            'bower_components/ipaddr.js/lib/ipaddr.js',
            'bower_components/angular/angular.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/d3/d3.js',
            'bower_components/d3-cloud/build/d3.layout.cloud.js',
            'bower_components/d3-more-plugins/build/d3-plugins.js',
            'bower_components/nvd3/build/nv.d3.js',
            'bower_components/angular-nvd3/dist/angular-nvd3.js',
            'bower_components/velocity/velocity.js',
            'bower_components/velocity/velocity.ui.js',
            'bower_components/angular-ui-router/release/angular-ui-router.js',
            'bower_components/javascript-detect-element-resize/detect-element-resize.js',
            'bower_components/angular-gridster/src/angular-gridster.js',
            'bower_components/perfect-scrollbar/js/perfect-scrollbar.jquery.js',
            'bower_components/iso-3166-country-codes-angular/dist/iso-3166-country-codes-angular.min.js',
            'bower_components/angular-messages/angular-messages.js',
            'bower_components/lodash/lodash.js',
            'bower_components/angular-vs-repeat/src/angular-vs-repeat.js',
            'bower_components/moment/moment.js',
            'bower_components/lumx/dist/lumx.js',
            'bower_components/v-accordion/dist/v-accordion.js',
            'bower_components/ua-parser-js/src/ua-parser.js',
            'bower_components/smooth-scrollbar/dist/smooth-scrollbar.js',
            'bower_components/angular-smooth-scrollbar/dist/angular-smooth-scrollbar.js',
            'bower_components/codemirror/lib/codemirror.js',
            'bower_components/codemirror/addon/fold/foldcode.js',
            'bower_components/codemirror/addon/fold/foldgutter.js',
            'bower_components/codemirror/addon/fold/xml-fold.js',
            'bower_components/codemirror/addon/fold/brace-fold.js',
            'bower_components/codemirror/addon/search/searchcursor.js',
            'bower_components/codemirror/addon/scroll/simplescrollbars.js',
            'bower_components/codemirror/addon/selection/active-line.js',
            'bower_components/codemirror/addon/edit/matchbrackets.js',
            'bower_components/codemirror/addon/mode/multiplex.js',
            'bower_components/codemirror/mode/javascript/javascript.js',
            'bower_components/codemirror/mode/htmlmixed/htmlmixed.js',
            'bower_components/codemirror/mode/css/css.js',
            'bower_components/codemirror/mode/http/http.js',
            'bower_components/codemirror/mode/xml/xml.js',
            'bower_components/angular-ui-codemirror/ui-codemirror.js',
            'bower_components/angular-resizable/src/angular-resizable.js',
            'bower_components/ngstorage/ngStorage.js',
            'bower_components/ng-csv/build/ng-csv.js',
            'bower_components/jquery-mousewheel/jquery.mousewheel.js',
            'bower_components/js-beautify/js/lib/beautify.js',
            'bower_components/js-beautify/js/lib/beautify-css.js',
            'bower_components/js-beautify/js/lib/beautify-html.js',
            'bower_components/jquery-ui/jquery-ui.js',
            'bower_components/angular-ui-sortable/sortable.js',
            'bower_components/jqueryui-touch-punch/jquery.ui.touch-punch.min.js',
            'bower_components/lz-string/libs/lz-string.min.js',
            'bower_components/tippy.js/dist/tippy.js',
            'bower_components/crypto-js/core.js',
            'bower_components/crypto-js/enc-base64.js',
            'bower_components/crypto-js/md5.js',
            'bower_components/crypto-js/evpkdf.js',
            'bower_components/crypto-js/cipher-core.js',
            'bower_components/crypto-js/aes.js',
            'bower_components/angular-mocks/angular-mocks.js',
            'bower_components/jasmine/lib/jasmine-core/jasmine.js',
            'bower_components/jasmine-jquery/lib/jasmine-jquery.js',
            // endbower
            "app/scripts/**/*.js",
            "app/modules/some-folder/scripts/module.es6",
            "app/modules/mobile-replay/scripts/module.es6",
            "app/modules/web-replay/scripts/module.es6",
            "app/modules/period-picker/scripts/period-picker.es6",
            //"test/mock/**/*.es6",
            "app/modules/**/*.es6",
            "test/spec/**/*.es6",
            'app/views/**/*.html',
            'app/modules/*/views/**/*.html'
        ],

        proxies: {
            '/data/': '/data/'
        },

        // list of files / patterns to exclude
        exclude: [
            'app/modules/web-replay/scripts/replay-libs.js',
            'app/detector-beacon.min.js'
        ],

        // web server port
        port: 8082,

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

        // Which plugins to enable
        plugins: [
            '@metahub/karma-jasmine-jquery',
            'karma-*'
        ],

        ngHtml2JsPreprocessor: {
            stripPrefix: 'app/',
            moduleName: 'html-templates'
        },

        babelPreprocessor: {
            options: {
                presets: [['env',{
                    "targets": {
                        "browsers": ["last 10 Chrome major versions", "last 10 Firefox major versions", "ie >= 11", "safari >= 9"]
                    }
                }]],
                sourceMap: 'inline'
            }
        },

        // 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,

        browserDisconnectTolerance: 8,
        browserNoActivityTimeout: 10000,

        // 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_'
    });
};

示例项目(我无法上传我的项目):

经过测试的文件

angular.module('app', [])
.controller('PasswordController', function PasswordController($scope) {
  $scope.password = '';
  $scope.grade = function() {
    var size = $scope.password.length;
    if (size > 8) {
      $scope.strength = 'strong';
    } else if (size > 3) {
      $scope.strength = 'medium';
    } else {
      $scope.strength = 'weak';
    }
  };
});

测试文件:

describe('PasswordController', function() {
  beforeEach(module('app'));

  var $controller, $rootScope;

  beforeEach(inject(function(_$controller_, _$rootScope_){
    // The injector unwraps the underscores (_) from around the parameter names when matching
    $controller = _$controller_;
    $rootScope = _$rootScope_;
  }));

  describe('$scope.grade', function() {
    it('sets the strength to "strong" if the password length is >8 chars', function() {
      var $scope = $rootScope.$new();
      var controller = $controller('PasswordController', { $scope: $scope });
      $scope.password = 'longerthaneightchars';
      $scope.grade();
      expect($scope.strength).toEqual('strong');
    });
  });
});

0 个答案:

没有答案