More refactoring
This commit is contained in:
41
client/commonFramework/add-test-to-string.js
Normal file
41
client/commonFramework/add-test-to-string.js
Normal file
@@ -0,0 +1,41 @@
|
||||
window.common = (function({ common = { init: [] }}) {
|
||||
|
||||
var BDDregex = new RegExp(
|
||||
'(expect(\\s+)?\\(.*\\;)|' +
|
||||
'(assert(\\s+)?\\(.*\\;)|' +
|
||||
'(assert\\.\\w.*\\;)|' +
|
||||
'(.*\\.should\\..*\\;)/'
|
||||
);
|
||||
|
||||
common.addTestsToString = function(code) {
|
||||
const userTests = [];
|
||||
|
||||
// insert tests from mongo
|
||||
for (var i = 0; i < common.tests.length; i++) {
|
||||
code += '\n' + common.tests[i];
|
||||
}
|
||||
|
||||
var counter = 0;
|
||||
var match = BDDregex.exec(code);
|
||||
|
||||
while (match) {
|
||||
var replacement = '//' + counter + common.salt;
|
||||
code = code.substring(0, match.index) +
|
||||
replacement +
|
||||
code.substring(match.index + match[0].length);
|
||||
|
||||
userTests.push({
|
||||
err: null,
|
||||
text: match[0],
|
||||
line: counter
|
||||
});
|
||||
|
||||
counter++;
|
||||
match = BDDregex.exec(code);
|
||||
}
|
||||
|
||||
return { code, userTests };
|
||||
};
|
||||
|
||||
return common;
|
||||
}(window));
|
Reference in New Issue
Block a user