2016-05-26 11 views
0

私はAngular2プロジェクトでカルマをセットアップしようとしていますが、ジャーミンでカルマを正常に実行しているangle2クイックスタートを参照しようとしています。Anger2でカルマを設定するときにSystem.registerコールが無効

今まで私はkarma-test-shimをインポートしました。私のkarma.conf.jsファイルを私が必要と考えるものに変更しました。私は成功したテストで引っ張っています信じているが、カルマは、このエラー

Uncaught TypeError: Invalid System.register call. Anonymous System.register calls can only be made by modules loaded by SystemJS.import and not via script tags. 
ここ

シムで、設定ファイル

karma.conf.js

module.exports = function(config) { 
var client = './src/client/', 
    clientApp = client + 'app/'; 

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

    // frameworks to use 
    // some available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
    frameworks: ['jasmine'], 

    plugins:[ 
     require('karma-jasmine'), 
     require('karma-phantomjs-launcher'), 
     require('karma-chrome-launcher'), 
     require('karma-htmlfile-reporter') 
    ], 

    // list of files/patterns to load in the browser 
    files: [ 
     'node_modules/systemjs/dist/system.src.js', 

     //Polyfills 
     'node_modules/es6-shim/es6-shim.min.js', 
     'node_modules/systemjs/dist/system-polyfills.js', 

     // Reflect and Zone.js dependencies 

     'node_modules/reflect-metadata/Reflect.js', 
     'node_modules/zone.js/dist/zone.js', 
     'node_modules/zone.js/dist/jasmine-patch.js', 
     'node_modules/zone.js/dist/async-test.js', 
     'node_modules/zone.js/dist/fake-async-test.js', 

     // RxJs. 
     {pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false}, 
     {pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false}, 

     //paths loaded by module loaders 
     {pattern: 'node_modules/@angular/**/*.js', included: false, watched: false}, 
     {pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: false}, 

     {pattern: 'systemjs.config.js', included: false, watched: false}, 

     {pattern: 'karma-test-shim.js', included: false, watched: false}, 

     // transpiled application & spec code paths loaded via module imports 
     {pattern: clientApp + '**/**/*.js', included: true, watched: false}, 
     {pattern: clientApp + '**/**/*.spec.js', included: true, watched: true}, 

     // asset (HTML & CSS) paths loaded via Angular's component compiler 
     // (these paths need to be rewritten, see proxies section) 
     {pattern: clientApp + '**/**/*.html', included: false, watched: true}, 
     {pattern: clientApp + '**/**/*.css', included: false, watched: true}, 

     // paths for debugging with source maps in dev tools 
     {pattern: clientApp + '**/**/*.ts', included: false, watched: false}, 
     {pattern: clientApp + '**//***.js.map', included: false, watched: false} 
    ], 

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

    proxies: { 
     "/app/": clientApp 
    }, 

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

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

    htmlReporter: { 
     outputFile: 'reports/unitTests.html', 

     // Optional 
     pageTitle: 'Unit Tests', 
     subPageTitle: __dirname 
    }, 

    // 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', 'ChromeCanary', 'FirefoxAurora', 'Safari', 'PhantomJS'], 
    browsers: ['Chrome'], 

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

}と文句を言います。

とカルマ・テスト・shim.js

// /*global jasmine, __karma__, window*/ 
Error.stackTraceLimit = Infinity; 
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; 

__karma__.loaded = function() { 
}; 

function isJsFile(path) { 
    return path.slice(-3) == '.js'; 
} 

function isSpecFile(path) { 
    return /\.spec\.js$/.test(path); 
} 

function isBuiltFile(path) { 
    var builtPath = '/src/client'; 
    return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath); 
} 

var allSpecFiles = Object.keys(window.__karma__.files) 
    .filter(isSpecFile) 
    .filter(isBuiltFile); 

System.config({ 
    baseURL: ' ', 
    packageWithIndex: true // sadly, we can't use umd packages (yet?) 
}); 

System.import('systemjs.config.js') 
    .then(function() { 
     return Promise.all([ 
      System.import('@angular/core/testing'), 
      System.import('@angular/platform-browser-dynamic/testing') 
     ]) 
    }) 
    .then(function (providers) { 
     var testing = providers[0]; 
     var testingBrowser = providers[1]; 

     testing.setBaseTestProviders(
      testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, 
      testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); 

    }) 
    .then(function() { 
     // Finally, load all spec files. 
     // This will run the tests directly. 
     return Promise.all(
      allSpecFiles.map(function (moduleName) { 
       return System.import(moduleName); 
      })); 
    }) 
    .then(__karma__.start, __karma__.error); 

マイアプリの構造は、これまでのところ、私はちょうどそのような任意の輸入せずに健全性テストを実行しようとしているので、

./src 
    /client 
      /app/components 
       /directives 
       /etc... 
       main 

のようなものです

describe('1st tests', function() { 
it('true is true', function() { return expect(true).toEqual(true); }); 
}); 

私が気づいたことは、開発ツールのソースがスペックファイルのタイプスクリプトを見つけているようだということです。

答えて

1

問題は、systemJs.configファイルを正しく設定しなかったことです。 'app'のパスを 'src/client/app'に変更し、カルマが正常に実行されました。

EDIT

変更はそうのようなsystemjs.configであなたのマップファイルに行われる必要がある。我々はこのプロジェクトではdistの名前のビルドフォルダを使用している

var map = { 'app': 'src/client/app', // 'dist', 'rxjs': 'node_modules/rxjs', '@angular': 'node_modules/@angular',

+0

この変更をどのように実行しますか?どのファイルが変更されましたか? 'systemjs.config.js'というファイルがありましたか? – XtianGIS

+0

改訂版の回答を見る –

関連する問題