2016-11-03 17 views
1

Angular、JSの単体テスト実装があります。テストは私によって作られたものではありません。テストはJasmineを使用してビルドされ、PhantomJSのKarmaで実行されます。PhantomJSで実行中にKarmaテストが失敗する

問題は、テストがChromeを開き、何かを実行してブラウザを閉じることです。今私は、ブラウザを開こうとしないために、クロムを使わないようにこの実装を変更したいが、PhantomJsを変更したい。

module.exports = function(config) { 

    var appBase = 'app/';  // transpiled app JS files 
    var appAssets ='/base/app/'; // component assets fetched by Angular's compiler 

    config.set({ 
    basePath: '', 
    frameworks: ['jasmine'], 
    plugins: [ 
     require('karma-jasmine'), 
//  require('karma-chrome-launcher'), 
     require('karma-htmlfile-reporter'), 
     require('karma-phantomjs-launcher') 
    ], 

    customLaunchers: { 
     expletiveRedacted: { 
     base: 'PhantomJS', 
     options: { 
      windowName: 'my-window', 
      settings: { 
      webSecurityEnabled: false 
      }, 
     }, 
     flags: ['--load-images=true'], 
     debug: true 
     }, 

// phantomjsLauncher: { 
//  // Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom) 
//  exitOnResourceError: true 
// } 
    }, 

// customLaunchers: { 
//  // From the CLI. Not used here but interesting 
//  // chrome setup for travis CI using chromium 
//  Chrome_travis_ci: { 
//  base: 'Chrome', 
//  flags: ['--no-sandbox'] 
//  } 
// }, 
    files: [ 
     // System.js for module loading 
     'node_modules/systemjs/dist/system.src.js', 
     'node_modules/systemjs/dist/system-polyfills.js', 

     // Polyfills 
     'node_modules/core-js/client/shim.js', 

     // Reflect and Zone.js 
     'node_modules/reflect-metadata/Reflect.js', 
     'node_modules/zone.js/dist/zone.js', 
     'node_modules/zone.js/dist/long-stack-trace-zone.js', 
     'node_modules/zone.js/dist/proxy.js', 
     'node_modules/zone.js/dist/sync-test.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 }, 

     // Angular 2 itself and the testing library 
     {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}, 
//  'karma-test-shim.js', 
     {pattern: "karma-test-shim.js", watched: false}, 

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

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

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

     {pattern: 'node_modules/angular2-notifications/**/*.js', included: false, watched: false}, 
     {pattern: 'node_modules/angular2-notifications/**/*.js.map', included: false, watched: false} 
    ], 

    // proxied base paths for loading assets 
    proxies: { 
     // required for component assets fetched by Angular's compiler 
     "/app/": appAssets 
    }, 

    exclude: [], 
    preprocessors: {}, 
    reporters: ['progress', 'html'], 

    // HtmlReporter configuration 
    htmlReporter: { 
     // Open this file to see results in browser 
     outputFile: '_test-output/tests.html', 

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

    port: 9876, 
    colors: true, 
    logLevel: config.LOG_INFO, 
    autoWatch: true, 
    browsers: ['expletiveRedacted'], 
    singleRun: true 
    }) 
} 

カルマ・テストshim.jsファイル:

karma.conf.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 = '/base/app/'; 
    return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath); 
} 

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

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

System.import('systemjs.config.js') 
    .then(() => Promise.all([ 
     System.import('@angular/core/testing'), 
     System.import('@angular/platform-browser-dynamic/testing') 
    ])) 
    .then((providers) => { 
    var coreTesting = providers[0]; 
    var browserTesting = providers[1]; 
    coreTesting.TestBed.initTestEnvironment(
      browserTesting.BrowserDynamicTestingModule, 
      browserTesting.platformBrowserDynamicTesting()); 

    }) 
    .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); 

を今、私は次の例外を取得します:

> karma start karma.conf.js 

03 11 2016 12:31:11.264:INFO [karma]: Karma v1.3.0 server started at http://localhost:9876/ 
03 11 2016 12:31:11.264:INFO [launcher]: Launching browser expletiveRedacted with unlimited concurrency 
03 11 2016 12:31:11.275:INFO [launcher]: Starting browser PhantomJS 
03 11 2016 12:31:11.708:INFO [phantomjs.launcher]: ACTION REQUIRED: 
03 11 2016 12:31:11.709:INFO [phantomjs.launcher]: 
03 11 2016 12:31:11.709:INFO [phantomjs.launcher]: Launch browser at 
03 11 2016 12:31:11.709:INFO [phantomjs.launcher]: http://localhost:9000/webkit/inspector/inspector.html?page=2 
03 11 2016 12:31:11.709:INFO [phantomjs.launcher]: 
03 11 2016 12:31:11.709:INFO [phantomjs.launcher]: Waiting 15 seconds ... 
03 11 2016 12:31:28.639:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#7v0Lf6-X3ckgi5xZAAAA with id 33327697 
PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR 
    SyntaxError: Unexpected token ')' 
    at karma-test-shim.js:31 


npm ERR! Test failed. See above for more details. 

ライン31は、以下である:.then(()=> Promise.all([

私は実際にNode.JSを知らない。どのようなアイデアがこの問題の原因であり、どのように修正することができますか?

答えて

0
SyntaxError: Unexpected token ')' 
    at karma-test-shim.js:31 

ライン31は以下の通りです:.then(() => Promise.all([

それは最も可能性の高い矢印機能の使用です。 Chromeではサポートされていますが、おそらくPhantomJSではサポートされていません。 「スタック」:「(SystemJSだけではなく、

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) { 
    ... 
    }) 
+0

確かに、これは問題でしたが、今私はsystemjs/DIST/system.src.jsでラムダコールに関する同様の問題を、取得functionを使用するように変更)予期しないトークン '>' \ n \ ... もう1つの方法がありますか? – Nicolae

+0

わかりません: - (... –

+0

いくつかの設定ファイルに問題があります。 \ ** '** @ angular2-material/$ {name} \' '。**' ** ** ** ** ** 'の代わりに – Nicolae

関連する問題