From d6aebbad6e9b191fef141472887637ee4318438e Mon Sep 17 00:00:00 2001 From: Nick Tomlin Date: Wed, 30 Sep 2015 21:44:19 -0500 Subject: [PATCH] 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. --- lib/configParser.js | 16 +++++++++++----- spec/unit/config_test.js | 12 ++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/configParser.js b/lib/configParser.js index 828e75228..b76a418a1 100644 --- a/lib/configParser.js +++ b/lib/configParser.js @@ -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); } diff --git a/spec/unit/config_test.js b/spec/unit/config_test.js index 15c655657..9a51a704e 100644 --- a/spec/unit/config_test.js +++ b/spec/unit/config_test.js @@ -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$/); + }); }); });