2017-02-18 20:14:10 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* DO NOT EDIT THIS FILE
|
|
|
|
* For FCC testing purposes!
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
function objParser(str, init) {
|
|
|
|
// finds objects, arrays, strings, and function arguments
|
|
|
|
// between parens, because they may contain ','
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let openSym = ['[', '{', '"', "'", '('];
|
|
|
|
let closeSym = [']', '}', '"', "'", ')'];
|
|
|
|
let type;
|
|
|
|
let i;
|
|
|
|
for(i = (init || 0); i < str.length; i++ ) {
|
2017-02-18 20:14:10 +01:00
|
|
|
type = openSym.indexOf(str[i]);
|
|
|
|
if( type !== -1) break;
|
|
|
|
}
|
|
|
|
if (type === -1) return null;
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let open = openSym[type];
|
|
|
|
let close = closeSym[type];
|
|
|
|
let count = 1;
|
|
|
|
let k;
|
|
|
|
for(k = i+1; k < str.length; k++) {
|
2017-02-18 20:14:10 +01:00
|
|
|
if(open === '"' || open === "'") {
|
|
|
|
if(str[k] === close) count--;
|
|
|
|
if(str[k] === '\\') k++;
|
|
|
|
} else {
|
|
|
|
if(str[k] === open) count++;
|
|
|
|
if(str[k] === close) count--;
|
|
|
|
}
|
|
|
|
if(count === 0) break;
|
|
|
|
}
|
|
|
|
if(count !== 0) return null;
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let obj = str.slice(i, k+1);
|
2017-02-18 20:14:10 +01:00
|
|
|
return {
|
|
|
|
start : i,
|
|
|
|
end: k,
|
|
|
|
obj: obj
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function replacer(str) {
|
|
|
|
// replace objects with a symbol ( __#n)
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let obj;
|
|
|
|
let cnt = 0;
|
|
|
|
let data = [];
|
2017-02-18 20:14:10 +01:00
|
|
|
while(obj = objParser(str)) {
|
|
|
|
data[cnt] = obj.obj;
|
|
|
|
str = str.substring(0, obj.start) + '__#' + cnt++ + str.substring(obj.end+1)
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
str : str,
|
|
|
|
dictionary : data
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function splitter(str) {
|
|
|
|
// split on commas, then restore the objects
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let strObj = replacer(str);
|
|
|
|
let args = strObj.str.split(',');
|
2017-02-18 20:14:10 +01:00
|
|
|
args = args.map(function(a){
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let m = a.match(/__#(\d+)/);
|
2017-02-18 20:14:10 +01:00
|
|
|
while (m) {
|
|
|
|
a = a.replace(/__#(\d+)/, strObj.dictionary[m[1]]);
|
|
|
|
m = a.match(/__#(\d+)/);
|
|
|
|
}
|
|
|
|
return a.trim();
|
|
|
|
})
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
|
|
|
function assertionAnalyser(body) {
|
|
|
|
|
|
|
|
// already filtered in the test runner
|
|
|
|
// // remove comments
|
|
|
|
// body = body.replace(/\/\/.*\n|\/\*.*\*\//g, '');
|
|
|
|
// // get test function body
|
|
|
|
// body = body.match(/\{\s*([\s\S]*)\}\s*$/)[1];
|
|
|
|
|
|
|
|
if(!body) return "invalid assertion";
|
|
|
|
// replace assertions bodies, so that they cannot
|
|
|
|
// contain the word 'assertion'
|
|
|
|
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let cleanedBody = body.match(/(?:browser\s*\.\s*)?assert\s*\.\s*\w*\([\s\S]*\)/)
|
|
|
|
if(cleanedBody && Array.isArray(cleanedBody)) {
|
|
|
|
body = cleanedBody[0];
|
|
|
|
} else {
|
|
|
|
// No assertions present
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
let s = replacer(body);
|
2017-02-18 20:14:10 +01:00
|
|
|
// split on 'assertion'
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let splittedAssertions = s.str.split('assert');
|
|
|
|
let assertions = splittedAssertions.slice(1);
|
2017-02-18 20:14:10 +01:00
|
|
|
// match the METHODS
|
|
|
|
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let assertionBodies = [];
|
|
|
|
let methods = assertions.map(function(a, i){
|
|
|
|
let m = a.match(/^\s*\.\s*(\w+)__#(\d+)/);
|
2017-02-18 20:14:10 +01:00
|
|
|
assertionBodies.push(parseInt(m[2]));
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let pre = splittedAssertions[i].match(/browser\s*\.\s*/) ? 'browser.' : '';
|
2017-02-18 20:14:10 +01:00
|
|
|
return pre + m[1];
|
|
|
|
});
|
|
|
|
if(methods.some(function(m){ return !m })) return "invalid assertion";
|
|
|
|
// remove parens from the assertions bodies
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let bodies = assertionBodies.map(function(b){
|
2017-02-18 20:14:10 +01:00
|
|
|
return s.dictionary[b].slice(1,-1).trim();
|
|
|
|
});
|
|
|
|
assertions = methods.map(function(m, i) {
|
|
|
|
return {
|
|
|
|
method: m,
|
|
|
|
args: splitter(bodies[i]) //replace objects, split on ',' ,then restore objects
|
|
|
|
}
|
|
|
|
})
|
|
|
|
return assertions;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = assertionAnalyser;
|