2016-12-05 5 views
3

Привет, Привет, Я пишу тестовый пример, и в моем приложении я использую «@ ng-bootstrap/ng-bootstrap /» ниже, моя система .config.tsОшибка при запуске «npm test» для Angular2 с использованием Jasmine и кармы

(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; 

    } 
}; 

При выполнении моего НПМ теста он бросает под ошибкой:

05 12 2016 15:50:48.454:WARN [web-server]: 404: /base/node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js Chrome 39.0.2171 (Windows 7 0.0.0) ERROR: Error{originalErr: Error{}} 05 12 2016 15:50:48.582:WARN [web-server]: 404: /base/node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js

Finished in 0.003 secs/0 secs

SUMMARY: √ 0 tests completed npm ERR! Test failed. See above for more details.

Нет проблем с приложением «npm start», работает как и ожидалось, но в случае «npm test» я сталкиваюсь с проблемой. Мы полностью заблокированы здесь, любая помощь приветствуется.

ответ

4

Вы не добавили ng-bootstrap в свои файлы кармы. Карма только предоставляет файл, если он упоминается в свойстве files.

Вы должны добавить файл в karam.conf.js:

pattern: 'node_modules/@ng-bootstrap/**/*.js', included: false, watched: false }, 
+0

Спасибо, Его сейчас работает нормально. :) –

+0

@NawalKishore Добро пожаловать;) – Dinistro