-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 7cac830 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 |
There was a problem hiding this 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.
* @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. | ||
* |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
/** | ||
* Turn raw config values into normalized values | ||
*/ | ||
export function validateConfig( | ||
userConfig: any, | ||
root: string, | ||
cmd: string, | ||
): Promise<AstroConfig>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the usecase for exporting this? I'm not too comfortable with exposing this yet since the validation doesn't take in account of --verbose
and --silent
(or log level in the future) and it always logs to the console when it shouldn't in tests, so it requires some more refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's one of the APIs necessary to implement testing properly. Otherwise, we'd need to re-implement the transformations fone in the schema.
It is mentioned at the end of the proposal:
Similarly, the function
validateConfig
that fills default values and apply transformations on the configuration is also not exported. This is required to resolve a value from the configuration that is not directly set on the test but used for the test tolling, like theoutDir
andsrcDir
.
it always logs to the console when it shouldn't in tests, so it requires some more refactor.
I don't see anywhere in the code where it would log anything. It creates a Zod schema and parses using it. None of the refine
, superRefine
and transform
functions in the schema has any logs, they just add possible issues which will be reported as an error to the caller not as logs.
Are you perhaps thinking of resolveConfig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah it's resolveConfig
that's logging the error, not validateConfig
. But in that case, wouldn't resolveConfig
be more useful as it mimics what dev()
and build()
loads for the astro config? validateConfig()
only handles the validation part.
There was a problem hiding this 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.
!preview test-apis |
Snapshots have been released for the following packages:
Publish Log
Build Log
|
There was a problem hiding this 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!
Co-authored-by: Matt Kane <[email protected]>
Changes
Testing
There was no change in logic. The behavior for all changed functions was already tested.
Docs
build
API should be updatedastro/config
, so nothing to update. The two functions newly exported would go in such a reference.