2016-10-27 6 views
0

私は、チャイのExpectライブラリを使用してエンザイム(テストユーティリティ)を使用して私のReactプロジェクトをテストし、カルマ(テストランナー)を使用してテストを実行しています。カルマテストランナーがコンポーネントのサブディレクトリ内の酵素テストファイルを受け取りません

マイワーキングプロジェクトのディレクトリ構造は次のようになります。 アプリ - >コンポーネント - >ボタン - > __test - > test.jsx

カルマは、上記のテストを見つけるのは問題がなく、正常に実行されます。

問題のディレクトリ構造は次のようになります。 アプリ - >コンポーネント - >リスト - > LISTHEADER - > __test - 彼らはサブディレクトリ内に存在する場合> test.jsx

カルマは、テストをピックアップしていませんコンポーネントの

私はautoWatch=trueと設定し、パスをkarma.configに追加し、インターネット上の手がかり/ヒント/解決策を運のない状態で探しました。それが役に立ったら私のkarma.configファイルを追加しました。

この問題を調査してくれてありがとう!

const webpack = require('webpack') 
const argv = require('yargs').argv 
const path = require('path') 

const aliases = require('./webpack/alias') 
const config = require('./webpack/settings') 
const loaders = require('./webpack/loaders') 
const preloaders = require('./webpack/preloaders') 

const karmaConfig = (config) => { 
    config.set({ 
    // only use PhantomJS for our 'test' browser 
    browsers: ['PhantomJS'], 

    // just run once by default unless --watch flag is passed 
    singleRun: !argv.watch, 

    // Enable or disable colors in the output (reporters and logs) 
    colors: true, 

    // which karma frameworks do we want integrated 
    frameworks: ['mocha', 'chai', 'sinon'], 

    // displays tests in a nice readable format 
    reporters: ['spec'], 

    // include some polyfills for babel and phantomjs 
    files: [ 
     './node_modules/babel-polyfill/dist/polyfill.js', 
     './node_modules/phantomjs-polyfill/bind-polyfill.js', 
     './app/**/**/__test/test.jsx', // specify files to watch for tests 
     './app/**/**/__test/test.js', // specify files to watch for tests 
     './app/**/**/**/__test/test.jsx', // specify files to watch for tests 
     './app/**/**/**/__test/test.js' // specify files to watch for tests 
    ], 
    preprocessors: { 
     // these files we want to be precompiled with webpack 
     // also run tests throug sourcemap for easier debugging 
     ['./app/**/**/__test/*']: ['webpack', 'sourcemap'] 
    }, 
    // A lot of people will reuse the same webpack config that they use 
    // in development for karma but remove any production plugins like UglifyJS etc. 
    // I chose to just re-write the config so readers can see what it needs to have 
    webpack: { 
     devtool: 'inline-source-map', 
     resolve: { 
     // allow us to import components in tests like: 
     // import Example from 'components/Example'; 
     root: path.resolve(__dirname, './app'), 

     // allow us to avoid including extension name 
     extensions: ['', '.js', '.jsx'], 

     // required for enzyme to work properly 
     alias: aliases 
     }, 

     module: { 
     // don't run babel-loader through the sinon module 
     noParse: [ 
      /sinon(\\|\/)pkg(\\|\/)sinon\.js/ 
     ], 
     // run babel loader for our tests 
     // preLoaders: preloaders, 
     loaders: loaders, 
     }, 
     // required for enzyme to work properly 
     externals: { 
     'jsdom': 'window', 
     'cheerio': 'window', 
     'react-dom/server': 'window', 
     'text-encoding': 'window', 
     'react/addons': true, 
     'react/lib/ExecutionEnvironment': true, 
     'react/lib/ReactContext': 'window' 
     }, 
    }, 
    webpackMiddleware: { 
     noInfo: true, 
     stats: { 
     colors: true, 
     chunks: false 
     } 
    }, 
    // tell karma all the plugins we're going to be using to prevent warnings 
    plugins: [ 
     'karma-*' 
    ], 

    autoWatch: true 
    }) 
} 

module.exports = karmaConfig 

答えて

0

これはグロブの既知の問題です:

最後に主な原因は、私は二重のアスタリスク(* /)に含まkarma.configのglobパターンを使用した場合ように見えました2番目のレベルより深く進んだフォルダに保存します。

次に、node-globを直接使用してエラーを複製して、同じエラーを生成しました。

最後に、glob.syncルートを使用してURL配列を作成すると、問題が解決しました。うまくいけば、これは著者が彼が修正するためにできることの手がかりを与える。歓声

代わりにjsdomとglobを使用してください。例えば:

const glob = require('glob'); 
const jsdom = require('jsdom'); 
const chai = require('chai'); 

global.document = jsdom.jsdom(); 
global.window = document.defaultView; 

global.navigator = window.navigator || {}; 
global.Node = window.Node; 
global.addEventListener = window.addEventListener; 
global.MouseEvent = window.MouseEvent; 
global.KeyboardEvent = window.KeyboardEvent; 
global.Event = window.Event; 
global.btoa = window.btoa; 
global.FormData = window.FormData; 
global.FileReader = window.FileReader; 
global.File = window.File; 

window.beforeEach = global.beforeEach; 
window.afterEach = global.afterEach; 
window.before = global.before; 
window.after = global.after; 
window.mocha = true; 

参照

関連する問題