2016-11-18 6 views
14

Angular-CLI(ベータ20)でAngular2プロジェクトをビルドしました。angle-cliで1つのテスト仕様を実行する方法

選択した1つのスペックファイルに対してのみテストを実行する方法はありますか。

私はAngular2クイックスタートに基づいてプロジェクトを作成していましたが、手動でジャスミンファイルに仕様を追加することができました。しかし、私はカルマテストのような外部設定方法や、カルマテストをangle-cliビルドのあるファイルに限定する方法を知らない。

答えて

50

あなた.spec.tsファイルのそれぞれが、このようなdescribeブロックにグループ化されたすべてのテストを持っている:

describe('SomeComponent',() => {...}

を簡単にfdescribe関数名を付けることによって、ちょうどこの単一のブロックを実行することができます。

fdescribe('SomeComponent',() => {...}

このような機能をお持ちの場合は、describeブロックはありません走る Btw。 it =>fitと同様のことをすることができますし、 "ブラックリスト"バージョン - xもあります。だから、:

  • fdescribefitのみ機能が
  • xdescribexitを実行するには、この方法は、すべてが、機能は、私は自分のためにこの問題を解決し
+0

https://jasmine.github.io/api/2.8/global.html#fdescribe – hkievet

1

を実行するには、この方法をマーク引き起こしマーク原因不平を言う。私は以下のような不快なスクリプトを持っています。スクリプトが実行するのは、特定のテストのコマンドラインパラメータを実行してtest.tsのコピーを作成し、この特定のテスト名をそこに格納することです。これを実行するに

、最初に使用した作男-CLIをインストールします。

npm install -g grunt-cli 

あなたのpackage.jsonでイサキの依存関係の下に置く:

"grunt": "^1.0.1", 
"grunt-contrib-clean": "^1.0.0", 
"grunt-contrib-copy": "^1.0.0", 
"grunt-exec": "^2.0.0", 
"grunt-string-replace": "^1.3.1" 

Gruntfileとして以下のイサキファイルを保存し、それを実行するには.jsをルートフォルダに追加します。コマンドラインから次のように実行します。

grunt --target=app.component 

これはapp.component.spec.tsを実行します。

うなり声のファイルは以下の通りです:

/* 
This gruntfile is used to run a specific test in watch mode. Example: To run app.component.spec.ts , the Command is: 
grunt --target=app.component 
Do not specific .spec.ts. If no target is specified it will run all tests. 
*/ 
module.exports = function(grunt) { 
var target = grunt.option('target') || ''; 
    // Project configuration. 
    grunt.initConfig({ 
    pkg: grunt.file.readJSON('package.json'), 
    clean: ['temp.conf.js','src/temp-test.ts'], 
    copy: { 
     main: { 
     files: [ 
      {expand: false, cwd: '.', src: ['karma.conf.js'], dest: 'temp.conf.js'}, 
      {expand: false, cwd: '.', src: ['src/test.ts'], dest: 'src/temp-test.ts'} 
      ], 
     } 
    }, 
    'string-replace': { 
      dist: { 
      files: { 
       'temp.conf.js': 'temp.conf.js', 
       'src/temp-test.ts': 'src/temp-test.ts' 
      }, 
      options: { 
       replacements: [{ 
       pattern: /test.ts/ig, 
       replacement: 'temp-test.ts' 
       }, 
       { 
       pattern: /const context =.*/ig, 
       replacement: 'const context = require.context(\'./\', true, /'+target+'\\\.spec\\\.ts$/);' 
       }] 
      } 
     } 
    }, 
    'exec': { 
     sleep: { 
      //The sleep command is needed here, else webpack compile fails since it seems like the files in the previous step were touched too recently 
      command: 'ping 127.0.0.1 -n 4 > nul', 
      stdout: true, 
      stderr: true 
     }, 
     ng_test: { 
      command: 'ng test --config=temp.conf.js', 
      stdout: true, 
      stderr: true 
     } 
    } 
    }); 

    // Load the plugin that provides the "uglify" task. 
    grunt.loadNpmTasks('grunt-contrib-clean'); 
    grunt.loadNpmTasks('grunt-contrib-copy'); 
    grunt.loadNpmTasks('grunt-string-replace'); 
    grunt.loadNpmTasks('grunt-exec'); 
    // Default task(s). 
    grunt.registerTask('default', ['clean','copy','string-replace','exec']); 

}; 
+0

受け入れソリューションを見て、私はこの方法があるとは思いません – Ryan

+0

@Brian - 私の解決策は、ソースコードを変更する必要がないため、ファイルをチェックインする際の間違いを防ぐことができます。私の解決策では、手動の手順を自動化することで、コマンドラインでテスト名を指定することができます。 – vanval

+0

ええ、それは実際には良い点です。あなたはxdescribeやfdescribeを削除することを忘れる可能性があり、あなたのテストは完全に削除されます。 – Ryan

関連する問題