Требование не определено, angularDragula не определено - как исправить проблемы конфигурации кармы? - PullRequest
0 голосов
/ 14 декабря 2018

Только начинается тестирование с Jamsine и Karma.Я попытался следовать официальным документам AngularJS, а также нескольким другим статьям, чтобы настроить мою конфигурацию и начать тестирование.Я получаю, что это требование не определено, а angularDragula не определено с ошибками, когда я запускаю начало кармы .Я пытаюсь установить контроллер AngularJS здесь.Вот мой конфигурационный файл кармы:

module.exports = function(config) {
  config.set({

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine','browserify'],
    plugins: ['karma-jasmine','karma-chrome-launcher','karma-browserify'],
    // list of files / patterns to load in the browser
    files: [
      'public/assets/bower_components/angular/angular.min.js',
      'node_modules/angular-mocks/angular-mocks.js',
      'public/assets/bower_components/angular-dragula/angular-dragula.js',
      'public/app/controllers/testController.js',
      'public/app/app.js',
      'public/app/controllers/testController.spec.js'
    ],


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


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
      'public/*.js': ['browserify']
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


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


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false,

    // Concurrency level
    // how many browser should be started simultaneous
    concurrency: Infinity
  })
}

Я попытался найти ошибку require и обнаружил, что browserify требуется при тестировании кармы в браузере.Я установил его и добавил в файл конфигурации (препроцессоры).Но все равно это не помогает.

Вот моя спецификация:

describe('Controller Test', function(){

    beforeEach(module('App'));
    var $controller;

    beforeEach(inject(function(_$controller_){
        $controller = _$controller_;
    }));

    describe('$scope.testVar', function(){
        var $scope, controller;

        beforeEach(function(){
            $scope = {};
            controller = $controller('testController', {$scope : $scope});

            it('checks value for testVar', function(){
                expect($scope.testVar).toEqual('hey');
            })
        })
    })
})

Я все еще получаю эту ошибку:

Chrome 70.0.3538 (Linux 0.0.0) ERROR
  {
    "message": "An error was thrown in afterAll\nUncaught ReferenceError: require is not defined\nUncaught ReferenceError: angularDragula is not defined",
    "str": "An error was thrown in afterAll\nUncaught ReferenceError: require is not defined\nUncaught ReferenceError: angularDragula is not defined"
  }
Chrome 70.0.3538 (Linux 0.0.0): Executed 0 of 0 ERROR (0.005 secs / 0 secs)

Может ли кто-нибудь помочь мне здесь?

...