Skip to content

Conversation

@hitarth-gg
Copy link
Collaborator

Description of Change

  • Sets up the testing environment using Mocha and Chai to verify Devtron installation and ensure tracked IPC events are received by Devtron’s Background Service Worker.
  • Adds tests to verify that the .on method on ipcMain and both .on and .once methods on ipcRenderer are tracked correctly.
  • More tests will be added once this foundational PR for the testing setup is merged.

@hitarth-gg hitarth-gg marked this pull request as ready for review August 7, 2025 13:24
}

/* Run Mocha tests in the main process */
async function runMainProcessTests() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you speak a bit more as to why you chose to use Mocha's API programmatically to run tests rather than just run the mocha CLI tool?

Copy link
Collaborator Author

@hitarth-gg hitarth-gg Aug 13, 2025

Choose a reason for hiding this comment

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

I'm not very familiar with mocha and testing in Electron, but my understanding is that it might not be possible to use mocha CLI in this case since we're using a real Electron app to verify whether Devtron's Service Worker correctly receives the tracked IPC events. This requires us to fetch the ipcEvents list from the Service Worker in the main process and check whether the IPC events sent by Electron exist in that list.

I also used electron-browser-shell/packages/electron-chrome-extensions/spec/index.js as a reference when adding these tests, and it also uses Mocha's API in a similar way.

If there’s a better approach, I’m happy to try it.

Copy link
Member

@yangannyx yangannyx Aug 21, 2025

Choose a reason for hiding this comment

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

I like the simplicity of using a real electron app to test the extension installation. The alternative would be to mock out all of the Electron APIs involved with the extension setup, though I would imagine there's a lot to mock out and would be harder to set up and maintain

Copy link
Member

@yangannyx yangannyx Aug 21, 2025

Choose a reason for hiding this comment

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

(Non-blocking) We ideally want to add some more simple unit testing to code in src/extension, and support a more standard setup that lets contributors declare test files in the same directory level as their source folder, have the mocha CLI match on a file extension pattern etc. It would be great if we could get that set up to work along with the electron app runner testing and have the package test command run both

Copy link
Member

@yangannyx yangannyx Aug 21, 2025

Choose a reason for hiding this comment

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

Maybe you could set this up as a test in mocha that spawns a child process and asserts against the expected "All tests passed" stdout strings you're emitting. That way, you could just run have the package test command run the mocha CLI.
We should set up CI to run tests on every PR when we move devtron into electron. My feeling is that using the mocha CLI as the main runner will also make it easier for us to set up reporting test outcomes with CI

@hitarth-gg
Copy link
Collaborator Author

hitarth-gg commented Aug 14, 2025

@erickzhao I made a PR that deals with sending tracked IPC events from Devtron's service worker to the Electron main process - #280.
I'll rebase and update this PR once #280 gets merged.

@hitarth-gg
Copy link
Collaborator Author

I can update this PR if #282 doesn't seem like a viable option for testing.

@hitarth-gg
Copy link
Collaborator Author

Added Mocha CLI that spawns the Electron process and verifies its exit code to determine whether the Electron tests pass or not - 6dcd198

Copy link
Member

@dsanders11 dsanders11 left a comment

Choose a reason for hiding this comment

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

I set up a test workflow on GitHub Actions and added it to this branch. It ran clean on macOS but not on Linux and Windows, so temporarily skipping those and we'll do a follow-up to get it running there as well. Not immediately if they're legit failures, or the CI environment needs some tweaking.

Otherwise this LGTM and I'm going to go head and merge.

@dsanders11 dsanders11 merged commit 42c47c6 into main Aug 29, 2025
1 check passed
@dsanders11 dsanders11 deleted the chore/add-tests branch August 29, 2025 22:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants