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

Add testing for website code blocks #2014

Merged
merged 10 commits into from
Aug 28, 2021
Merged

Conversation

mc1098
Copy link
Contributor

@mc1098 mc1098 commented Aug 26, 2021

Description

This PR adds a new crate for testing the website code blocks. This came from this suggestion and the code is essentially tweaked from the tokio-rs/website repo.

Luckily it doesn't wreck havoc with Docusaurus markup to use rust doc test attributes, like ignore. Docusaurus attributes, like title, don't seem to cause issues for the doc tests either :)

The tests run on the docs/ path so just the master/next code blocks- I think to test versioned code blocks would require a different crate due to conflicts of the yew versions.

Some of the code blocks have been changed quite a bit to add context for it to compile and some seem to have just been old blocks that never got updated.

Some code blocks depend on other types that don't really add to the point of the example but are required for compile checking, this can now be added as module and imported in the code blocks for example:

use website_test::my_module::MyType;

// use `MyType` in example

Part of #2012

Checklist

  • I have run cargo make pr-flow
  • I have reviewed my own code
  • I have added tests

mc1098 added 3 commits August 26, 2021 02:41
Heavily inspired by tokio-rs/website repo.
Some code snippets are explicitly ignored and some are not run
to avoid having to include dependencies for one liners.
@github-actions
Copy link

github-actions bot commented Aug 26, 2021

Visit the preview URL for this PR (updated for commit e9d217c):

https://yew-rs--pr2014-website-code-tests-ocoqi4on.web.app

(expires Fri, 03 Sep 2021 12:30:33 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@mc1098 mc1098 marked this pull request as draft August 26, 2021 03:45
Code snippets can import types from doc_test crate i.e.:
```rust
use doc_test::agents::EventBus;
```
This allows for moving some boilerplate away from the example and still
checks that the code compiles correctly.

Also some slight changes to some of the examples and the information
about `ComponentLink` which is deprecated.
@mc1098 mc1098 marked this pull request as ready for review August 26, 2021 16:18
@mc1098 mc1098 changed the title Add testing for website code snippets Add testing for website code blocks Aug 26, 2021
@ranile
Copy link
Member

ranile commented Aug 27, 2021

Why not put doc-tests crate in packages like changelog?

mc1098 added 3 commits August 27, 2021 13:18
The new name makes it more clear the purpose of this crate.
@mc1098
Copy link
Contributor Author

mc1098 commented Aug 27, 2021

Why not put doc-tests crate in packages like changelog?

Good point :D

I have also renamed doc-test to website-test as I think this makes it more clear what that crate is for :)

@siku2 siku2 merged commit ed2e1ea into yewstack:master Aug 28, 2021
@mc1098 mc1098 deleted the website-code-tests branch August 29, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants