Skip to content

Conversation

@Hugo-RM
Copy link
Contributor

@Hugo-RM Hugo-RM commented Jan 17, 2026

Fixes #3761
Fixes #3762

Changes

  • Fixes bug where p5Versions containing objects caused URL version parsing to fail
  • Migrates parseUrlParams and test file to TypeScript

Testing

  • Added tests for version patterns
  • Verified invalid inputs properly fall back to defaults
  • Tests use regex assertions and validity checks to ensure only valid versions are returned

Testing Strategy Note

The version parsing tests use regex patterns (e.g., /^1\.\d+\.\d+$/) rather than hardcoded expected versions (e.g., '1.11.11'). This approach:

  • Validates that the correct version prefix is returned
  • Verifies the result is a valid version from p5VersionStrings
  • Avoids test failures when new p5.js versions are released

Alternative approach: Tests could assert exact versions (e.g., expect(result.version).toBe('1.11.11')), which would catch sorting bugs but require updates whenever p5Versions changes.

Sorting bugs are very unlikely to occur unless version numbers change drastically. Current tests simply attempt to prevent future silent errors.

I'm happy to switch to hardcoded assertions or explore other testing strategies if you have suggestions!

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • has no typecheck errors (npm run typecheck)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123
  • meets the standards outlined in the accessibility guidelines

Updated parseVersionString to handle object format instead of
assuming string format.
- Add regression tests for major/major.minor version patterns
- Add tests for invalid input fallback behavior
- Migrate test file to TypeScript
- Export p5VersionStrings from parseUrlParams for test validation
- Use regex assertions to avoid breaking when p5Versions updates
@welcome
Copy link

welcome bot commented Jan 17, 2026

🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already.

return typeof item === 'string' ? item : item.version;
}

export const p5VersionStrings = p5Versions.map(getVersionString);
Copy link
Collaborator

@clairep94 clairep94 Jan 19, 2026

Choose a reason for hiding this comment

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

Is this being called anywhere else? Otherwise we can probably keep it local and not export it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only used in the parseURLParams.test.ts file. I can move it to be local if preferred. It's a small bit of code so I wasn't sure if I should avoid code duplication or not.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! thanks for doing this

}

export function parseUrlParams(url) {
export function parseUrlParams(url: string): ParsedUrlParams {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add JSDocs for what this function is for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do so.

@clairep94
Copy link
Collaborator

Looks great, thanks for migrating this! Just some small comments 🙏

@clairep94 clairep94 added the Area: Typescript Migration Related to Typescript Migration after the initial pr05 grant 2025 migration work label Jan 19, 2026
Comment on lines 42 to 43
const bad = parseUrlParams('https://example.com?version=9.9.9');
expect(bad.version).toBe(currentP5Version);

Choose a reason for hiding this comment

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

The invalid-version test relies on '9.9.9' never becoming a real release. Once p5 publishes that tag, the test will report a failure even though the fallback logic works. Using an obviously invalid token (e.g., 'invalid-version' or a value derived from p5Versions that is guaranteed to be absent) would make the check resilient to future releases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I didn't think about future releases breaking this. I'll update it to use 'invalid-version'.

function getNewestVersion(versions) {
function getVersionString(
item: string | { version: string; label: string }
): string {

Choose a reason for hiding this comment

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

Looks like it can also resolve #3779. Can you help double check it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes the issue is resolved by this.

- Add JSDoc to parseUrlParams
- Remove export from p5VersionStrings and copy its logic to test file
- Fix invalid version test to use 'invalid-version' instead of '9.9.9'
Copy link

@lirenjie95 lirenjie95 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Typescript Migration Related to Typescript Migration after the initial pr05 grant 2025 migration work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

URL version parsing fails for major/major.minor patterns Migrate Version URL Parser to TypeScript

3 participants