Angular-CLI(ベータ20)でAngular2プロジェクトをビルドしました。angle-cliで1つのテスト仕様を実行する方法
選択した1つのスペックファイルに対してのみテストを実行する方法はありますか。
私はAngular2クイックスタートに基づいてプロジェクトを作成していましたが、手動でジャスミンファイルに仕様を追加することができました。しかし、私はカルマテストのような外部設定方法や、カルマテストをangle-cliビルドのあるファイルに限定する方法を知らない。
Angular-CLI(ベータ20)でAngular2プロジェクトをビルドしました。angle-cliで1つのテスト仕様を実行する方法
選択した1つのスペックファイルに対してのみテストを実行する方法はありますか。
私はAngular2クイックスタートに基づいてプロジェクトを作成していましたが、手動でジャスミンファイルに仕様を追加することができました。しかし、私はカルマテストのような外部設定方法や、カルマテストをangle-cliビルドのあるファイルに限定する方法を知らない。
あなた.spec.ts
ファイルのそれぞれが、このようなdescribe
ブロックにグループ化されたすべてのテストを持っている:
describe('SomeComponent',() => {...}
を簡単にf
でdescribe
関数名を付けることによって、ちょうどこの単一のブロックを実行することができます。
fdescribe('SomeComponent',() => {...}
このような機能をお持ちの場合は、describe
ブロックはありません走る Btw。 it
=>fit
と同様のことをすることができますし、 "ブラックリスト"バージョン - x
もあります。だから、:
fdescribe
とfit
はのみ機能がxdescribe
とxit
を実行するには、この方法は、すべてが、機能は、私は自分のためにこの問題を解決しを実行するには、この方法をマーク引き起こしマーク原因不平を言う。私は以下のような不快なスクリプトを持っています。スクリプトが実行するのは、特定のテストのコマンドラインパラメータを実行して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']);
};
https://jasmine.github.io/api/2.8/global.html#fdescribe – hkievet