3

こんにちは、私はテスト ケースを書いており、アプリケーションで "@ng-bootstrap/ng-bootstrap/" を使用しています。以下は system.config.ts です。

(function (global) {
  System.config({

    paths: {
      // paths serve as alias
      'npm:': 'base/node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',
      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@ng-bootstrap/ng-bootstrap': 'npm:@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js',

      '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
      '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
      '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
      '@angular/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js',
      '@angular/platform-browser/testing':
      'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
      '@angular/platform-browser-dynamic/testing':
      'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',
      '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js',

      // other libraries
      'rxjs': 'npm:rxjs',
      'ng2-highcharts': 'npm:ng2-highcharts',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',

    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
       "@ng-bootstrap/ng-bootstrap": {
        defaultExtension: "js"
      },
      "ng2-highcharts": {
        main: "index.js",
        defaultExtension: "js"
      },
      'angular-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);

以下は私のkarma.config.tsです:

// Karma configuration
// Generated on Wed Jul 15 2015 09:44:02 GMT+0200 (Romance Daylight Time)
'use strict';

var argv = require('yargs').argv;

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


    // list of files / patterns to load in the browser
    files: [
      // Polyfills.
      'node_modules/core-js/client/shim.min.js',

      'node_modules/traceur/bin/traceur.js',

      // System.js for module loading
      'node_modules/systemjs/dist/system.src.js',

      // Zone.js dependencies
      'node_modules/zone.js/dist/zone.js',
      'node_modules/zone.js/dist/long-stack-trace-zone.js',
      'node_modules/zone.js/dist/async-test.js',
      'node_modules/zone.js/dist/fake-async-test.js',
      'node_modules/zone.js/dist/sync-test.js',
      'node_modules/zone.js/dist/proxy.js',
      'node_modules/zone.js/dist/jasmine-patch.js',
      'https://js.stripe.com/v2',
      // RxJs.
      { pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
      { pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },

      // paths loaded via module imports
      // Angular itself
      { pattern: 'node_modules/@angular/**/*.js', included: false, watched: true },
      { pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false },


      { pattern: 'dist/dev/**/*.js', included: false, watched: true },

      { pattern: 'dist/dev/**/*.html', included: false, watched: true, served: true },
      { pattern: 'dist/dev/**/*.css', included: false, watched: true, served: true },
      { pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: false, watched: false }, // PhantomJS2 (and possibly others) might require it

      // suppress annoying 404 warnings for resources, images, etc.
      { pattern: 'dist/dev/assets/**/*', watched: false, included: false, served: true },

      'test-config.js',
      'dist/dev/app/system-config.js',
      'test-main.js'
    ],

    // must go along with above, suppress annoying 404 warnings.
    proxies: {
      '/assets/': '/base/dist/dev/assets/'
    },

    // list of files to exclude
    exclude: [
      'node_modules/**/*spec.js'
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor

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


    // web server port
    port: 9876,


    // enable / disable colors in the output (reporters and logs)
    colors: true,
    captureTimeout: 60000, // it was already there
browserDisconnectTimeout : 10000,
browserDisconnectTolerance : 1,
browserNoActivityTimeout : 60000,//by default 10000

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


    customLaunchers: {
      Chrome_travis_ci: {
        base: 'Chrome',
        flags: ['--disable-web-security']
      },
      IE11: {
      base: 'IE',
    'x-ua-compatible': 'IE=EmulateIE11'
  }
    },

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

    // Passing command line arguments to tests
    client: {
      files: argv.files
    }
  });

  if (process.env.APPVEYOR) {
    config.browsers = ['IE'];
    config.singleRun = true;
   // Note: default value (10000) is not enough
  }

  if (process.env.TRAVIS || process.env.CIRCLECI) {
    config.browsers = ['Chrome_travis_ci'];
    config.singleRun = true;

  }
};

npm テストの実行中に以下のエラーがスローされます:

05 12 2016 15:50:48.454:WARN [Web サーバー]: 404: /base/node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js Chrome 39.0.2171 (Windows 7 0.0.0)エラー: エラー {originalErr: エラー{}} 05 12 2016 15:50:48.582: 警告 [web サーバー]: 404: /base/node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js

0.003 秒 / 0 秒で終了

概要: √ 0 個のテストが完了しました npm ERR! テストに失敗しました。詳細については、上記を参照してください。

「npm start」アプリケーションが期待どおりに実行されていることに問題はありませんが、「npm test」の場合、問題に直面しています。私たちはここで完全にブロックされています。

4

1 に答える 1

5

ng-bootstrapカルマ ファイルを追加しませんでした。Karma は、filesプロパティで言及されている場合にのみファイルを提供します。

次の場所にファイルを追加する必要がありますkaram.conf.js

 pattern: 'node_modules/@ng-bootstrap/**/*.js', included: false, watched: false },
于 2016-12-05T10:47:13.417 に答える