2016-11-18 17 views
14

के साथ केवल एक टेस्ट स्पेक निष्पादित करने के लिए मेरे पास कोणीय-सीएलआई (बीटा 20) के साथ कोणीय 2 प्रोजेक्ट का निर्माण है।कोणीय-क्ली

क्या केवल एक चयनित स्पेक फ़ाइल के खिलाफ परीक्षण चलाने का कोई तरीका है।

मेरे पास Angular2 त्वरित प्रारंभ के आधार पर एक प्रोजेक्ट होता था, और मैं मैन्युअल रूप से चमेली फ़ाइल में चश्मा जोड़ सकता था। लेकिन मुझे नहीं पता कि कर्म परीक्षण के बाहर या कोणीय-क्ली बिल्ड के साथ कुछ फाइलों में कर्म परीक्षणों को कैसे सीमित किया जाए। f साथ

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

आप आसानी से सिर्फ इस खंड चला सकते हैं, describe समारोह नाम लगाकर द्वारा:

उत्तर

50

अपने .spec.ts फ़ाइल में से प्रत्येक की सभी परीक्षणों इस तरह describe ब्लॉक में वर्गीकृत किया है

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

यदि आपके पास ऐसा कार्य है, तो कोई अन्य describe ब्लॉक नहीं होगा चलाते हैं। बीटीडब्ल्यू। आप it =>fit के साथ समान काम कर सकते हैं और एक "ब्लैकलिस्ट" संस्करण भी है - x। तो:

  • fdescribe और fit का कारण बनता है केवल कार्यों
  • xdescribe और xit का कारण बनता है सब लेकिन कार्यों
+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

@ ब्रायन - मेरा समाधान स्रोत कोड को संशोधित करने से बचाता है और इसलिए फ़ाइल में जांचने में संभावित गलतियों को रोकता है। मेरा समाधान मैन्युअल चरणों को स्वचालित करके कमांड लाइन पर परीक्षण नाम निर्दिष्ट करने में सक्षम बनाता है। – vanval

+0

हाँ, यह वास्तव में एक अच्छा मुद्दा है। एक अच्छा मौका है कि आप xdescribe या fdescribe को हटाने के लिए भूल सकते हैं - और आपके परीक्षण को हटा दिया जाएगा! – Ryan