longform icon indicating copy to clipboard operation
longform copied to clipboard

Add Tests for Creating a New Project

Open b-camphart opened this issue 11 months ago • 3 comments

I tried to keep this as small as possible, but I ended up creating a whole little ad-hoc integration test framework 😅

To summarize what's happening here:

  • I extracted logic from store-vault-sync.ts and draft-utils.ts into the drafts.ts file to isolate it from the obsidian API. (re-exported functions in-place so preserve existing imports in the rest of the code)
  • I created an interface that could be mocked between that logic and the obsidian API.
  • Created unit tests for Creating a New Project (from both the plugin's API, and by creating a new index file)
  • To ensure that the wrapper around the obsidian API (VaultDirectory) worked the way I expected, and that the mocked version I'm using in unit tests worked the same way, I created a contract test and, well, an integration test framework. This allows us to actually run tests within obsidian, but only when we actually run the specific build config. In the normal dev and prod build configurations, the tests won't be imported by anything, and thus not included.

I recognize that this is still probably a lot to look over, so, if you'd prefer that I split this into two PRs: one for the int test framework stuff, and the other for actually adding the Create New Project unit tests, let me know :)

b-camphart avatar Mar 03 '24 07:03 b-camphart