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 testing setup #79

Closed
wants to merge 13 commits into from
Closed

Conversation

hjonasson
Copy link

I am writing my own plugin and wanted to add tests. I get around the closed nature of obsidian by using Jest's manual mocks. I added three tests to establish a pattern for testing Plugins.

Closes #37

PS: When researching if this was a solved problem, I came across obsidian-full-calendar which has much more detailed mock implementations. I leave that link here for posterity if someone wants more detailed mocks.

@lishid
Copy link
Collaborator

lishid commented Nov 16, 2023

Thanks for the PR.

I think it's great to have a sample plugin with testing framework integrated for people to use, but I would rather we don't further complicate the official sample plugin template.

In this case, I think it's best if we have your fork as a standalone fork, where people can choose to use if they'd like to write tests for their plugins. If you'd like to maintain the template for longer term we can look into adding links to your repo in our plugin developer docs.

@lishid lishid closed this Nov 16, 2023
@hjonasson
Copy link
Author

@lishid thanks for the quick review! This seems a highly requested feature given the thumbs up in #37. Please consider opening up the PR again pending discussions in the feature request.

Please note that this is by far the simplest implementation of everything I tried out. If you look at how others solve testing obsidian plugins (obsidian-full-calendar, or excalidraw) the setup is either much harder to understand and use or obsidian can't be mentioned anywhere in the tests. This makes developing plugins hard to develop in my opinion. The official Obsidian docs suggest you refactor your code to be able to test it here. This does not seem user friendly to me and doesn't allow you to test things like "did I register my command?".

@x3ro
Copy link

x3ro commented Dec 9, 2023

I want to chime in here to say thanks to @hjonasson and the Obsidian maintainers, but also to ask the maintainers to reconsider adding this functionality to the sample plugin.

As someone who is contributing to an Obsidian plugin to the first time, it took me a while to find this PR. Before that, I looked at various other Obsidian plugins of varying popularity, and they all have fairly different, often quite complicated test setups. I think the reason for this is that currently, everyone is reinventing the wheel when it comes to testing their Obsidian plugins.

Having an officially blessed way of writing tests would be amazing because

  1. Many plugins created in the future might "automatically" have some tests, even if they are simple, just because it's part of the template. I think this is not currently the case because the effort of figuring out how to test the plugin is too high.
  2. When making changes, Obsidian maintainers would notice whether this breaks the default testing setup.

🚀

@hjonasson
Copy link
Author

Thanks @x3ro ! This was my feeling exactly. Both about everyone needing to reinvent it for each plugin, and most setups being more complicated. I (biasedly) think this PR or a similar one would be a great addition to the sample plugin.

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.

Enhance sample plugin with Jest Unit Test
3 participants