शायद सबसे सुरुचिपूर्ण समाधान चांदा के कोड को बदलने के लिए किया जाएगा। लेकिन पुस्तकालय को अपग्रेड करने के लिए आवश्यक होने पर यह समस्याग्रस्त हो सकता है।
मैं सजावटी प्रोटैक्टर के द्वारा का वर्णन करके एक समाधान समाधान के साथ आया था। एकमात्र चेतावनी यह है कि इसे स्पेक कोड को सही ढंग से इंडेंट करने की आवश्यकता होती है। असल में इस सीमा को एक फीचर के रूप में माना जा सकता है, क्योंकि निश्चित रूप से कोड सही ढंग से इंडेंट करने के लिए एक अच्छा अभ्यास है और वर्तमान आईडीई के साथ यह केवल 2-सेकंड-कार्य है। आप require('./protractor-decorator').resetCounter();
पर कॉल करके काउंटर को रीसेट कर सकते हैं (उदा। प्रत्येक spec की शुरुआत में)।
अद्यतन
आप it
सिर्फ it = require('./protractor-decorator.js').decorateUsingErrorStack(it);
फोन या एक ही विधि में यह refactor को सजाने के लिए चाहते हैं।
चांदा-decorator.js मॉड्यूल:
var stack = [];
var lastIndentColumn = 1;
function decorateUsingErrorStack(origDescribe){
function describe(){
var callerIndent, args;
if(stack.length === 0){
stack.push(0);
}
// from current stack we get the information about indentation of the code
callerIndent = new Error().stack.split('\n')[2].split(':');
callerIndent = parseInt(callerIndent[callerIndent.length-1]);
if(callerIndent == lastIndentColumn){
stack[stack.length-1] += 1;
}
else {
if(callerIndent < lastIndentColumn){
stack.pop();
stack[stack.length-1] += 1;
}
else {
stack.push(1);
}
}
lastIndentColumn = callerIndent;
args = Array.prototype.slice.call(arguments, 0);
origDescribe.call(null, stack.join('.') + '. ' + args[0], args[1]);
}
return describe;
}
module.exports = {
decorateUsingErrorStack : decorateUsingErrorStack,
resetCounter : function(){
// this function should be called to start counting from 1.
stack = [];
lastIndentColumn = 1;
}
}
कल्पना।js फ़ाइल:
describe = require('./protractor-decorator.js').decorateUsingErrorStack(describe);
describe(' should be 1.', function(){
describe('should be 1.1.', function(){
it('xxx', function(){
});
describe('should be 1.1.1.', function(){
it('xxx', function(){
});
describe('should be 1.1.1.1', function(){
it('xxx', function(){
});
});
describe('should be 1.1.1.2', function(){
it('xxx', function(){
});
});
});
describe('should be 1.1.2.', function(){
it('xxx', function(){
});
});
});
describe('should be 1.2.', function(){
it('xxx', function(){
});
});
describe('should be 1.3.', function(){
it('xxx', function(){
});
});
});
// same as above but all starts with 2.
describe(' should be 2.', function(){...});
स्रोत
2014-10-23 20:35:39
आपके सुझाव के लिए धन्यवाद। ब्याज से आपको लगता है कि यह एक ऐसी सुविधा है जिसे सीधे जैस्मीन स्पेक रिपोर्टर में जोड़ा जा सकता है? मुझे कस्टम प्रोसेसर के विचार पसंद हैं लेकिन अगर यह कॉन्फ़िगरेशन सुविधाओं के रूप में उपलब्ध थे तो यह आगे बढ़ना आसान होगा। धन्यवाद –
मैं कॉन्फ़िगरेशन विकल्पों की मात्रा को सीमित करने का प्रयास करता हूं, उस कारण से कस्टम प्रोसेसर पेश किए गए थे। लेकिन आप सही हैं, यह विकल्प अन्य उपयोगकर्ताओं के लिए उपयोगी हो सकता है। मैं इसे एक कॉन्फ़िगरेशन फीचर के रूप में जोड़ रहा हूं। –
मैंने तदनुसार अपना जवाब अपडेट किया है। –