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

Consolidate onBuild tests + verify imagesPath for multiple operating systems #101

Merged

Conversation

gshel
Copy link
Contributor

@gshel gshel commented Nov 15, 2023

Description

Consolidated and added new tests to demonstrate bug where Windows imagesPath contains url-encoded \, caused by path.join() using os specific separator which is escaped \ for windows

Issue Ticket Number

#100

Fixes #100

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • I have followed the contributing guidelines of this project as mentioned in CONTRIBUTING.md
  • I have created an issue ticket for this PR
  • I have checked to ensure there aren't other open Pull Requests for the same update/change?
  • I have performed a self-review of my own code
  • I have run tests locally to ensure they all pass
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes needed to the documentation
Copy link

netlify bot commented Nov 15, 2023

Deploy Preview for netlify-plugin-cloudinary ready!

Name Link
🔨 Latest commit ed164ab
🔍 Latest deploy log https://app.netlify.com/sites/netlify-plugin-cloudinary/deploys/656a4ffb2b02740008a5ed00
😎 Deploy Preview https://deploy-preview-101--netlify-plugin-cloudinary.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@colbyfayock
Copy link
Collaborator

hey @gshel changes generally look good! looks like it's running into a little issue though

are you able to see the logs? https://github.com/cloudinary-community/netlify-plugin-cloudinary/actions/runs/6885078686/job/18751733492?pr=101

@gshel
Copy link
Contributor Author

gshel commented Nov 16, 2023

hey @gshel changes generally look good! looks like it's running into a little issue though

are you able to see the logs? https://github.com/cloudinary-community/netlify-plugin-cloudinary/actions/runs/6885078686/job/18751733492?pr=101

I can, thanks @colbyfayock! Looks like I've got some work to do on the win32 stuff. Is it possible that the tests were run on my first commit? I was trying to demonstrate that there were issues but a later commit included the fix. Here are my results locally:

image

I see that there is a posix test failing when imagesPath = '/images/nest'. I did some testing locally and it looks like if imagesPath is passed in as a string, it will always end up as /images regardless of the user input. Is this expected?

@colbyfayock
Copy link
Collaborator

definitely not expected! that may be a regression then? as it did work at one point. i dont currently have a test for that it seems

@gshel
Copy link
Contributor Author

gshel commented Nov 16, 2023

I crack myself up. I wrote tests to catch issues caused by using path.sep and then proceeded to use path.sep IN the tests 😶‍🌫️

…string or list, if undefined default to `/images`

* Fixes issue wherein, if input imagesPath was a string, it would always use `/images`. This prevented users from specifying `/notimages` and `images/specificsubfolder` as their input imagesPath
@gshel
Copy link
Contributor Author

gshel commented Nov 16, 2023

Okey doke I think it should be ready to pass all the tests now 🤞

I fixed the issue where imagesPath would ignore the user input['imagesPath'] if it was a string, and instead always use /images

I also added tests to make sure that imagesPath will:

  1. default to /images if input.imagesPath is undefined.
    e.g. input['imagesPath'] === undefined
    -> imagesPath = '/images'
  2. use full value of input.imagesPath if it is defined as a string
    e.g. input['imagesPath'] === '/babygoats/here'
    -> imagesPath = '/babygoats/here'

There's quite a bit in this one PR; if you'd prefer I'd be happy to split it into separate PRs.

Thanks @colbyfayock !

imagesPath = CLOUDINARY_ASSET_DIRECTORIES.find(
({ inputKey }) => inputKey === 'imagesPath',
)?.path,
imagesPath = inputs.imagesPath || '/images',
Copy link
Collaborator

Choose a reason for hiding this comment

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

looking at this again - the intent for using CLOUDINARY_ASSET_DIRECTORIES was so that i could define the different configurations for different asset types in one location

for instance, in the future there could be a second object in CLOUDINARY_ASSET_DIRECTORIES with a name of videos

im kind of surprised the default wasn't working properly as the code seems to run fine

image

can we keep the default value but use the inputs first if available like you have?

Copy link
Contributor Author

@gshel gshel Nov 30, 2023

Choose a reason for hiding this comment

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

Heya!

im kind of surprised the default wasn't working properly as the code seems to run fine

I was surprised also, but I noticed the bug when testing locally and wrote two tests to confirm it.

To reproduce on the main branch:

  1. ✅ Run all tests successfully
    pnpm -r test
    
  2. ✏️ Change line 129 of on-build.test.js to a string that is not /images
    const imagesPath = '/notimages'
    
  3. ❌ Run all tests again; the test should create redirects with defaut fetch-based configuration in deploy preview context will fail.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we keep the default value but use the inputs first if available like you have?

I'll look into this now~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@colbyfayock
Copy link
Collaborator

just one more question on the default value update!

* CLOUDINARY_ASSET_DIRECTORIES is meant to contain configurations for various asset types in one location
@colbyfayock
Copy link
Collaborator

thanks @gshel!

@colbyfayock colbyfayock merged commit 90b20bd into cloudinary-community:main Dec 4, 2023
8 checks passed
github-actions bot pushed a commit that referenced this pull request Dec 4, 2023
# [1.16.0](v1.15.0...v1.16.0) (2023-12-04)

### Features

* Consolidate onBuild tests + verify imagesPath for multiple operating systems ([#101](#101)) ([90b20bd](90b20bd)), closes [#100](#100) [#100](#100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants