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 DatabaseTestUtils #988

Merged
merged 10 commits into from
Jan 29, 2024
Merged

Add DatabaseTestUtils #988

merged 10 commits into from
Jan 29, 2024

Conversation

Julien-R44
Copy link
Member

@Julien-R44 Julien-R44 commented Jan 25, 2024

Changes

  • Add a DatabaseTestUtils class. Works as before.

    • testUtils.db().migrate()
    • testUtils.db().truncate()
    • testUtils.db().seed(),
      We can also pass a custom connectionName like testUtils.db('secondary').seed()
  • Also, let me know if we should not keep it, but though it would be cool to include a testUtils.db().withGlobalTransaction() method that can be used like this :

     import testUtils from '@adonisjs/core/services/test_utils'
     
     test.group('', (group) => {
        group.each.setup(() => testUtils.db().withGlobalTransaction())
     })

So every test in this group will be wrapped a transaction that will be reverted at the end of the test

@Julien-R44
Copy link
Member Author

tests will fail cause of the last two commits since we dont have TestUtils exported from @adonisjs/core/test_utils.

@thetutlage
Copy link
Member

We should export TestUtils class from @adonisjs/core in order to be able to extend it with macros. Which export path should we use ? @adonisjs/core/test_utils' ? Let me know and I will make a PR on core

Yeah, we can export it from /test_utils submodule.

not sure about this one. Naively, i would say no, but : could it cause some problems to register testUtils bindings only in test environnement ?

We can use the container resolving hook. https://docs.adonisjs.com/guides/ioc-container#container-hooks

not sure here too. should we resolve the Ace binding immediately ?

Yeah, can be lazily resolved as someone uses one of the methods from the DatabaseTestUtils class.

@Julien-R44 Julien-R44 marked this pull request as ready for review January 26, 2024 12:19
@Julien-R44
Copy link
Member Author

Should be all good. Let me just know if we keep withGlobalTransaction or not. Also if naming look correct to you

@thetutlage
Copy link
Member

Looks good.

We will have to create a new doc under the testing group, inside the AdonisJS documentation covering the usage of these hooks

@Julien-R44 Julien-R44 merged commit 9c845f6 into develop Jan 29, 2024
32 checks passed
@Julien-R44 Julien-R44 deleted the feat/db-test-utils branch January 29, 2024 11:51
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.

None yet

2 participants