Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(config): Fixes absolute path parsing in windows
Browse files Browse the repository at this point in the history
This allows absolute paths absolute paths in to be properly parsed in windows.
This should maintain the line-number feature introduced in ff88e without
breakage.
  • Loading branch information
NickTomlin authored and juliemr committed Oct 2, 2015
1 parent e013dba commit d6aebba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/configParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,23 @@ ConfigParser.resolveFilePatterns =
for (var i = 0; i < patterns.length; ++i) {
// Cucumber allows running a spec given a line number. See
// https://github.com/angular/protractor/issues/2413
var fileName = patterns[i].split(':')[0],
lineNumber = patterns[i].split(':')[1],
matches = glob.sync(fileName, {cwd: cwd});
var lineNumber = '';
var parsedPath = path.parse(patterns[i]);
parsedPath.base = parsedPath.base.replace(/:\d+/, function (match) {
lineNumber = match;
return '';
});

var filePath = path.format(parsedPath);
var matches = glob.sync(filePath, {cwd: cwd});

if (!matches.length && !opt_omitWarnings) {
log.warn('pattern ' + patterns[i] + ' did not match any files.');
}
for (var j = 0; j < matches.length; ++j) {
var resolvedPath = path.resolve(cwd, matches[j]);
if(lineNumber) {
resolvedPath += ':' + lineNumber;
if (lineNumber) {
resolvedPath += lineNumber;
}
resolvedFiles.push(resolvedPath);
}
Expand Down
12 changes: 12 additions & 0 deletions spec/unit/config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,17 @@ describe('the config parser', function() {
expect(specs[0].indexOf(path.normalize('unit/data/fakespecA.js'))).not.toEqual(-1);
expect(specs[1].indexOf(path.normalize('unit/data/fakespecB.js'))).not.toEqual(-1);
});

it('should allow for line numbers in file paths', function() {
spyOn(process, 'cwd').and.returnValue(__dirname + '/');
var toAdd = {
specs: ['data/fakespecA.js:32', 'data/fakespecB.js']
};
var config = new ConfigParser().addConfig(toAdd).getConfig();
var specs = ConfigParser.resolveFilePatterns(config.specs);
expect(specs.length).toEqual(2);
expect(specs[0].indexOf(path.normalize('unit/data/fakespecA.js:32'))).not.toEqual(-1);
expect(specs[1]).toMatch(/unit\/data\/fakespecB.js$/);
});
});
});

0 comments on commit d6aebba

Please sign in to comment.