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 for primitives, objects and tools #20

Merged
merged 9 commits into from
May 23, 2024

Conversation

brauliorivas
Copy link
Member

@brauliorivas brauliorivas commented May 16, 2024

BEGINRELEASENOTES

  • We should start testing dmX. As stated by @tmadlener in Setup basic CI and some basic (unit) tests #15, this test suite will check out that for every new change/contribution, nothing will break the basic functioning of dmX.
  • These test suites will later be added to github workflows.

ENDRELEASENOTES
I checked a library called jest-canvas-mock that allows to test the canvas API using jest. However after trying to use it a bit, I don't think that can be useful. There is almost no documentation, and some examples try to test for error rather than to test visual aspect. I don't think this meets testing goal, to be simple and cover an important use case. So that's why I think we could use plain jest with a less strict approach but easier to test.

@brauliorivas
Copy link
Member Author

Hey @tmadlener, the preview didn't work. I don't know why. Just to make sure, did you change the workflow permission like this?
Selection_001
After following this configuration

@brauliorivas brauliorivas marked this pull request as ready for review May 16, 2024 01:03
@tmadlener
Copy link
Contributor

The settings should be OK as far as I can see

@brauliorivas
Copy link
Member Author

Ok. Then I will finish writing more tests and later open a new PR to fix the previews.

@brauliorivas brauliorivas changed the title Add testing for graphic-primitives.js Add testing for primitives, objects and tools May 16, 2024
@brauliorivas brauliorivas requested a review from tmadlener May 16, 2024 23:32
Copy link
Contributor

@tmadlener tmadlener left a comment

Choose a reason for hiding this comment

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

Very nice. I think this is OK as it is in principle. One thing that I would consider to do is the following.

Currently all the individual test cases (or test case sections? 🤔 ) create their own objects to test manually. Quite often they create the same object. Is it possible to lift this code outside of the actual cases and create a fixture (or use some other setup method) that will then be freshly created automatically for each test?

I like the thoroughness of the tests, and I think it's OK for now, but in general some of them are very detailed and start to test implementation details (IMHO). Especially some of the primitives.test.js ones. Tests that check for implementation details, rather than the interfaces / "visible behavior" are usually hard to maintain because whenever your implementation changes, also your tests have to change. However, most of the times as long as the visible behavior is unchanged, it doesn't really matter how that is achieved.

I think for now we can keep this and if we realize that they start to become a nuisance we can think about how to change them once we are at that point.

Finally, as far as I can see these are not yet automatically run in a workflow, right? Can you add the necessary configuration for that?

Comment on lines 55 to 57
const result = infoBox.isHere(x, y);

expect(result).toBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const result = infoBox.isHere(x, y);
expect(result).toBe(false);
expect(infoBox.isHere(x, y)).toBe(false);

Would make the cases a few lines shorter. Similar for other cases below.

package.json Outdated
Copy link
Collaborator

@kjvbrt kjvbrt May 17, 2024

Choose a reason for hiding this comment

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

Can you make this a proper package.json with name and license,....

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

@@ -0,0 +1,22 @@
name: Run test for dmX on push to main and PR's
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
name: Run test for dmX on push to main and PR's
name: Build and test

Just make this a bit shorter to make the check section of the PRs a bit easier to read. The other information is not really necessary, since we know in which repository we are and in the end we don't care too much what triggered the workflow.

Copy link

github-actions bot commented May 23, 2024

PR Preview Action v1.4.7
Preview removed because the pull request was closed.
2024-05-23 15:45 UTC

@tmadlener tmadlener merged commit 6cc387c into key4hep:main May 23, 2024
2 checks passed
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