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

Refactor existing tests and add new ones #254

Merged
merged 4 commits into from
Nov 17, 2021

Conversation

wlsf82
Copy link
Collaborator

@wlsf82 wlsf82 commented Nov 15, 2021

For more details, read the commit messages.

See the tests running:

login.spec.js.mp4
models.spec.js.mp4

Cc @ArthurMota9, @idmarjr, and @miltonbsn.

The login tests now have better assertions.

And the login custom command can now use the cy.session
experimental feature, which allows restoring the session of a user,
which speeds up tests.

But, for the login tests, we don't want any cache to be restored.
This is why for the login tests we pass { cacheSession: false }
@wlsf82 wlsf82 force-pushed the tests/refactor-and-new-tests branch 2 times, most recently from c7d21f0 to 9d4ced2 Compare November 15, 2021 16:29
Such tests make use of the refactored login command, which means
that only the first tests needs to log in via the GUI, while others
benefit from the session to be restored from the cache.

In this test suite, I've also create a custom command to cleanup
all existing models on the beforeEach hook so that tests always
start in a fresh state.
@wlsf82 wlsf82 force-pushed the tests/refactor-and-new-tests branch from 9d4ced2 to 5cc04c1 Compare November 15, 2021 20:50
@idmarjr idmarjr linked an issue Nov 16, 2021 that may be closed by this pull request
@idmarjr
Copy link
Collaborator

idmarjr commented Nov 16, 2021

Not sure if I'm doing something wrong but one of the tests is failing here:

Screen Shot 2021-11-16 at 23 29 25
Screen Shot 2021-11-16 at 23 30 13

is this expected?

@wlsf82
Copy link
Collaborator Author

wlsf82 commented Nov 16, 2021

is this expected?

Not it's not. Are you running the tests against your local environment?

Maybe I'll need to increase a timeout since the default one from Cypress might not be enough.

@idmarjr, have you tried more than once? If so, does it always fails on the same step?

@idmarjr
Copy link
Collaborator

idmarjr commented Nov 17, 2021

Yes sir. I'm running it at localhost and tried to run it twice, once using yarn test and another using yarn cy:open, both fail.

Maybe someone else can run the tests as well to double check it?

CC @ArthurMota9 @miltonbsn or @oicramps

@wlsf82
Copy link
Collaborator Author

wlsf82 commented Nov 17, 2021

Yes sir. I'm running it at localhost and tried to run it twice, once using yarn test and another using yarn cy:open, both fail.

Maybe we can pair on it tomorrow so that I can investigate it further.

@wlsf82
Copy link
Collaborator Author

wlsf82 commented Nov 17, 2021

Oddly, only one test is failing.

The beforeEach hook runs before each test, as its name suggests.
This means that, for all other tests, all steps inside of it have passed.

@miltonbsn, maybe you can help us out here.

When visiting the relative URL /#!/main as a logged-in user, should a GET request always happen to retrieve the models of such user (/models?userId=*)?

@wlsf82 wlsf82 force-pushed the tests/refactor-and-new-tests branch from 531ba04 to 8501473 Compare November 17, 2021 11:24
@miltonbsn
Copy link
Member

Oddly, only one test is failing.

The beforeEach hook runs before each test, as its name suggests. This means that, for all other tests, all steps inside of it have passed.

@miltonbsn, maybe you can help us out here.

When visiting the relative URL /#!/main as a logged-in user, should a GET request always happen to retrieve the models of such user (/models?userId=*)?

Hi @wlsf82, yes every time you visite /#!/main we execute a GET request.

ctrl.$onInit = () => {
Is it too slow?

@wlsf82
Copy link
Collaborator Author

wlsf82 commented Nov 17, 2021

@idmarjr, can you pull the new code I pushed today and try again, please?

Let's see if this commit 02c5314 will fix it.

Cc @miltonbsn.

@idmarjr
Copy link
Collaborator

idmarjr commented Nov 17, 2021

Nope. 02c5314 did not solve the issue. 😢

Screen Shot 2021-11-17 at 19 48 55

Screen Shot 2021-11-17 at 19 49 08

Screen Shot 2021-11-17 at 19 52 51

@wlsf82
Copy link
Collaborator Author

wlsf82 commented Nov 17, 2021

Nope. 02c5314 did not solve the issue. 😢

Right after line 10 (the failure), I see that there's a GET request to http://localhost:3000/models, while the test expects a request to http://localhost:3000/models?userId=*.

@miltonbsn, is there a "kind" of user who gets all the models instead of only its own?

@wlsf82 wlsf82 merged commit 35350b4 into development Nov 17, 2021
@wlsf82 wlsf82 deleted the tests/refactor-and-new-tests branch November 17, 2021 22:39
@wlsf82
Copy link
Collaborator Author

wlsf82 commented Nov 20, 2021

To keep it documented, we discovered that, on @idmarjr's computer, the failure is related to the use of the experimental feature cy.session. Without it, all tests worked fine.

On everyone else's computer, cy.session works fine .

What happens to on Id's computer is that when using cy.session, the getUserModels request that we are trying to intercept never happens, failing the test in the beforeEach hook.

But, we decided to keep using the feature since it speeds up tests, and in the meanwhile, Id will try it out on another computer.

@wlsf82
Copy link
Collaborator Author

wlsf82 commented Nov 20, 2021

To keep it documented, we discovered that, on @idmarjr's computer, the failure is related to the use of the experimental feature cy.session. Without it, all tests worked fine.

On everyone else's computer, cy.session works fine .

What happens to on Id's computer is that when using cy.session, the getUserModels request that we are trying to intercept never happens, failing the test in the beforeEach hook.

But, we decided to keep using the feature since it speeds up tests, and in the meanwhile, Id will try it out on another computer.

@bahmutov, any thoughts?

@bahmutov
Copy link

bahmutov commented Nov 20, 2021 via email

@wlsf82
Copy link
Collaborator Author

wlsf82 commented Dec 3, 2021

To keep it documented, we discovered that, on @idmarjr's computer, the failure is related to the use of the experimental feature cy.session. Without it, all tests worked fine.

On everyone else's computer, cy.session works fine .

What happens to on Id's computer is that when using cy.session, the getUserModels request that we are trying to intercept never happens, failing the test in the beforeEach hook.

But, we decided to keep using the feature since it speeds up tests, and in the meanwhile, Id will try it out on another computer.

Just to keep it documented, the issue only happens when the server is pointing to a remote MongoDB. If the server points to a local MongoDB everything works fine.

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.

Add continuous integration tool (CI)
5 participants