Skip to content

Conversation

@dave-artificial-agency
Copy link
Contributor

@dave-artificial-agency dave-artificial-agency commented Oct 9, 2025

  • Set up jest as a unit testing system
  • Add a number of tests to verify the code in Add pin types #6 , and prove that it works.
  • Add github config to run these unit tests on PRs

Here are a number of unit tests to prove that the code from #6 works.
I have added in several null checks where I ran into crashes while creating and testing some parser classes.

There is a new class TestableNodeControl, designed to make it easier to test your parsing classes (especially if you create your own custom parsing classes, like you can do with #7 )
It gives you access to some of the node properties so you can verify e.g. if they have the icon and color that you want.

(If you are willing to accept and merge in #6 , the diff here will become a lot smaller.
You can ignore the commits before 7195288)

Run the tests with:

$ npx jest

context is only used by the NodeParserRegistry,
and NodeParserRegistry is already mocked.
@dave-artificial-agency
Copy link
Contributor Author

I will update this branch to pull in the merged changes from main branch andthe updated plugin syntax from 3c694f2#diff-7fa81459b9ffec9f7251f22a705c83d6a65d370d1e6ed30e56a4a2ff5a3e9255L33 , and then push an update.

update to match the syntax based on committed and merged code -
Joined-Forces@3c694f2
@dave-artificial-agency dave-artificial-agency changed the title Add unit tests Add unit tests with jest Oct 14, 2025

beforeEach(() => {
let nodeParserRegistry = new NodeParserRegistry();
parser = new GenericNodeParser(nodeParserRegistry);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One note for the future - currently the unit tests cannot call nodeParserRegistry.loadPlugins();, because the webpack require.context is not available inside the test.
You will get an error like:

    TypeError: require.context is not a function

      71 |
      72 |     public loadPlugins(): void {
    > 73 |         const pluginContext = (require as any).context('../../plugins', true, /\.plugin\.ts$/);
         |                                                ^

example:

https://github.com/Joined-Forces/klee/actions/runs/18507939361/job/52741425985?pr=8

I avoid this for now by just not calling that function inside the test.
But if we want to add tests for loadPlugins() in the future, we would need to fix this.

One possible way would be to patch and mock require.context before the tests run. This might require changing some code, as currently adding a mock in setupFiles happens too late.

But: this PR will add test coverage on a number of other areas, and we can always refactor later.
Let me know what you think.

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.

1 participant