Skip to content

refactor: convert remaining JavaScript test files to TypeScript #7199

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

Merged
merged 2 commits into from
Apr 16, 2025

Conversation

ndhoule
Copy link
Contributor

@ndhoule ndhoule commented Apr 11, 2025

This changeset converts all remaining JavaScript tests to TypeScript. It's sort of a hack job; I used a bulk converter for most of it, then hand-converted the rest. There's varying degrees of "hey, he did a nice job in this file" and "hey, he did a terrible job in this file," but on the whole this is an improvement.

I also updated all of the import paths in tests from importing transpiled (dist/) code to untranspiled (src/) code. Ergonomically this is better--it's confusing to work on tests that aren't necessarily running code that reflects your edits--but really, I was forced into this by spooky conflicts between transpiled types and untranspiled types.

Copy link

github-actions bot commented Apr 11, 2025

📊 Benchmark results

Comparing with defbb03

  • Dependency count: 1,156 (no change)
  • Package size: 281 MB ⬇️ 0.00% decrease vs. defbb03
  • Number of ts-expect-error directives: 465 ⬆️ 13.98% increase vs. defbb03

@ndhoule ndhoule force-pushed the refactor/convert-js-tests-to-ts branch 11 times, most recently from 8c10307 to 905f9e6 Compare April 15, 2025 22:52
@ndhoule ndhoule marked this pull request as ready for review April 15, 2025 22:52
@ndhoule ndhoule requested a review from a team as a code owner April 15, 2025 22:52
@ndhoule ndhoule force-pushed the refactor/convert-js-tests-to-ts branch 2 times, most recently from 9d8494e to d1afe9f Compare April 15, 2025 23:01
@serhalp serhalp force-pushed the refactor/convert-js-tests-to-ts branch from 9c643db to d1afe9f Compare April 16, 2025 21:16
@ndhoule ndhoule force-pushed the refactor/convert-js-tests-to-ts branch 2 times, most recently from ea835e2 to 7f451f9 Compare April 16, 2025 21:31
Copy link
Collaborator

@serhalp serhalp left a comment

Choose a reason for hiding this comment

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

📉 Amazing, thanks! Nothing blocking

@ndhoule ndhoule force-pushed the refactor/convert-js-tests-to-ts branch 2 times, most recently from 8ad1eaa to 8bf4d2f Compare April 16, 2025 22:19
ndhoule added 2 commits April 16, 2025 15:23
This changeset converts all remaining JavaScript tests to TypeScript.
It's sort of a hack job; I used a bulk converter for most of it, then
hand-converted the rest. There's varying degrees of "hey, he did a nice
job in this file" and "hey, he did a terrible job in this file," but on
the whole this is an improvement.

I also updated all of the import paths in tests from importing
transpiled (`dist/`) code to untranspiled (`src/`) code. Ergonomically
this is better--it's confusing to work on tests that aren't necessarily
running code that reflects your edits--but really, I was forced into
this by spooky conflicts between transpiled types and untranspiled
types.
This removes the `assert` calls we were making in `copyTemplateDir`, as
well as the tests that exercise this behavior. These asserts probably
made more sense in a pre-TypeScript world, but we no longer need them as
TypeScript serves the same purpose.
@ndhoule ndhoule force-pushed the refactor/convert-js-tests-to-ts branch from 8bf4d2f to bd6a26e Compare April 16, 2025 22:23
@ndhoule ndhoule merged commit 54a2d68 into main Apr 16, 2025
52 checks passed
@ndhoule ndhoule deleted the refactor/convert-js-tests-to-ts branch April 16, 2025 23:52
ndhoule added a commit that referenced this pull request Apr 21, 2025
Follow-up to a comment thread in #7199.

This changeset adds types for the global configuration file
(`$CONFIG_HOME/netlify/config.json`).

This is mainly a step forward in documenting the configuration format.
The type safety on it isn't ideal; e.g. you can try to read or write
properties that don't exist in the config schema. That said, it's an
improvement on the read side in the sense that any property you
read is typed--even unknown ones default to `undefined`.

This comes with two _potential_ breaking changes; I didn't find that
they actually broke anything in practice, but they're worth looking out
for in review:

1. We now set defaults for some values we did not previously set
   defaults for, e.g. `users[id: string].auth` defaults to an object.
   This could only break if a code path assumes e.g. the presence of
   `auth.github` means the user is authenticated; however, the way the
   types are structured marks all properties on that object as
   undefined, so this is a difficult error to make now.
2. We now validate that `users[id: string].id` is set. Failing to set it
   would make looking up user configuration impossible (we index into
   this object using the top-level `userId` field), so this prevents a
   class of mysterious logic errors.

Stronger typing caused some issues in tests that mock the global config
store; broke the `GlobalConfigStore`'s storage logic out into an adapter
and implemented an in-memory adapter for use in tests. There are better
ways to solve this problem--tests should be able to mock the global
config without resorting to module mocking--but this will do for now.

I think the global config store interface could use some work: at this
point I think the dot-prop style of setting and getting properties only
adds complexity vs something like a Proxy-wrapped object. That said,
this is a step forward without committing to a bigger change.
ndhoule added a commit that referenced this pull request Apr 21, 2025
Follow-up to a comment thread in #7199.

This changeset adds types for the global configuration file
(`$CONFIG_HOME/netlify/config.json`).

This is mainly a step forward in documenting the configuration format.
The type safety on it isn't ideal; e.g. you can try to read or write
properties that don't exist in the config schema. That said, it's an
improvement on the read side in the sense that any property you
read is typed--even unknown ones default to `undefined`.

This comes with two _potential_ breaking changes; I didn't find that
they actually broke anything in practice, but they're worth looking out
for in review:

1. We now set defaults for some values we did not previously set
   defaults for, e.g. `users[id: string].auth` defaults to an object.
   This could only break if a code path assumes e.g. the presence of
   `auth.github` means the user is authenticated; however, the way the
   types are structured marks all properties on that object as
   undefined, so this is a difficult error to make now.
2. We now validate that `users[id: string].id` is set. Failing to set it
   would make looking up user configuration impossible (we index into
   this object using the top-level `userId` field), so this prevents a
   class of mysterious logic errors.

Stronger typing caused some issues in tests that mock the global config
store; broke the `GlobalConfigStore`'s storage logic out into an adapter
and implemented an in-memory adapter for use in tests. There are better
ways to solve this problem--tests should be able to mock the global
config without resorting to module mocking--but this will do for now.

I think the global config store interface could use some work: at this
point I think the dot-prop style of setting and getting properties only
adds complexity vs something like a Proxy-wrapped object. That said,
this is a step forward without committing to a bigger change.
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