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

Add failing test for root + absolute option #294

Closed
wants to merge 3 commits into from

Conversation

phated
Copy link
Contributor

@phated phated commented Sep 20, 2016

Hey @isaacs - with the absolute option feature, I encountered a problem that I've created a failing test for. I am still digging into a solution but I thought I'd get this test in front of you incase you have a better idea of what is happening.

Side note: I have a commented out test using t.like which was passing, not sure if I stumbled on a node-tap bug while working on this.

@phated
Copy link
Contributor Author

phated commented Sep 20, 2016

Interesting that this passes on Windows. That's extra confusing for me.

@phated
Copy link
Contributor Author

phated commented Sep 20, 2016

I think I have a partial solution (separate commit) but found another problem and added a failing test.

@phated
Copy link
Contributor Author

phated commented Sep 20, 2016

I think this actually might a symptom of a deeper problem with makeAbs because it seems _emitMatch is always receiving matches as absolute when the root option is set and caching results based on something like /Users/phated/node-glob/test/fixtures/a/Users/phated/node-glob/test/fixtures/a/b which seems to be wrong.

@phated
Copy link
Contributor Author

phated commented Sep 20, 2016

Rebased with possible fixes. I have a TODO comment because I don't know the answer to:

is an absolute cwd supposed to be resolved against root?
e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')

@phated
Copy link
Contributor Author

phated commented Sep 20, 2016

Hmm, broke something else on Windows.

@phated
Copy link
Contributor Author

phated commented Sep 20, 2016

Yay, passing tests! I'm not sure if everything I did to get these tests passing is kosher or even that the tests are written correctly, but it seems to be doing the right thing in the few narrow cases I came up with.

Can you think of a better way to write the cacheCheck tests to verify the paths being cached actually exist and isn't suffering from this joining of 2 absolute paths?

'/Users/phated/node-glob/test/fixtures/a/bc/e',
'/Users/phated/node-glob/test/fixtures/a/bc/e/f' ]
*/
// t.like(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
Copy link
Owner

Choose a reason for hiding this comment

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

Ha! Yes, this is because t.like does substring matching. So, t.like('hamburger', 'amburg') passes. Calling t.like(array, otherArray) does a t.like on the elements, so t.like(['hamburger'], ['amburg']) would also pass. tap is working as designed, but I'm using it wrong here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alright, I'll update the tests in this file to use t.same

// t.like(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
// return path.join(path.resolve('a'), m).replace(/\\/g, '/')
// }))
t.same(matches, [ '/b', '/b/c', '/b/c/d', '/bc', '/bc/e', '/bc/e/f' ].map(function (m) {
Copy link
Owner

Choose a reason for hiding this comment

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

t.same is the right thing to use here.

self.cwdAbs = makeAbs(self, self.cwd)
// TODO: is an absolute `cwd` supposed to be resolved against `root`?
// e.g. { cwd: '/test', root: __dirname } === path.join(__dirname, '/test')
self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd)
Copy link
Owner

Choose a reason for hiding this comment

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

This seems like a reasonable fix. We do need makeAbs to mount onto the root, if one is specified, so that /a/* maps onto {root}/a/b. But using cwd and root together is just... kinda weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, how should I go about resolving this then? If makeAbs is used, it appends an absolute path to an absolute root resulting in something like /Users/phated/node-glob/test/Users/phated/node-glob/test/fixtures

@phated
Copy link
Contributor Author

phated commented Sep 29, 2016

@isaacs sorry to ping again but I'd like to get this resolved in some way so I can land the usage in glob-stream

@isaacs isaacs closed this in b2aa29b Sep 29, 2016
@isaacs
Copy link
Owner

isaacs commented Sep 29, 2016

Thanks! this'll go out in the next release. I also wanna fix the thing with the stat errors on Windows, in #245.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants