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

feat(astro): Exposes extra APIs for script and testing #12052

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Fryuni
Copy link
Member

@Fryuni Fryuni commented Sep 22, 2024

Changes

Testing

There was no change in logic. The behavior for all changed functions was already tested.

Docs

  • The docs on the build API should be updated
  • There is currently no reference documentation for the functions and types exported from astro/config, so nothing to update. The two functions newly exported would go in such a reference.

@Fryuni Fryuni added the pkg: astro Related to the core `astro` package (scope) label Sep 22, 2024
@Fryuni Fryuni self-assigned this Sep 22, 2024
Copy link

changeset-bot bot commented Sep 22, 2024

🦋 Changeset detected

Latest commit: 0cd9fc0

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the semver: minor Change triggers a `minor` release label Sep 22, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This PR is blocked because it contains a minor changeset. A reviewer will merge this at the next release if approved.

Comment on lines -43 to +45
* @internal only used for testing
* When building multiple projects in the same execution (e.g. during tests), disabling
* this option can greatly improve performance at the cost of some extra memory usage.
*
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to keep this internal still. I imagine for external libraries this shouldn't have a significant impact if not used since it only mattered for Astro having tons of tests.

Copy link
Member Author

@Fryuni Fryuni Sep 29, 2024

Choose a reason for hiding this comment

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

Astro has around 2,000 tests. For companies requiring high reliability, it is not uncommon to have very exhaustive testing on libraries (at least for the companies I know that fit that description, including mine).

Multiple of our libraries for Next have over 10k tests each. Libraries for Astro (which we are working on) won't be any less tested.

Copy link
Member

Choose a reason for hiding this comment

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

This isn't related to the number of test, but the number of builds for tests. Astro has many builds to test different permutations of all features and I doubt the same is needed for external libraries. Even so, Astro's test suite is due for some fixtures reduction because some fixtures could be combined, so in practice this option isn't really encouraged.

Copy link
Member Author

@Fryuni Fryuni Feb 15, 2025

Choose a reason for hiding this comment

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

It's been months, and we talked about this on the call in the meantime. Now that I've changed downstream packages, it seems the effects are the opposite of what I expected.

At the scale of Inox Tools, this indeed doesn't make much difference regarding performance. Initializing the compiler was a very small part of the test time. However, it does have a big difference in memory usage. Contrary to my expectations, it reduces memory usage by about 20% when tests have concurrency enabled.

Although it uses more memory as an overhead in later steps by not discarding the compiler, it actually saves memory overall. Without disabling teardown, tests running on the same isolate can discard the compiler while it's still in use by a different test, resulting in multiple instances of the compiler service existing in memory at the same time.

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

Thank you @Fryuni for kicking off this! I am going to block this PR for now, while we agreed on a plan on how to ship this new feature on Discord.

@matthewp
Copy link
Contributor

matthewp commented Oct 8, 2024

!preview test-apis

@github-actions github-actions bot added the pr preview This PR has a preview release label Oct 8, 2024
Copy link
Contributor

github-actions bot commented Oct 8, 2024

Snapshots have been released for the following packages:

  • astro@experimental--test-apis
  • @astrojs/rss@experimental--test-apis
  • create-astro@experimental--test-apis
Publish Log
🦋  warn ===============================IMPORTANT!===============================
🦋  warn Packages will be released under the experimental--test-apis tag
🦋  warn ----------------------------------------------------------------------
🦋  info npm info astro
🦋  info npm info @astrojs/prism
🦋  info npm info @astrojs/rss
🦋  info npm info create-astro
🦋  info npm info @astrojs/db
🦋  info npm info @astrojs/alpinejs
🦋  info npm info @astrojs/lit
🦋  info npm info @astrojs/markdoc
🦋  info npm info @astrojs/mdx
🦋  info npm info @astrojs/partytown
🦋  info npm info @astrojs/preact
🦋  info npm info @astrojs/react
🦋  info npm info @astrojs/sitemap
🦋  info npm info @astrojs/solid-js
🦋  info npm info @astrojs/svelte
🦋  info npm info @astrojs/tailwind
🦋  info npm info @astrojs/vue
🦋  info npm info @astrojs/web-vitals
🦋  info npm info @astrojs/internal-helpers
🦋  info npm info @astrojs/markdown-remark
🦋  info npm info @astrojs/studio
🦋  info npm info @astrojs/telemetry
🦋  info npm info @astrojs/underscore-redirects
🦋  info npm info @astrojs/upgrade
🦋  info astro is being published because our local version (0.0.0-test-apis-20241008195645) has not been published on npm
🦋  warn @astrojs/prism is not being published because version 3.1.0 is already published on npm
🦋  info @astrojs/rss is being published because our local version (0.0.0-test-apis-20241008195645) has not been published on npm
🦋  info create-astro is being published because our local version (0.0.0-test-apis-20241008195645) has not been published on npm
🦋  warn @astrojs/db is not being published because version 0.14.2 is already published on npm
🦋  warn @astrojs/alpinejs is not being published because version 0.4.0 is already published on npm
🦋  warn @astrojs/lit is not being published because version 4.3.0 is already published on npm
🦋  warn @astrojs/markdoc is not being published because version 0.11.4 is already published on npm
🦋  warn @astrojs/mdx is not being published because version 3.1.7 is already published on npm
🦋  warn @astrojs/partytown is not being published because version 2.1.2 is already published on npm
🦋  warn @astrojs/preact is not being published because version 3.5.3 is already published on npm
🦋  warn @astrojs/react is not being published because version 3.6.2 is already published on npm
🦋  warn @astrojs/sitemap is not being published because version 3.2.0 is already published on npm
🦋  warn @astrojs/solid-js is not being published because version 4.4.2 is already published on npm
🦋  warn @astrojs/svelte is not being published because version 5.7.2 is already published on npm
🦋  warn @astrojs/tailwind is not being published because version 5.1.1 is already published on npm
🦋  warn @astrojs/vue is not being published because version 4.5.2 is already published on npm
🦋  warn @astrojs/web-vitals is not being published because version 3.0.0 is already published on npm
🦋  warn @astrojs/internal-helpers is not being published because version 0.4.1 is already published on npm
🦋  warn @astrojs/markdown-remark is not being published because version 5.2.0 is already published on npm
🦋  warn @astrojs/studio is not being published because version 0.1.1 is already published on npm
🦋  warn @astrojs/telemetry is not being published because version 3.1.0 is already published on npm
🦋  warn @astrojs/underscore-redirects is not being published because version 0.3.4 is already published on npm
🦋  warn @astrojs/upgrade is not being published because version 0.3.4 is already published on npm
🦋  info Publishing "astro" at "0.0.0-test-apis-20241008195645"
🦋  info Publishing "@astrojs/rss" at "0.0.0-test-apis-20241008195645"
🦋  info Publishing "create-astro" at "0.0.0-test-apis-20241008195645"
🦋  success packages published successfully:
🦋  [email protected]
🦋  @astrojs/[email protected]
🦋  [email protected]
🦋  Creating git tags...
🦋  New tag:  [email protected]
🦋  New tag:  @astrojs/[email protected]
🦋  New tag:  [email protected]
Build Log

> [email protected] build /home/runner/work/astro/astro
> turbo run build --filter=astro --filter=create-astro --filter="@astrojs/*" --filter="@benchmark/*"

• Packages in scope: @astrojs/alpinejs, @astrojs/cloudflare, @astrojs/db, @astrojs/internal-helpers, @astrojs/lit, @astrojs/markdoc, @astrojs/markdown-remark, @astrojs/mdx, @astrojs/netlify, @astrojs/node, @astrojs/partytown, @astrojs/preact, @astrojs/prism, @astrojs/react, @astrojs/rss, @astrojs/sitemap, @astrojs/solid-js, @astrojs/studio, @astrojs/svelte, @astrojs/tailwind, @astrojs/telemetry, @astrojs/underscore-redirects, @astrojs/upgrade, @astrojs/vercel, @astrojs/vue, @astrojs/web-vitals, @benchmark/timer, astro, create-astro
• Running build in 29 packages
• Remote caching enabled
::group::@astrojs/telemetry:build
cache miss, executing 214adb7ba3481648

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/telemetry
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/internal-helpers:build
cache miss, executing 6bc5ceedab5ed77d

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/internal-helpers
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json

