- 
                Notifications
    You must be signed in to change notification settings 
- Fork 106
test: set up testing environment #279
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
Conversation
58100ac    to
    f853aae      
    Compare
  
    | } | ||
|  | ||
| /* Run Mocha tests in the main process */ | ||
| async function runMainProcessTests() { | 
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| @erickzhao I made a PR that deals with sending tracked IPC events from Devtron's service worker to the Electron main process - #280. | 
| I can update this PR if #282 doesn't seem like a viable option for testing. | 
f853aae    to
    a250534      
    Compare
  
    | Added Mocha CLI that spawns the Electron process and verifies its exit code to determine whether the Electron tests pass or not - 6dcd198 | 
There was a problem hiding this 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.
Description of Change
.onmethod onipcMainand both.onand.oncemethods onipcRendererare tracked correctly.