Skip to content

feat: Unit testing setup restructure #1595

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

Merged
merged 14 commits into from
Apr 17, 2025
Merged

feat: Unit testing setup restructure #1595

merged 14 commits into from
Apr 17, 2025

Conversation

matthewlipski
Copy link
Collaborator

@matthewlipski matthewlipski commented Apr 7, 2025

This PR restructures clipboard and format conversion tests for @blocknote/core and @blocknote/react, making all of them use the same design pattern and organizing them in a more sensible way. Also, the tests themselves have been split up, so they are now responsible for one thing instead of testing multiple behaviours at once. These tests have also been moved to the tests/ directory in the package root.

Moving unit tests to the tests/ directory was a necessary change, as many files containing vitest imports would otherwise need to be exported from @blocknote/core, since they're used in @blocknote/react This is an issue for 2 reasons:

  1. Importing vitest in a file without running any tests throws an error, if the code in that file is run. The restructured tests have a lot of xyzTestExecutor files where vitest is imported to define tests but not run them, which throws the error when the files are exported. The error was preventing the editor from even initializing, and anyway test files shouldn't even be read outside running the test command. After discussing with @nperez0111, the cleanest solution was to move the unit tests to the tests/ directory.
  2. Because unit test related files were being exported by @blocknote/core for use in other BlockNote packages, consumers can also access them. Since unit tests are strictly internal, it doesn't make sense for consumers to even be aware of them.

I made sure to design the tests in a way that makes sense for all of our unit tests, so that in the future we can also convert the block manipulation tests to use the same pattern, as well as tests in @blocknote/xl-multi-column and @blocknote/xl-*-exporter packages. However, that's out of scope for now.

It may also be worth revisiting if we actually need all of our unit tests, as some are probably redundant. However, this is a minor TODO that we can also leave for a future date. The goal of this PR is just to restructure the tests, not to change their scope.

TODO:

  • Fix equality tests not passing
  • Update react package tests
  • Update multi-column package tests
  • Update exporter package tests
  • Review what cases need to be tested where, since atm it's largely the same as what we had before
  • Review snapshots
  • Figure out where to put the test files. Maybe we actually want a separate folder, but either way will have to move stuff around the api folder
  • Add tests for pasting external content, e.g. inline styles should be converted to Styles. (see feat: Less data loss in external HTML #1605)
  • Fix lint

Copy link

vercel bot commented Apr 7, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview Apr 17, 2025 8:33am
blocknote-website ✅ Ready (Inspect) Visit Preview Apr 17, 2025 8:33am

// Test for verifying that exporting blocks to another format, then importing
// them back results in the same blocks as the original. Used broadly to ensure
// that exporting and importing blocks does not result in any data loss.
const testExportParseEqualityTest = async (
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we not have this for markdown or html? or only for some of those cases?

Copy link
Collaborator

Choose a reason for hiding this comment

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

also, wdym with Used broadly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added tests for HTML in #1605, though up until now HTML and Markdown wasn't really a concern since the export is lossy, so we didn't really expect the result after export + re-import to be the same as the original blocks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also updated the comment

<pre><code class="language-python">print("Should parse Python from language- class")</code></pre>
<pre><code class="language-ruby" data-language="typescript">console.log("Should prioritize TS from data-language over language- class")</code></pre>`,
},
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I get the idea, but I'm not entirely sure if it makes sense markdown / html of these cases should live in the same file

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed this so that tests for different formats are in separate arrays, and get their own describe. Imo we don't need to also separate to different files.

Copy link

pkg-pr-new bot commented Apr 8, 2025

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/ariakit@1595

@blocknote/code-block

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/code-block@1595

@blocknote/core

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/core@1595

@blocknote/mantine

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/mantine@1595

@blocknote/react

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/react@1595

@blocknote/server-util

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/server-util@1595

@blocknote/shadcn

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/shadcn@1595

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-docx-exporter@1595

@blocknote/xl-multi-column

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-multi-column@1595

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-pdf-exporter@1595

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/TypeCellOS/BlockNote/@blocknote/xl-odt-exporter@1595

commit: 4b4866c

@nperez0111
Copy link
Contributor

This looks great. Lot of clean up here. Thanks @matthewlipski for taking this on 💪!

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.

3 participants