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 filename glob #85

Closed
wants to merge 3 commits into from

Conversation

IanVS
Copy link
Contributor

@IanVS IanVS commented Oct 18, 2022

Maybe I'm using this wrong, but I would expect the test in this PR to pass. And in fact I have this kind of situation in my storybook PR that is failing as well, which is why I figured I'd put this together and find out whether it's a bug.

I also added jest to devDependencies, since I wasn't able to run the tests without it.

@thecodrr
Copy link
Owner

thecodrr commented Oct 19, 2022

I tested around and this can easily be fixed by setting basename property to true in the picomatch matcher function. This effectively makes the glob matcher to match against base names in addition to full paths. This also allows picomatch to match against non-full paths (relative paths, filenames etc.). I think we can make it the default until #81 is merged which adds a new method that exposes the internal picomatch options.

@IanVS
Copy link
Contributor Author

IanVS commented Oct 19, 2022

Thanks for taking a look. I suppose for now, I can just add the crawl path to the start of my globs, right?

Edit, nope, that works in some cases, but not all. Maybe not with symlinks, since it seems to be failing for me with a glob like /Users/ianvs/code/storybook/storybook/sandbox/react-vite-default-js/template-stories/**/*.stories.@(js|jsx|ts|tsx|mdx) (see #23 (comment))

@thecodrr
Copy link
Owner

thecodrr commented Aug 6, 2023

@IanVS

After v6.0.2, this test now passes as follows:

  const api = new fdir()
    .withBasePath()
    .globWithOptions(["a.js"], { basename: true })
    .crawl("__tests__/fixtures");
  const files = await api.withPromise();
  expect(files).toEqual(["__tests__/fixtures/a.js"]);

or as follows:

  const api = new fdir()
    .withBasePath()
    .glob("**/a.js")
    .crawl("__tests__/fixtures");
  const files = await api.withPromise();
  expect(files).toEqual(["__tests__/fixtures/a.js"]);

@IanVS
Copy link
Contributor Author

IanVS commented Sep 5, 2023

Awesome, I'll close this out then, thanks!

@IanVS IanVS closed this Sep 5, 2023
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