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

Update database.md #172

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Update database.md #172

wants to merge 1 commit into from

Conversation

eduwass
Copy link
Contributor

@eduwass eduwass commented Nov 28, 2024

For the truncate command to work this was needed

See:
https://github.com/orgs/adonisjs/discussions/4609

For the truncate command to work this was needed

See:
https://github.com/orgs/adonisjs/discussions/4609
@thetutlage
Copy link
Member

I am not sure this is the right solution. Japa hooks must return the cleanup function and not execute them as it is.

This is how I expect the truncate database hook to work

  • Before running each test it will migrate the database
  • After each test it will truncate the database.

Maybe, you have different expectations. You were expecting the truncate method to truncate the database before running the tests.

@eduwass
Copy link
Contributor Author

eduwass commented Nov 28, 2024

Hi @thetutlage,

First of all, thank you for your amazing work and for taking the time to reply! 🙏

Thanks again for the clarification on how hooks are implemented in Japa. By the way, I found these docs here to be quite useful: https://japa.dev/docs/lifecycle-hooks

Specially the Cleanup Functions part

This behavior was initially what confused me, compared to most testing frameworks (like PHPUnit, Jest, or Mocha), where:

  • setup runs preparation logic directly before each test.
  • teardown runs cleanup logic directly after each test.

In this case, I had expected setup to allow me to run await testUtils.db().truncate() directly without needing to manage a returned function explicitly. Having to "double call" (first to get the function, then to execute it) adds complexity and makes the behavior less predictable, especially for new users like me (and I believe I'm not the only one as I saw a few similar issues in Github).

Would it make sense to:

  1. Simplify testUtils.db().truncate() to perform the truncation immediately without returning a separate function?
  2. Or, add clearer documentation about why truncate requires this additional step? Maybe a reference to the Japa docs above would suffice, in case people want to go deeper into detail.

I’d be happy to help refine the documentation to clarify this behavior if needed.

Thanks for your patience!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants