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 unit and E2E tests #479

Merged
merged 50 commits into from
Jan 30, 2024
Merged

Add unit and E2E tests #479

merged 50 commits into from
Jan 30, 2024

Conversation

AgnesToulet
Copy link
Contributor

@AgnesToulet AgnesToulet commented Nov 7, 2023

Fixes #434

@AgnesToulet AgnesToulet marked this pull request as ready for review November 23, 2023 15:28
@AgnesToulet AgnesToulet requested review from a team, juanicabanas and lucychen-grafana and removed request for a team November 23, 2023 15:28
@AgnesToulet AgnesToulet changed the title WIP: Add unit and E2E tests Add unit and E2E tests Nov 23, 2023
Copy link
Contributor

@evictorero evictorero left a comment

Choose a reason for hiding this comment

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

I left some comments with thoughts and ideas but it works like a charm.

src/service/http-server.integration.test.ts Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
// It writes the diff file to /testdata if tests are run with SAVE_DIFF=true.
function compareImage(testName: string, responseBody: any): number {
const goldenFilePath = path.join(goldenFilesFolder, `${testName}.png`);
if (process.env['UPDATE_GOLDEN'] === 'true') {
Copy link
Contributor

Choose a reason for hiding this comment

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

We are running all test cases only to update the images and the compareImage has this side effect, which I don't think should be here. Maybe we can create a specific script to only update images instead of running all tests and call it from yarn test-update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about updating the test-update command to:

"test-update": "cross-env UPDATE_GOLDEN=true jest -t=screenshot",

I'm worried that if we create a separate script, we will have a lot of duplicated code with the test. But I agree that we don't need to run all the tests so this would only run the screenshot test. We could do the same for the test-diff command.

Copy link
Contributor

Choose a reason for hiding this comment

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

The update script should be a loop over a map with a request and writing the response to an image. I think it should be decoupled entirely of the test suite. Maybe sounds like duplicating because that is what primarily tests are, just a request and comparing the response.
The map could contain a URL (the one used to render a panel) and an image name.
However, this shouldn't be a blocker, maybe this is too much and we can move on with this PR that is a great start and refactor later if needed.

src/service/http-server.integration.test.ts Outdated Show resolved Hide resolved
src/service/http-server.integration.test.ts Outdated Show resolved Hide resolved
@AgnesToulet
Copy link
Contributor Author

@evictorero Thanks a lot for your thorough review! I updated the PR according to your feedback. I also had an issue with the Drone pipeline so I added a docker-compose file and some instructions to run tests in a Drone-like environment locally so this is easier to troubleshoot.

It should work as before but please do test again to ensure I didn't break anything on non-Windows environments.

Copy link
Contributor

@evictorero evictorero left a comment

Choose a reason for hiding this comment

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

Looks great! Left one comment to think about it.
I think it's ready for merge but only thing that bothers me a bit is the test output, when successful, it writes a lot of console.log messages and it confuses me because the tests are all successful.
Can we remove the output messages to avoid noise when all tests succeed?

src/service/http-server.integration.test.ts Dismissed Show dismissed Hide dismissed
@AgnesToulet
Copy link
Contributor Author

I have hidden the logs when tests are successful 👍

For the update, I agree with you that it could be better, but I think it will make more sense to do it when we have more tests.

@AgnesToulet AgnesToulet merged commit aca8ee6 into master Jan 30, 2024
4 checks passed
@AgnesToulet AgnesToulet deleted the add-tests branch January 30, 2024 08:16
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.

Unit testing framework for renderer
2 participants