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

replaced global vue with test vue in unit tests #11138

Merged
merged 1 commit into from
Jan 15, 2021

Conversation

Nerdinacan
Copy link
Contributor

@Nerdinacan Nerdinacan commented Jan 14, 2021

Noticed a lot of client-side tests are continuing to use global Vue instead of our curated Vue instance.

Right now, it's just an annoyance with the eye-spam during test runs with the BootstrapVue components blithely trying to access a non-existent document.

But the problem is that component authors are not using the standard mount function which means they are unit testing in a Vue environment that is unlikely to match the one in which the component actually runs.

The helper we wrote is intended to generate a Vue instance that matches the one in the client in terms of plugins, filters, directive overrides, etc.

@dannon
Copy link
Member

dannon commented Jan 14, 2021

@Nerdinacan Thanks; I mentioned I was going to take care of this in #11121, but not having to do it myself (again) is even better!

@Nerdinacan
Copy link
Contributor Author

Ahh crap sorry Dannon, didn't see that one.

@dannon
Copy link
Member

dannon commented Jan 14, 2021

Totally fine -- again, one less thing I have to do, and I'm not upset about that :)

@jmchilton
Copy link
Member

jmchilton commented Jan 14, 2021

If we're using that pattern over and over - does it make sense to have a wrapper around shallowMount in jest/helper that takes care of that detail (defaulting vue to that local vue I mean).

Update: Or maybe that is what mountRenderless is 😆 .

@dannon
Copy link
Member

dannon commented Jan 14, 2021

@jmchilton Yeah, when I added the helper my thinking it should be used sparingly, and was an extra indicator that a component was leaning on these extra directives. I'll admit the behavior is more prevalent than I was thinking though.

@Nerdinacan
Copy link
Contributor Author

Nerdinacan commented Jan 14, 2021

@jmchilton
Mount renderless is for the renderless components (i.e. providers). The ones with just a single big slot and you still need to check the slotProps even though there's nothing to render.

I think the only reason I didn't make a helper as you suggested is that we should really be using shallowMount, and a lot of people are using mount(), and I'd have to rewrite a bunch of tests to make that fly.

The fact that people are using mount() instead of shallowMount() tells me that the components are too monolithic.
Presumably, nobody cares whether b-form-checkbox properly prints a label, right? In a unit test, what you care about is probably that variable XYZ is true or false.

If all you care about is the variable you don't need a full mount(), you just check to see if wrapper.vm.XYZ is what you want after you set up the test?

I think the real problem is people are building big-ass components instead of breaking them into logical chunks. It's a common problem with new component designers who aren't yet comfortable with props in / events out.

@jmchilton
Copy link
Member

The fact that people are using mount() instead of shallowMount() tells me that the components are too monolithic.

While I've switch to shallowMount more and more for my recent tests, the thing I would read into this is that nearly all the examples in the official docs ( https://vue-test-utils.vuejs.org/api/wrapper/#emitted, https://vue-test-utils.vuejs.org/api/wrapper/#methods, etc...) use mount instead of shallowMount.

@dannon
Copy link
Member

dannon commented Jan 14, 2021

@Nerdinacan RefactorConfirmationModal is still spewing to info in my quick test

@Nerdinacan
Copy link
Contributor Author

@jmchilton
No argument there.

The official docs, and every video I've ever seen are basically teaching you how to write a unit test that is testing rendering. They are showing you how to write a unit test that is really more of a selenium test.

While that's important if you are indeed writing a new kind of low-level rendering component, what's more important and flexible is making sure the business logic works right since presumably the rendering should be able to change when somebody makes it prettier without busting tests.

I agree with you that the availability of good advice about writing tests is thin.

@Nerdinacan
Copy link
Contributor Author

Nerdinacan commented Jan 14, 2021

@dannon
Hmmm yeah, flushPromises()?
Or maybe lots of stuff in that folder does a Vue.use(). I'll look at that later.

Copy link
Member

@jmchilton jmchilton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just merge as is, seems atomic and working and just follow up with additional fixes in new PRs. I'll wait on the other requested reviewers though.

@dannon
Copy link
Member

dannon commented Jan 14, 2021

It's most of the way there, let's give @Nerdinacan the chance to address the last bit in this PR before merging.

@Nerdinacan
Copy link
Contributor Author

Nerdinacan commented Jan 14, 2021

@dannon
The problem is not the test, it's the code.

The message itself is an indicator that something strange is happening, and sure enough if you look at one of the data services used in that component, it references global Vue, seemingly to do the worrk of a Promise.

The Workflow editor needs to be fixed, not the test.

You can make the message disappear by setting the production flags on/off there, but the real problem is that Vue is being used at all in that file when it should just be an asynchronous function of some sort.

Vue.config.devtools = false

@Nerdinacan
Copy link
Contributor Author

I went ahead and removed the suppression of the messages so we remember to refactor that service.

@jmchilton jmchilton merged commit 0cb9469 into galaxyproject:dev Jan 15, 2021
@github-actions
Copy link

This PR was merged without a "kind/" label, please correct.

@Nerdinacan Nerdinacan deleted the fix_tests_again branch January 15, 2021 04:09
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.

4 participants