Skip to content

feat(describeScenario): Seed scenario once and group tests#9572

Closed
dac09 wants to merge 6 commits intoredwoodjs:mainfrom
dac09:try/setupScenario-multiple-tests
Closed

feat(describeScenario): Seed scenario once and group tests#9572
dac09 wants to merge 6 commits intoredwoodjs:mainfrom
dac09:try/setupScenario-multiple-tests

Conversation

@dac09
Copy link
Copy Markdown
Contributor

@dac09 dac09 commented Nov 23, 2023

See discussion here: https://community.redwoodjs.com/t/api-testing-and-scenarios/5553

Tasks

  • Add docs.
  • Should add to e2e tests? Not sure how else to test
  • Wait for discussion during CTM to make sure API seems right.

Usage

describeScenario<StandardScenario>('contacts', (getScenario) => {
  it('xxx', () => {
  //  
   const scenario = getScenario() 
   /...
  })

This will load, and seed the scenario once and allow you to write multiple expecations inside the describeScenario block.

@dac09 dac09 added the release:feature This PR introduces a new feature label Nov 23, 2023
@dac09 dac09 added this to the next-release milestone Nov 23, 2023
@dac09
Copy link
Copy Markdown
Contributor Author

dac09 commented Nov 23, 2023

@cjreimer created the PR here. Do you want to take it for a spin on your project first?

Would appreciate your help with the docs, since you'll have real examples where it makes more sense to use describeScenario

@cjreimer
Copy link
Copy Markdown
Contributor

Wow, that was fast! Yes, I'll try to take it for a spin, possibly this weekend!

And yes, I'll write up some docs for this.

Thanks, Danny!

@cjreimer
Copy link
Copy Markdown
Contributor

@dac09 It works great! Thanks!

As you noted previously, the const scenario= getScenario() required in each it test is not ideal. I took a brief look myself, and the fact we can't pass an async function to a jest describe block appears to be the limiting factor. I think we can live with this, as it provides an opportunity for performance improvements and the possibility for dependent tests (with caution!)

@cjreimer
Copy link
Copy Markdown
Contributor

cjreimer commented Dec 5, 2023

@dac09, is there any update on the core team being on the same page with this feature? I was waiting on that before starting the docs. Thanks!

@dac09
Copy link
Copy Markdown
Contributor Author

dac09 commented Dec 5, 2023

@dac09, is there any update on the core team being on the same page with this feature? I was waiting on that before starting the docs. Thanks!

Hey @cjreimer - just discussed, and we're good to go :) - while there are some concerns with the potential for footguns here, we can strongly caution users in the docs that writing tests with describeScenario won't cleanup between tests.

I think it would help also with your examples to explain when it would be useful, and when its likely not the correct tool to reach for.

@cjreimer
Copy link
Copy Markdown
Contributor

cjreimer commented Dec 5, 2023

Great, thanks! I'll start working on the docs!

@cjreimer cjreimer mentioned this pull request Dec 14, 2023
2 tasks
@dac09 dac09 marked this pull request as ready for review December 26, 2023 07:09
@dac09
Copy link
Copy Markdown
Contributor Author

dac09 commented Jan 22, 2024

Closing this PR, as I'm creating a branch with docs and code together.

@dac09 dac09 closed this Jan 22, 2024
@jtoar jtoar removed this from the next-release milestone Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:feature This PR introduces a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants