-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 tests 🧪 #1937
Comments
So some feedback for those who are following this thread. @lluia and started working on an initial setup at #1992. We are going to use Currently, the best-tested adapter is the new Prisma one: https://github.com/nextauthjs/adapters/blob/canary/packages/prisma/tests/index.test.ts Even that could be improved though in my opinion. When all these are in place, we will have to start to think about how to write some tests that would connect everything together. Open for suggestions! |
So I just checked out the prisma tests, and I'm a bit confused as to how jest i.e. how does this on test("createUser", async () => {
const adapter = await prismaAdapter.getAdapter(appOptions)
user = await adapter.createUser({
email: "[email protected]",
name: "test",
image: "https://",
} as any)
expect(user.email).toMatchInlineSnapshot(`"[email protected]"`)
expect(user.name).toMatchInlineSnapshot(`"test"`)
expect(user.image).toMatchInlineSnapshot(`"https://"`)
}) Know if Prisma actually created those? Snapshots are usually just text files of literal snapshots of the dom, right? If jest / jest snapshots can be wired up to database queries / database snapshots that could make the rest of the adapter testing much easier too! |
not sure why they didn't use |
I started working on Adapter tests, have a look: https://github.com/nextauthjs/adapters/pull/90/files This basically introduces a helper function that runs the most basic tests for any adapter, in a few lines of code. |
@balazsorban44 this is great! To wire up the other adapters, i.e. typeorm for example, we just need to spin up docker containers for each type of db again, seed them, and then run a similar test file against it, obviously requiring typeorm instead of the prisma adapter, for example. Right? |
yes, that are my thoughts as well! |
Are there any test scripts or acceptance criteria that custom adapter developers can use to verify their implementation? |
@khawajaumarfarooq Funny that you ask, @ndom91 and I merged a PR (nextauthjs/adapters#90) a few minutes ago, that introduces a way to run basic tests that all adapters should be able to pass! We should maybe expose it as a package, so people could use it much easier for their custom adapters that are not in the official repo. For now, have a look at: https://github.com/nextauthjs/adapters/blob/canary/basic-tests.ts Note, that it does not test account linking, because I first have to learn more about it how we use it in the source code in the first place. |
I have an example of how to use At the moment it's just a basic test, open the page, check the user is not logged in, click sign in and login the user, check that the user is now logged in. |
Hi there! It looks like this issue hasn't had any activity for a while. It will be closed if no further activity occurs. If you think your issue is still relevant, feel free to comment on it to keep it open. (Read more at #912) Thanks! |
Hi there! It looks like this issue hasn't had any activity for a while. To keep things tidy, I am going to close this issue for now. If you think your issue is still relevant, just leave a comment and I will reopen it. (Read more at #912) Thanks! |
Summary 💭
Currently, we don't have any test coverage. We rely on manual testing, Typescript, and inline code comments to ensure the library works as expected.
Description 📓
By adding unit/integration tests to the different modules exposed by the library:
next-auth/client,
next-auth/providers
, etc... we will gain confidence during refactors and releases and better documentation than inline code comments. 💭The idea is to start testing our client module:
next-auth/client
as a POC to agree on the tooling and the workflows we want. Once we're happy with the setup, then go ahead and test the rest of the modules. 🏋🏽The text was updated successfully, but these errors were encountered: