Skip to content

Commit

Permalink
version 0.1.17: add data-* attribute support
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonvictor committed Oct 10, 2015
1 parent 0d1bf65 commit ff03a15
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 42 deletions.
84 changes: 43 additions & 41 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var gulpProtractorQA = {
var _this = this,
results,
regexList = _this.ptorFindElements.regex;

// lopp regexlist
for( var i = 0; i<regexList.length; i++ ){
// verify matches
Expand All @@ -35,7 +35,7 @@ var gulpProtractorQA = {
attrName : regexList[i].attrName,
fileName : path
};

_this.ptorFindElements.foundList.push( res );

}
Expand Down Expand Up @@ -77,12 +77,12 @@ var gulpProtractorQA = {

for( var i = 0; i < _this[ collection ].length; i++ ){
var obj = _this[ collection ][i];
if( typeof obj.path != 'undefined' ){
if( filepath.indexOf( obj.path.replace("./", "/") ) >= 0 ){
obj.contents = newContent;
break;
}
}
if( typeof obj.path != 'undefined' ){
if( filepath.indexOf( obj.path.replace("./", "/") ) >= 0 ){
obj.contents = newContent;
break;
}
}
}

// reset foundList and totalNumOfElements
Expand All @@ -103,7 +103,7 @@ var gulpProtractorQA = {
exists = true;
}
}

return exists;
},

Expand All @@ -112,47 +112,49 @@ var gulpProtractorQA = {
var _this = this,
allElementsFound = true;

for( var i = 0; i<foundList.length; i++ ){
for( var i = 0; i < foundList.length; i++ ){

var found = false;
var foundItem = foundList[i];

for(var c = 0; c < _this.viewFiles.length; c++ ){
var obj = _this.viewFiles[c];

$ = cheerio.load( obj.contents );
var selector = '';

if( foundItem.type === "attr" ){
selector = [ '[', foundItem.attrName, '="', foundItem.val, '"]' ].join("");

if( foundItem.attrName === "ng-bind" ){
// search for {{bindings}}
if( _this.bindExists( foundItem.val, obj.contents ) ){
found = true;
}
}

selector = [
'[', foundItem.attrName, '="', foundItem.val, '"], ',
'[data-', foundItem.attrName, '="', foundItem.val, '"]'
].join("");

if( foundItem.attrName === "ng-bind" ){
// search for {{bindings}}
if( _this.bindExists( foundItem.val, obj.contents ) ){
found = true;
}
}
} else if( foundItem.type === "cssAttr" ){
selector = [ '[', foundItem.val, ']' ].join("");
}

if( $( selector ).length ){
if ($(selector).length) {
found = true;
}
}

if( !found ){
if( !found ){
allElementsFound = false;
gutil.log('[' + chalk.cyan(PLUGIN_NAME) + '] ' + chalk.red(foundItem.at) + ' at ' + chalk.bold(foundItem.fileName) + ' not found in view files!');
gutil.log('[' + chalk.cyan(PLUGIN_NAME) + '] ' + chalk.red(foundItem.at) + ' at ' + chalk.bold(foundItem.fileName) + ' not found within view files!');
}

}

if( allElementsFound ){
gutil.log(
'[' + chalk.cyan(PLUGIN_NAME) + '] ' +
chalk.green("all test element found!")
gutil.log(
'[' + chalk.cyan(PLUGIN_NAME) + '] ' +
chalk.green("all test elements were successfully found!")
);
}

Expand All @@ -164,44 +166,44 @@ var gulpProtractorQA = {

// watch test files changes
var gaze = new Gaze(src);
gaze.on('all', function(event, filepath) {
gaze.on('all', function(event, filepath) {
fs.readFile(filepath, 'utf8', function(err, data){
if (err) { throw err };
if (err) { throw err; }
_this.updateFileContents(collection, filepath, data);
});
});


// async map file contents
var async = function async(arg, callback) {
fs.readFile(arg, 'utf8', function (err, data) {
if (err) { throw err };
callback(arg, data);
});
fs.readFile(arg, 'utf8', function (err, data) {
if (err) { throw err; }
callback(arg, data);
});
};

glob.glob(src, function (er, files) {
files.forEach(function(item) {
async(item, function(filePath, data){
_this[ collection ].push(

_this[ collection ].push(
{
path : filePath,
contents : data
}
);

if( _this[ collection ].length == files.length ) {
_cb();
}
if( _this[ collection ].length == files.length ) {
_cb();
}
});
});
});

},

bindStoreFileContents : function( _callback ){

var _this = this;

_this.storeFileContents( _this.options.testSrc, "testFiles", function(){
Expand All @@ -218,7 +220,7 @@ gulpProtractorQA.init = function( options ){
var globals = gulpProtractorQA;

globals.options = options || {};

if (typeof globals.options.testSrc == 'undefined') {
throw new gutil.PluginError(PLUGIN_NAME, '`testSrc` required');
}
Expand All @@ -228,10 +230,10 @@ gulpProtractorQA.init = function( options ){

globals.bindStoreFileContents(function(){
globals.searchProtractorDotByContents(globals.testFiles, function beforeViewMatches(){
gutil.log( '[' + chalk.cyan(PLUGIN_NAME) + '] ' + chalk.gray( "// " + globals.ptorFindElements.foundList.length + " out of " + globals.totalNumOfElements + " element selectors are been watched" ) );
gutil.log( '[' + chalk.cyan(PLUGIN_NAME) + '] ' + chalk.gray( "// " + globals.ptorFindElements.foundList.length + " out of " + globals.totalNumOfElements + " element selectors are being watched" ) );
});
});

};

// Exporting the plugin main function
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-protractor-qa",
"version": "0.1.16",
"version": "0.1.17",
"description": "Gulp Protractor QA warns you on the fly whether all element() selectors could be found or not within your AngularJS view files.",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit ff03a15

Please sign in to comment.