Настройте карму для приложения на основе Angularjs с помощью ngJsTree - PullRequest
0 голосов
/ 21 января 2020

У меня проблемы с настройкой Кармы для AngularJs -проекта. Когда я запускаю Karma, он жалуется, что ngJsTree недоступен, даже если я указал это в файле конфигурации и установил его локально через npm install. Я не могу понять, почему Карма не может найти ngJsTree, он находит все другие зависимости, указанные выше. Для упрощения я указал один тестовый пример.

мое приложение. js файл

'use strict';

/**
 * @ngdoc overview
 * @name diarietApp
 * @description
 * # xxxApp
 *
 * Main module of the application.
 */
angular.module('xxxApp', [
        'ngAnimate',
        'ngAria',
        'ngCookies',
        'ngMessages',
        'ngResource',
        'ngRoute',
        'ngSanitize',
        'ngJsTree',
        'pascalprecht.translate',
        'ajoslin.promise-tracker',
        'ui.select',
        'ui.bootstrap',
        'ngDraggable',
        'unsavedChanges',
        'cfp.hotkeys',
        'angularCSS',
        'base64',
        'ngMaterial',
        'angularUtils.directives.dirPagination',
        'angular-toArrayFilter',
        'tableSort'
    ])

my karma.conf. js

  // 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', 'requirejs'],


    // list of files / patterns to load in the browser
    files: [
      'test-main.js',
      '../node_modules/angular/angular.js',
      '../node_modules/angular-mocks/angular-mocks.js',
      '../node_modules/angular-animate/angular-animate.js',
      '../node_modules/angular-aria/angular-aria.js',
      '../node_modules/angular-cookies/angular-cookies.js',
      '../node_modules/angular-messages/angular-messages.js',
      '../node_modules/angular-resource/angular-resource.js',
      '../node_modules/angular-route/angular-route.js',
      '../node_modules/angular-sanitize/angular-sanitize.js',
      '../node_modules/jquery/dist/jquery.js',
      '../node_modules/jstree/dist/jstree.js',
      '../node_modules/ng-js-tree/ngJsTree.js',
      '../app/scripts/**/*.js',
      '../test/spec/**/valideringsService*.js'
    ],

сообщение об ошибке:

mpt%20(http%3A%2F%2Flocalhost%3A9876%2FabsoluteC%3A%2FAF_Projects%2Fapps-xxx%2Fweb%2Fnode_modules%2Fkarma-jasmine%2Fnode_modules%2Fjasmine-core%2Flib%2Fjasmine-core%2Fj
asmine.js%3Ffbc7eaf339ea249d8c912b258548d4e7b4dc180c%3A6365%3A44)
            at <Jasmine>
            at C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:138:12
            at C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:5062:15
            at forEach (C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:387:20)
            at loadModules (C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:5022:5)
            at Object.createInjector [as injector] (C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:4939:19)
            at UserContext.WorkFn (C:/AF_Projects/apps-xxx/web/node_modules/angular-mocks/angular-mocks.js:3449:52)
            at <Jasmine>
        TypeError: Cannot read property 'isPersonnummer' of undefined
            at <Jasmine>
            at UserContext.<anonymous> (spec/services/valideringsServiceSpec.js:16:35)
            at <Jasmine>
Chrome 79.0.3945 (Windows 10.0.0) valideringsService .giltigt personnummer FAILED
        Error: [$injector:modulerr] Failed to instantiate module xxxApp due to:
        Error: [$injector:modulerr] Failed to instantiate module ngJsTree due to:
        Error: [$injector:nomod] Module 'ngJsTree' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you spe
cify the dependencies as the second argument.

