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

Commit d6aebba

Browse files
NickTomlinjuliemr
authored andcommitted
fix(config): Fixes absolute path parsing in windows
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.
1 parent e013dba commit d6aebba

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/configParser.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,23 @@ ConfigParser.resolveFilePatterns =
9898
for (var i = 0; i < patterns.length; ++i) {
9999
// Cucumber allows running a spec given a line number. See
100100
// https://github.com/angular/protractor/issues/2413
101-
var fileName = patterns[i].split(':')[0],
102-
lineNumber = patterns[i].split(':')[1],
103-
matches = glob.sync(fileName, {cwd: cwd});
101+
var lineNumber = '';
102+
var parsedPath = path.parse(patterns[i]);
103+
parsedPath.base = parsedPath.base.replace(/:\d+/, function (match) {
104+
lineNumber = match;
105+
return '';
106+
});
107+
108+
var filePath = path.format(parsedPath);
109+
var matches = glob.sync(filePath, {cwd: cwd});
104110

105111
if (!matches.length && !opt_omitWarnings) {
106112
log.warn('pattern ' + patterns[i] + ' did not match any files.');
107113
}
108114
for (var j = 0; j < matches.length; ++j) {
109115
var resolvedPath = path.resolve(cwd, matches[j]);
110-
if(lineNumber) {
111-
resolvedPath += ':' + lineNumber;
116+
if (lineNumber) {
117+
resolvedPath += lineNumber;
112118
}
113119
resolvedFiles.push(resolvedPath);
114120
}

spec/unit/config_test.js

+12
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,17 @@ describe('the config parser', function() {
6262
expect(specs[0].indexOf(path.normalize('unit/data/fakespecA.js'))).not.toEqual(-1);
6363
expect(specs[1].indexOf(path.normalize('unit/data/fakespecB.js'))).not.toEqual(-1);
6464
});
65+
66+
it('should allow for line numbers in file paths', function() {
67+
spyOn(process, 'cwd').and.returnValue(__dirname + '/');
68+
var toAdd = {
69+
specs: ['data/fakespecA.js:32', 'data/fakespecB.js']
70+
};
71+
var config = new ConfigParser().addConfig(toAdd).getConfig();
72+
var specs = ConfigParser.resolveFilePatterns(config.specs);
73+
expect(specs.length).toEqual(2);
74+
expect(specs[0].indexOf(path.normalize('unit/data/fakespecA.js:32'))).not.toEqual(-1);
75+
expect(specs[1]).toMatch(/unit\/data\/fakespecB.js$/);
76+
});
6577
});
6678
});

0 commit comments

Comments
 (0)