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

Refactor rendering for testing #5071

Merged
merged 3 commits into from
Oct 13, 2022
Merged

Refactor rendering for testing #5071

merged 3 commits into from
Oct 13, 2022

Conversation

matthewp
Copy link
Contributor

Changes

  • This refactors core/render to make it easier to test. The goal is to be able to create rendering tests directly in JavaScript without the need for fixtures.
  • Main change is that core/render now has 2 new types:
    • Environment is an object that contains things that do not change between requests, such as the logging options, the routeCache, the markdown options, etc.
    • RenderContext is an object that contains things specific to a request, such as the request object and the scripts/styles that need to be included.

Testing

  • Some basic tests are added, more to come with bugs.
  • Fixture tests should all pass as no external API changes occurred.

Docs

N/A, internal refactor

@changeset-bot
Copy link

changeset-bot bot commented Oct 13, 2022

⚠️ No Changeset found

Latest commit: de66761

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

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

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Oct 13, 2022
return render`<div>${renderSlot(result, slots['myslot'])}</div>`;
});

const Page = createAstroJSXComponent(() => {
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 create an Astro JSX component in plain JS now!

})

it('Can render slots', async () => {
const Wrapper = createComponent((result, _props, slots = {}) => {
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 create Astro components in plain JS now.

@matthewp matthewp marked this pull request as ready for review October 13, 2022 15:10
@matthewp
Copy link
Contributor Author

!bench

@github-actions
Copy link
Contributor

Node: 14
PR: �[0m[1]�[0m 23k requests in 30.11s, 1.57 GB read
MAIN: �[0m[1]�[0m 22k requests in 30.08s, 1.53 GB read


Node: 16
PR: �[0m[1]�[0m 14k requests in 30.1s, 897 MB read
MAIN: �[0m[1]�[0m 13k requests in 30.13s, 876 MB read

@matthewp
Copy link
Contributor Author

Nice! ~1k more requests in the same time. I think this comes down to the fact that we are now setting up this Environment object once when the server first starts and that gets reused by every request. That object has a resolve method which previously created a new closure on every request and no longer does.

Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

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

This is amazing, great work! Excited to build on this with our public testing API. ❤️

@matthewp matthewp merged commit df453e4 into main Oct 13, 2022
@matthewp matthewp deleted the name-slot-astro branch October 13, 2022 19:18
@matthewp
Copy link
Contributor Author

I think we can do more to make this nice from a public API perspective. Probably most of the params we treat as required should not actually be required. We want them to be required internally so we get things like logging, but a public API would probably only need the request object and the page component. We can improve from here though

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)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants