2016-11-24 15 views
0

私はAngular 2アプリ用にカルマを設定しています。私のkarma-test-shim.jsのSystem.importはエラーを投げています。私はkarma.conf.jsに入れたものを間違ってインポートしていると思います。karma-test-shim.jsでSystem.importが処理されない

マイkarma.conf.js(トリムダウン):

'use strict'; 

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

module.exports = function (config) { 
    config.set({ 
    basePath: './', 
    frameworks: ['jasmine'], 
    files: [ 
     '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', 

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

    { pattern: 'app/**/*.js', included: false, watched: true }, 
    { pattern: 'app/**/*.html', included: false, watched: true, served: true }, 
    { pattern: 'app/**/*.css', included: false, watched: true, served: true }, 
    { pattern: 'node_modules/systemjs/dist/system-polyfills.js', included: false, watched: false }, 
    { pattern: 'karma-test-shim.js', included: true, watched: true}, 
], 
// Proxied base paths 
proxies: {}, 
exclude: [ 
    'node_modules/**/*spec.js' 
], 
reporters: ['mocha'], 
port: 9876, 
colors: true, 
logLevel: config.LOG_DEBUG, 
autoWatch: false, 
// TODO: Remove sandbox. This is just work around for Chrome issue 
// https://github.com/karma-runner/karma-chrome-launcher/issues/73#issuecomment-236597429 
browsers: ['ChromeNoSandbox'], 
customLaunchers: { 
    ChromeNoSandbox: { 
    base: 'Chrome', 
    flags: ['--no-sandbox'] 
    } 
}, 
singleRun: true, 

// Command line args for tests 
client: { 
    files: argv.files 
    } 
    }); 
}; 

私のカルマテスト-shim.js:

// Turn on full stack traces in errors to help debugging 
Error.stackTraceLimit=Infinity; 


jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000; 

// // Cancel Karma's synchronous start, 
// // we will call `__karma__.start()` later, once all the specs are loaded. 
__karma__.loaded = function() {}; 


System.config({ 
    packages: { 
    'base/app': { 
     defaultExtension: false, 
     format: 'register', 
     map: Object.keys(window.__karma__.files). 
      filter(onlyAppFiles). 
      reduce(function createPathRecords(pathsMapping, appPath) { 
       var moduleName = appPath.replace(/^\/base\/app\//, './').replace(/\.js$/, ''); 
       pathsMapping[moduleName] = appPath + '?' + window.__karma__.files[appPath] 
       return pathsMapping; 
      }, {}) 

     } 
    } 
}); 

Promise.all([ 
    System.import('@angular/core/testing'), 
    System.import('@angular/platform-browser-dynamic/testing') 
]) 
    // First, initialize the Angular testing environment. 
    .then(([testing, testingBrowser]) => { 
    // testing.getTestBed().initTestEnvironment(
    // testingBrowser.BrowserDynamicTestingModule, 
    // testingBrowser.platformBrowserDynamicTesting() 
    //); 
    testing.setBaseTestProviders(testingBrowser.TEST_BROWSER_DYNAMIC_PLATFORM_PROVIDERS, 
     testingBrowser.TEST_BROWSER_DYNAMIC_APPLICATION_PROVIDERS); 
    }) 
    // Then we find all the tests. 
    .then(() => require.context('./', true, /\.spec\.ts/)) 
    // And load the modules. 
    .then(context => context.keys().map(context)) 
    // Finally, start Karma to run the tests. 
    .then(__karma__.start, __karma__.error); 


function filePath2moduleName(filePath) { 
    return filePath. 
      replace(/^\//, '').    // remove/prefix 
      replace(/\.\w+$/, '');   // remove suffix 
} 


function onlyAppFiles(filePath) { 
    return /\/base\/app\/(?!.*\.spec\.js$).*\.js$/.test(filePath); 
} 


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

エラー私は取得しています:

24 11 2016 18:19:31.954:DEBUG [middleware:source-files]: Requesting /@angular/core/testing/
24 11 2016 18:19:31.954:DEBUG [middleware:source-files]: Fetching /@angular/core/testing 
24 11 2016 18:19:31.956:WARN [web-server]: 404: /@angular/core/testing 
24 11 2016 18:19:31.958:DEBUG [middleware:source-files]: Requesting /@angular/platform-browser-dynamic/testing/
24 11 2016 18:19:31.959:DEBUG [middleware:source-files]: Fetching /@angular/platform-browser-dynamic/testing 
24 11 2016 18:19:31.962:WARN [web-server]: 404: /@angular/platform-browser-dynamic/testing 
Chrome 54.0.2840 (Windows 7 0.0.0) ERROR 
    { 
    "originalErr": {} 
    } 

答えて

0

あなたのkarma-test-shim.jsが間違っていると、地図を変更する必要があります

System.config({ 
    baseURL: '/base', 
    // Extend usual application package list with test folder 
    packages: {'testing': {main: 'index.js', defaultExtension: 'js'}}, 

    // Assume npm: is set in `paths` in systemjs.config 
    // Map the angular testing umd bundles 
    map: { 
    '@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js', 
    '@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js', 
    '@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-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/http/testing': 'npm:@angular/http/bundles/http-testing.umd.js', 
    '@angular/router/testing': 'npm:@angular/router/bundles/router-testing.umd.js', 
    '@angular/forms/testing': 'npm:@angular/forms/bundles/forms-testing.umd.js', 
    }, 
}); 

強いテキスト

+0

ええ、それは間違っていたマッピングました。 –

関連する問題