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

loki approve fails with "no images found to approve" when fileNameFormatter produces subfolders #317

Open
florian-milky opened this issue Apr 23, 2021 · 11 comments

Comments

@florian-milky
Copy link

loki test returns a bunch of failed tests
when I want to approve all changes with loki approve, it tells me no images found to approve
Why is that?

@techeverri
Copy link
Collaborator

loki test returns a bunch of failed tests
when I want to approve all changes with loki approve, it tells me no images found to **approve**

The code that prints the error is very simple and the only obvious way is that there is no valid PNGs in the output folder

const files = fs.readdirSync(outputDir).filter(isPNG);
if (!files.length) {
die(
'No images found to approve',
'Run update command to generate reference files instead'
);
}

Why is that?

Hard to know without a way to reproduce it.

@florian-milky
Copy link
Author

Thanks @techeverri I'm gonna try to debug it :)

@techeverri
Copy link
Collaborator

If you find a bug please reopen this issue or create a new one 👍

@florian-milky
Copy link
Author

florian-milky commented Apr 23, 2021

@techeverri fs.readdirSync(outputDir) returns only top folders desktop and mobile which are my configurations

/current contains desktop and mobile, images are in these subfolders

Screenshot 2021-04-23 at 11 54 03

My node version is v14.13.1
loki 0.28.0

@techeverri
Copy link
Collaborator

How does your fileNameFormatter look like?
🔗 https://loki.js.org/configuration.html#filenameformatter

Does it happen on Windows, Linux or macOS?

@techeverri techeverri reopened this Apr 23, 2021
@florian-milky
Copy link
Author

florian-milky commented Apr 23, 2021

How does your fileNameFormatter look like?

fileNameFormatter: ({ configurationName, kind, story }) => {
    return `${configurationName}/${kind}--${story}`;
  },

I'm on macOS.

Is loki supposed to work well with subdirectories?

I have a script that generates the approve cmd file by file so I fixed that. However I noticed it's a bit confusing because in the story filter I had to replace the -- that I get from the file name with a space.

@techeverri
Copy link
Collaborator

The defaultFileNameFormatter looks like this 👇

const defaultFileNameFormatter = ({ configurationName, kind, story }) =>
slugify(`${configurationName} ${kind} ${story}`, SLUGIFY_OPTIONS);

It doesn't generate subfolders and so fs.readdirSync(outputDir) works as expected with a flat structure

@techeverri
Copy link
Collaborator

techeverri commented Apr 23, 2021

It sounds like we need extra logic in all places that read from outputDir to support when the config has a custom fileNameFormatter

@techeverri techeverri changed the title no images found to approve loki approve fails with "no images found to approve" when fileNameFormatter produces subfolders Apr 23, 2021
@florian-milky
Copy link
Author

It sounds like we need extra logic in all places that read from outputDir to support when the config has a custom fileNameFormatter

Would you recommend keeping a flat structure? I don't think it's a deal breaker, you're not really supposed to browse the images manually anyway

@florian-milky
Copy link
Author

related to #229 I would say

@d8corp
Copy link

d8corp commented Jan 28, 2025

Added a PR to fix approve command with custom fileNameFormatter (for deep file structure)

#532

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

No branches or pull requests

3 participants