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 tests and refactor code #246

Open
5 tasks
b-camphart opened this issue Feb 23, 2024 · 7 comments
Open
5 tasks

Add tests and refactor code #246

b-camphart opened this issue Feb 23, 2024 · 7 comments

Comments

@b-camphart
Copy link
Contributor

In approaching #244 I'm finding myself refactoring code to make it more testable to show that the new feature adheres to what was discussed there. I figured, if we're writing to people's files, we should be really, really sure we're doing it without messing anything up. However, all the refactoring felt more appropriate to do in a separate PR so that it's easier to review the incremental changes. With that in mind, I'm proposing to refactor the code, and add tests for, the following use cases:

  • Creating a new project
  • Creating a new draft
  • Creating a new scene
  • Ignoring a scene (that was already included)
  • Reordering scenes

My thinking is to have these each as their own PRs (which the subtasks can be linked to in github, if I'm not mistaken). However, I wanted to document my intention here because the way I'm planning to refactor the code would apply across each of these. My plan is to add these files to the src/model folder:

  • project.ts
  • draft.ts
  • scene.ts

These files would contain the refactored code that handles the functionality for the above use cases, but would be completely isolated from the obsidian api, since it's basically impossible to do unit tests against without fully mocking out the dependency. In many cases, I'd simply be moving functions that were previously defined in other src/model files, then re-exporting them in the place they used to be so that references across the codebase don't need to be updated. In some cases, I might have to adjust the functions to accept an interface, which would serve as a wrapper around the obsidian api, but would allow easy mocking in unit tests.

I'll create a PR for the first use case shortly so that you can see more of what I mean, @kevboh . Just want to get your thoughts on this before I did a whole bunch of stuff. I figure, this issue could also serve as a discussion point for further refactorings and tests being added for other use cases in the future, if you want to go this route.

@kevboh
Copy link
Owner

kevboh commented Feb 23, 2024

Makes sense. I think before you start we should properly respect an in-repo prettier config; iirc that's not happening at present.

@b-camphart
Copy link
Contributor Author

Yeah, and I keep needing to disable the "formatOnSave" setting because it makes my PRs get crazy with changes 😅

@b-camphart
Copy link
Contributor Author

Would you want to do that? I can, if not. It's just that, it might require a lot of files being updated to match the rules, so the PR could be a nightmare. If you do it, no need for a PR 😄

@kevboh
Copy link
Owner

kevboh commented Feb 29, 2024

I can do it, but not immediately: started a new job recently and haven't had tons of dev time outside it.

@kevboh
Copy link
Owner

kevboh commented Feb 29, 2024

Okay well I ended up doing it now https://github.com/kevboh/longform/tree/prettier

@kevboh
Copy link
Owner

kevboh commented Feb 29, 2024

Going to PR it and get it into main, then sleep!

@b-camphart
Copy link
Contributor Author

🤣 "I can't do it immediately"
20 minutes later "well, I did it"

You're awesome @kevboh

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

No branches or pull requests

2 participants