Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pickle_filter: use absolute paths #962

Merged
merged 3 commits into from
Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/pickle_filter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import _ from 'lodash'
import path from 'path'
import { TagExpressionParser } from 'cucumber-tag-expressions'

const FEATURE_LINENUM_REGEXP = /^(.*?)((?::[\d]+)+)?$/
Expand All @@ -20,7 +21,7 @@ export default class PickleFilter {
featurePaths.forEach(featurePath => {
const match = FEATURE_LINENUM_REGEXP.exec(featurePath)
if (match) {
const uri = match[1]
const uri = path.resolve(match[1])
const linesExpression = match[2]
if (linesExpression) {
if (!mapping[uri]) {
Expand All @@ -47,7 +48,7 @@ export default class PickleFilter {
}

matchesAnyLine({ pickle, uri }) {
const lines = this.featureUriToLinesMapping[uri]
const lines = this.featureUriToLinesMapping[path.resolve(uri || '')]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a test fail if the || '' is removed? I don't understand why that is needed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resolve requires a string argument, could rewrite as:

const lines = this.featureUriToLinesMapping[uri ? path.resolve(uri) : undefined]

or just return true if uri is undefined, which is the case when running with a line that does not exist

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't think of a case where this function would be called without a uri though.

Copy link
Contributor Author

@mmuller99 mmuller99 Oct 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uri is undefined during all of the line, name, and tag filters tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auhh. Can you please update the unit tests so a uri is always passed in? I'd prefer not to have the || '' since in real use I expect the uri to always be there

if (lines) {
return _.size(_.intersection(lines, _.map(pickle.locations, 'line'))) > 0
} else {
Expand Down
26 changes: 26 additions & 0 deletions src/pickle_filter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ describe('PickleFilter', function() {
})
})
})

describe('scenario line using current directory path representation', function () {
beforeEach(function() {
this.input.uri = './features/b.feature'
})

describe('scenario line matches', function() {
beforeEach(function() {
this.input.pickle.locations = [{ line: 1 }]
})

it('returns true', function() {
expect(this.pickleFilter.matches(this.input)).to.be.true
})
})

describe('scenario line does not match', function() {
beforeEach(function() {
this.input.pickle.locations = [{ line: 3 }]
})

it('returns false', function() {
expect(this.pickleFilter.matches(this.input)).to.be.false
})
})
})
})

describe('name filters', function() {
Expand Down