::endgroup::
::group::@astrojs/prism:build
cache miss, executing 8a200e48d3ad77d3

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/astro-prism
> astro-scripts build "src/**/*.ts" && tsc -p ./tsconfig.json

::endgroup::
::group::create-astro:build
cache miss, executing 3bc781012dc99721

> [email protected] build /home/runner/work/astro/astro/packages/create-astro
> astro-scripts build "src/index.ts" --bundle && tsc

::endgroup::
::group::@astrojs/upgrade:build
cache miss, executing 0038756a9e347ad5

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/upgrade
> astro-scripts build "src/index.ts" --bundle && tsc

::endgroup::
::group::@astrojs/markdown-remark:build
cache miss, executing 7c1ae241d812f896

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/markdown/remark
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json

::endgroup::
::group::astro:build
cache miss, executing 07680a1965407f24

> [email protected] build /home/runner/work/astro/astro/packages/astro
> pnpm run prebuild && astro-scripts build "src/**/*.{ts,js}" --copy-wasm && tsc


> [email protected] prebuild /home/runner/work/astro/astro/packages/astro
> astro-scripts prebuild --to-string "src/runtime/server/astro-island.ts" "src/runtime/client/{idle,load,media,only,visible}.ts"

::endgroup::
::group::@astrojs/studio:build
cache miss, executing c484be47b557600f

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/studio
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/underscore-redirects:build
cache miss, executing c9060bde264921a2

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/underscore-redirects
> astro-scripts build "src/**/*.ts" && tsc -p tsconfig.json

::endgroup::
::group::@astrojs/alpinejs:build
cache miss, executing e663907511e76994

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/alpinejs
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/lit:build
cache miss, executing c3071774a5f79088

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/lit
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/partytown:build
cache miss, executing 38767e3a1ee60cab

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/partytown
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@benchmark/timer:build
cache miss, executing f805e7155e366346

> @benchmark/[email protected] build /home/runner/work/astro/astro/benchmark/packages/timer
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/tailwind:build
cache miss, executing e8c351f4f19e4738

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/tailwind
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/vue:build
cache miss, executing d2a2285c81d67488

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/vue
> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc

::endgroup::
::group::@astrojs/mdx:build
cache miss, executing 0ce1a75b0637839e

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/mdx
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/markdoc:build
cache miss, executing 8bd0750d843b0dfa

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/markdoc
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/rss:build
cache miss, executing f4d542e84b5fbb16

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/astro-rss
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/sitemap:build
cache miss, executing 4c2a10aa8d9d9795

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/sitemap
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/react:build
cache miss, executing 538ea99483193d37

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/react
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/svelte:build
cache miss, executing 82102e98fa5b19cc

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/svelte
> astro-scripts build "src/index.ts" && astro-scripts build "src/editor.cts" --force-cjs --no-clean-dist && tsc

::endgroup::
::group::@astrojs/solid-js:build
cache miss, executing 4a3e5e8638105b63

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/solid
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/preact:build
cache miss, executing 7e11742635b60788

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/preact
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::
::group::@astrojs/db:build
cache miss, executing 321eca678fc2d736

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/db
> astro-scripts build "src/**/*.ts" && tsc && pnpm types:virtual


> @astrojs/[email protected] types:virtual /home/runner/work/astro/astro/packages/db
> tsc -p ./tsconfig.virtual.json

::endgroup::
::group::@astrojs/web-vitals:build
cache miss, executing c2b6947ef33dfc15

> @astrojs/[email protected] build /home/runner/work/astro/astro/packages/integrations/web-vitals
> astro-scripts build "src/**/*.ts" && tsc

::endgroup::

 Tasks:    25 successful, 25 total
