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

Img conflict name #3157

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Img conflict name #3157

wants to merge 3 commits into from

Conversation

aarbi
Copy link
Contributor

@aarbi aarbi commented Nov 9, 2021

fixes #3156

@aarbi
Copy link
Contributor Author

aarbi commented Nov 9, 2021

the hashes are different from what I got in my local machine.
I haven't found a method in the File class that supports fuzzy search.

I will start by getting the hashes of files generated on the Github actions environement and stick them in the tests.
if this is not good enough, I will add a helped function that uses fs-extra to do something like this:

/**
 * Finds the files in a folder that have a given file name and extension.
 * This helps when looking for files generated by webpack with hashes
 *
 * @param {string} path
 * @param {string} fileName
 * @param {string} extension
 * @returns
 */
export async function filesFoundInFolder(path, fileName, extension) {
	const filesInFolder = await fs.readdir(path);
	const filteredFiles = filesInFolder.filter(
		f => f.startsWith(fileName) && f.endsWith(extension)
	);

	return filteredFiles;
}

Then within the test, we can check the length of the returned array like so:

t.true(File.exists(`test/fixtures/app/dist/images/img.66162.svg`));
becomes:
t.true( (await filesFoundInFolder('test/fixtures/app/dist/images/', 'img', 'svg')).length == 1 );

@aarbi aarbi force-pushed the img-conflict-name branch 2 times, most recently from 721ac5a to 4a4c5e7 Compare November 10, 2021 01:04
@aarbi
Copy link
Contributor Author

aarbi commented Nov 10, 2021

So webpack hashes aren't generated based on the absolute paths, but from the where the root dir of the project. Which means that the hashes are consistent if the test are run in local and github actions. I set the exact has I had in local and it works now in Github. It didn't work earlier to me because I used 6 chars instead of 8

@aarbi aarbi force-pushed the img-conflict-name branch 2 times, most recently from 15c7843 to 5359bd3 Compare November 10, 2021 09:23
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.

Bundling images with the same file name but with different paths causes an error
2 participants