...

            at <Jasmine>
            at C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:138:12
            at C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:5062:15
            at forEach (C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:387:20)
            at loadModules (C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:5022:5)
            at Object.createInjector [as injector] (C:/AF_Projects/apps-xxx/web/node_modules/angular/angular.js:4939:19)
            at UserContext.WorkFn (C:/AF_Projects/apps-xxx/web/node_modules/angular-mocks/angular-mocks.js:3449:52)
            at <Jasmine>
        TypeError: Cannot read property 'isPersonnummer' of undefined
            at <Jasmine>
            at UserContext.<anonymous> (spec/services/valideringsServiceSpec.js:16:35)
            at <Jasmine>
Chrome 79.0.3945 (Windows 10.0.0) ERROR
  An error was thrown in afterAll
  Uncaught TypeError: Cannot read property 'defaults' of undefined
  TypeError: Cannot read property 'defaults' of undefined
      at C:/AF_Projects/apps-xxx/web/node_modules/ng-js-tree/ngJsTree.js:3:14
      at C:/AF_Projects/apps-xxx/web/node_modules/ng-js-tree/ngJsTree.js:25:3
  Uncaught Error: Module name "jstree/dist/jstree.js" has not been loaded yet for context: _. Use require([])
  https://requirejs.org/docs/errors.html#notloaded
  Error: Module name "jstree/dist/jstree.js" has not been loaded yet for context: _. Use require([])
  https://requirejs.org/docs/errors.html#notloaded
      at makeError (C:/AF_Projects/apps-xxx/web/node_modules/requirejs/require.js:168:17)
      at Object.localRequire [as require] (C:/AF_Projects/apps-xxx/web/node_modules/requirejs/require.js:1436:44)
      at requirejs (C:/AF_Projects/apps-xxx/web/node_modules/requirejs/require.js:1797:24)
      at C:/AF_Projects/apps-xxx/web/app/scripts/controllers/trad/tradCtrl.js:3:1
Chrome 79.0.3945 (Windows 10.0.0): Executed 2 of 2 (2 FAILED) ERROR (0 secs / 0.03 secs)
Chrome 79.0.3945 (Windows 10.0.0): Executed 2 of 2 (2 FAILED) ERROR (0.063 secs / 0.03 secs)
20 01 2020 21:52:16.772:DEBUG [launcher]: CAPTURED -> BEING_KILLED
20 01 2020 21:52:16.772:DEBUG [launcher]: BEING_KILLED -> BEING_FORCE_KILLED
20 01 2020 21:52:16.774:DEBUG [karma-server]: Run complete, exiting.
20 01 2020 21:52:16.775:DEBUG [launcher]: Disconnecting all browsers
20 01 2020 21:52:16.776:DEBUG [launcher]: BEING_FORCE_KILLED -> BEING_FORCE_KILLED
20 01 2020 21:52:16.822:DEBUG [launcher]: Process Chrome exited with code null and signal SIGTERM
20 01 2020 21:52:16.824:DEBUG [temp-dir]: Cleaning temp dir C:\cygwin64\tmp\karma-18297091
20 01 2020 21:52:16.977:DEBUG [launcher]: Finished all browsers
20 01 2020 21:52:16.978:DEBUG [launcher]: BEING_FORCE_KILLED -> FINISHED
20 01 2020 21:52:16.979:DEBUG [launcher]: FINISHED -> FINISHED

test-main. js

var allTestFiles = []
var TEST_REGEXP = /(spec|test)\.js$/i

// Get a list of all the test files to include
Object.keys(window.__karma__.files).forEach(function (file) {
  if (TEST_REGEXP.test(file)) {
    // Normalize paths to RequireJS module names.
    // If you require sub-dependencies of test files to be loaded as-is (requiring file extension)
    // then do not normalize the paths
    var normalizedTestModule = file.replace(/^\/base\/|\.js$/g, '')
    allTestFiles.push(normalizedTestModule)
  }
})

require.config({
  // Karma serves files under /base, which is the basePath from your config file
  baseUrl: '/base',

  // dynamically load all test files
  deps: allTestFiles,

  // we have to kickoff jasmine, as it is asynchronous
  callback: window.__karma__.start
})
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...