Cached:    0 cached, 25 total
  Time:    51.141s 

Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

After the meeting we had, I am good now. Happy to merge it!

@sarah11918
Copy link
Member

There is currently no reference documentation for the functions and types exported from astro/config

Should there be? 😅

@ematipico
Copy link
Member

@Fryuni what's the status of the PR? Considering this is a minor and we are exposing new APIs, I believe we should document them. Happy to help if needed.

Copy link

codspeed-hq bot commented Feb 14, 2025

CodSpeed Performance Report

Merging #12052 will not alter performance

Comparing feat/expose-apis-for-testing (0cd9fc0) with main (2e1321e)

Summary

✅ 6 untouched benchmarks

@Fryuni
Copy link
Member Author

Fryuni commented Feb 14, 2025

Coming back to this PR (finally). I opened Fryuni/inox-tools#203 updating the astro-tests package to use these newly exported functions. Everything is working perfectly, both testing with Vitest and with Playwright.

Previously we talked about testing it out on the adapters repo, but since they are now part of this repo I don't think that would be necessary.

@florian-lefebvre florian-lefebvre added this to the 5.4.0 milestone Feb 21, 2025
@sarah11918
Copy link
Member

Just reminding @Fryuni to loop me in re: what might be required for docs! Just because something wasn't documented before doesn't mean it shouldn't have been... 😄

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Just quick changeset comments!


Fixes incorrect config update when calling `updateConfig` from `astro:build:setup` hook.

The function previously called a custom update config function made for merging an Astro config, Now it calls the appropriate `mergeConfig` utility exported by Vite that updates functional options correctly.
Copy link
Member

@sarah11918 sarah11918 Feb 25, 2025

Choose a reason for hiding this comment

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

Suggested change
The function previously called a custom update config function made for merging an Astro config, Now it calls the appropriate `mergeConfig` utility exported by Vite that updates functional options correctly.
The function previously called a custom update config function made for merging an Astro config. Now it calls the appropriate `mergeConfig()` utility exported by Vite that updates functional options correctly.

just nits!

Comment on lines +11 to +12
- `mergeConfig` allows users to merge partially defined Astro configurations on top of a base config while following the merge rules of `updateConfig` available for integrations;
- `validateConfig` allows users to validate that a given value is a valid Astro configuration and fills in default values as necessary;
Copy link
Member

@sarah11918 sarah11918 Feb 25, 2025

Choose a reason for hiding this comment

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

Suggested change
- `mergeConfig` allows users to merge partially defined Astro configurations on top of a base config while following the merge rules of `updateConfig` available for integrations;
- `validateConfig` allows users to validate that a given value is a valid Astro configuration and fills in default values as necessary;
- `mergeConfig()` allows users to merge partially defined Astro configurations on top of a base config while following the merge rules of `updateConfig()` available for integrations.
- `validateConfig()` allows users to validate that a given value is a valid Astro configuration and fills in default values as necessary.
These helpers are particularly useful for integration authors and for developers writing scripts that need to manipulate Astro configurations programmatically.

nits!

Also, I like Matt's wording from the blog here!

Comment on lines +18 to +19
- `devOutput` (default `false`): output a development-based build similar to code transformed in `astro dev`;
- `teardownCompiler` (default `true`): teardown the compiler WASM instance after build.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `devOutput` (default `false`): output a development-based build similar to code transformed in `astro dev`;
- `teardownCompiler` (default `true`): teardown the compiler WASM instance after build.
- `devOutput` (default `false`): output a development-based build similar to code transformed in `astro dev`.
- `teardownCompiler` (default `true`): teardown the compiler WASM instance after build.
These options provide more control when running Astro builds programmatically, especially for testing scenarios or custom build pipelines.

Same kind of nits/addition of blog post extra context!

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Approving for docs, with some nits below and additional "commentary" for your consideration @Fryuni ! I trust you to take it from here! 🫡

Also noting, to remind myself as much as anyone, I did not see any new error messages added to accompany this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr preview This PR has a preview release semver: minor Change triggers a `minor` release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants