2016-10-03 6 views
4

Angular2テストでwebpackを設定するにはどうすればよいですか?Angular2テスト用にwebpackを設定するにはどうすればよいですか?

Angular2 npmパッケージをテストするためにwebpackベースの設定をセットアップしました。 とにかく私のようなエラーを得続ける:

Error: This test module uses the component PaginationComponent which is using a "templateUrl", but they were never compiled. Please call "TestBed.compileComponents" before your test. in karma-test-shim.js (line 9952)

をそして、私の意見では、私は右のすべてをした、それが動作するはずです。 htmlscssファイルはwebpackによって読み込まれます。

完全な設定を確認する場合は、GitHubに変更してください。プロジェクトのソースとともに、webpack.test.jskarma.conf.jspackage.jsonがあります。それは小さい - 1つのコンポーネントプロジェクトです。あなたがここにTravis CI

に行くことができ、完全なエラーメッセージについては

webpack構成です:

var path = require('path'); 
var _root = path.resolve(__dirname, '..'); 

module.exports = { 
    devtool: 'inline-source-map', 

    resolve: { 
     extensions: ['', '.ts', '.js', '.json', '.css', '.scss', '.html'] 
    }, 

    module: { 
     loaders: [ 
      { 
       test: /\.ts$/, 
       loaders: ['awesome-typescript-loader', 'angular2-template-loader'] 
      }, 
      { 
       test: /\.html$/, 
       loader: 'html' 
      }, 
      { 
       test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/, 
       loader: 'null' 
      }, 
      { 
       test: /\.json$/, 
       loader: 'json' 
      }, 
      { 
       test: /\.css$/, 
       exclude: root('src'), 
       loader: 'null' 
      }, 
      { 
       test: /\.css$/, 
       include: root('src'), 
       loader: 'raw' 
      }, 
      { 
       test: /\.scss$/, 
       exclude: root('src'), 
       loader: 'null' 
      }, 
      { 
       test: /\.scss$/, 
       include: root('src'), 
       loader: 'raw!postcss!sass' 
      } 
     ] 
    } 
}; 

function root(args) { 
    args = Array.prototype.slice.call(arguments, 0); 
    return path.join.apply(path, [_root].concat(args)); 
} 
+0

seeの1つの問題は '_root'です。あなたは '' .. ''によって解決しています。 Angularの例では、 'config'フォルダに' helpers.js'ファイルがあります。したがって、ルートはレベルアップになります。しかし、あなたのケースでは、ヘルパーファイルのコンテンツを既にルートにある設定ファイルにコピーしただけです。したがって、実際には単一のドットだけを使うべきです。それは本当にそれが問題にすべてに収まるのを理解していない。しかし、問題は、テンプレートファイルが見つからないことが多いようで、多分それは関連しているかもしれません。知りません。私はWebpack –

+0

@peeskilletにあまり流暢ではありませんあなたは正しいですが、これはこれではありません:( – Vardius

+0

私はAngularの文書に基づいて[repo](https://github.com/psamsotha/angular2-webpack)を作成しました。テストして、それがうまくいったので、あなたのプロジェクト構造に合ったものを取り除き、テストしましたが、それでも動作します。それはそれを破る原因になるかもしれません。おそらくあなたは運が良いかもしれません: -/ –

答えて

0

問題は活字体構成としました。

tsconfig.json

{ 
    "compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "moduleResolution": "node", 
    "sourceMap": true, 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "removeComments": false, 
    "noImplicitAny": true, 
    "suppressImplicitAnyIndexErrors": true, 
    "declaration": true, 
    "outDir": "./lib", 
    "noEmitHelpers": false, 
    "isolatedModules": false 
    }, 
    "compileOnSave": false, 
    "buildOnSave": false, 
    "exclude": [ 
    "components.d.ts", 
    "typings/browser.d.ts", 
    "typings/browser", 
    "node_modules", 
    "examples" 
    ] 
} 

IDEインテリセンスがテスト中にエラーをスローするようにWebPACKのをcousingた可能ファイルを、.d.ts *タイピングの生成をトリガwhihオプション"declaration": true

buildを実行しているときにテストしてコメントを外すと、この行がコメントアウトされて解決しました。

関連する問題