-
Notifications
You must be signed in to change notification settings - Fork 27
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
[Feature] Allow usage of custom Mocha initializer #46
Comments
electron-mocha
in lieu of mocha
@Jack-Barry Thanks, its okay with me to merge support for |
@larixer Cool deal, I'll start looking into the specifics on this one |
Kind of parchuting into this one so I hope I am not widly off base. Does calling electron mocha require a different signature the mocha or is it a drop in replacement? If it's a drop in replacement I wonder if the more generalized solution to allow the user to specify a custom command to invoke? |
@JamesMcMahon I'm not sure if you got a chance to read the discussion referenced above but according to their maintainers it's mostly a drop in replacement. I haven't had a chance to really dig in, but from what I gathered What I have been looking into first though is tackling #34 as the CLI argument parsing will probably have some implications here, and seems to be the root of a few other open issues at the moment. I've initiated a PR with |
That's the part I haven't had a chance to dig into yet - initially that's what I thought it was doing under the hood already but once I saw a little bit of what's going on in One other place I do foresee needing to be re-approached if the API continues to be used is |
@Jack-Barry Don't also forget that
|
@larixer I'm not 100% certain but if Investigation NotesAdding some other notes of what I've been investigating here for reference and discussion.
Test NotesNot sure what would need to be tested, or what tests would be OK to drop if argument parsing is to be handled differently, but my thoughts on what functionality would need to be tested base level:
New Flag ProposalsI might have the glob patterns wrong and they can be adjusted, just trying to get the ideas down here. Some might not be needed once the implementation details are hammered out, but these are what it seems like would be necessary:
|
@Jack-Barry Yep, makes sense to me. Though maybe boolean |
After sitting down with a pen and paper, and really thinking into this before writing any specific code for it - I think @JamesMcMahon was on to something before with the concept of something like a custom Mocha initializer to run. I'm calling it Basically, have a The big road block at the moment is that Mochapack is re-implementing quite a bit of what Mocha already does. Still waiting on this PR to at least help with that. I think if we can implement a Here's a high level overview of how it might work: This would, of course involve a big change to some of Mochapack's internals, but I believe it could be accomplished without changing anything about how users already interface with it as intended. It almost feels like a |
@larixer and @JamesMcMahon I'm getting into the argument parsing aspect of this, and there's a couple of scenarios I want to get some second/third opinions on. With the new feature, a user can pass arguments for
The problem I'm running up against is how to handle the
Is pretty straightforward to assign the options as: {
byomOptions: {
path: 'my-mocha.js',
args: ['--unknown']
},
clearTerminal: true,
files: ['./my-test-file.js'],
mochaOptions: {
bail: true
}
} But what happens in cases where the unknown flags are placed before the files? Like this:
The resulting object might end up being: {
byomOptions: {
path: 'my-mocha.js',
args: ['--unknown', './my-test-file.js']
},
clearTerminal: true,
files: ['./test'], // default value
mochaOptions: {
bail: true
}
} There are a few ways to account for this, I'm just not sure which should be used:
Obviously each approach has its own pain points. Option 1 requires remembering to order arguments a specific way, option 2 rubs up against typical Mocha CLI usage, and option 3 adds more length to the test script. I'm inclined to think option 3 is the better of them since it is more explicit. There could also be a secondary flag Please let me know if you see a glaring issue with option 3. I'm going to write up the tests around it for now, but can shift course if needed. Thanks! |
Implemented a new Basically I'm building it out in a I think it's a little easier to follow what it's doing, tried to break it up into smaller, more digestible chunks that can be more easily maintained. One headache that arose is that for some reason |
@Jack-Barry Thanks! The code looks very clean! |
Mostly sharing to ensure there's no double work done toward #34 or #9. The changes here directly relate to those. A little more progress forward: split Mocha options into their own file which at the moment has parity with As far as I know, the user's Also - parsing the Mocha config can probably also just be handed off to |
@Jack-Barry Yep, user's |
Hi @Jack-Barry, are you saying you will cover #9 as part of this PR? I was going to start looking at it, but looks like you are already doing so? |
@jpspringall Yeah, it should be covered here. I've had to focus on some year-end wrap ups at work, but will be jumping back on this in the next week or two |
Finally caught up on things, jumping back on this throughout the rest of the month 🔨 |
Relevant to #9 Made some solid progress on this here: buildMochapackOptions/index.ts This method uses Mocha's configuration file and opts file parsers, so it can handle any file extension that Mocha supports. Anything in the config file that is not specific to Mochapack gets passed along as part of the Mocha configuration to be used when initializing Mocha. Still waiting on this for CLI argument parsing, but at least for now it's a lot easier to establish parity since changes will only need to be made in mochaOptions.ts Next steps:
|
Getting a chance to start looking at this in off-hours again and hoping optimistically to have it tackled in April or May, just making some investigatory notes for now (so I don't forget where I'm at on this when I come back to it 😝). Looks like a lot of what is going on in Once the config for Mocha and the config for Webpack is being handled as much as possible as it should be by their code, we arrive at the meat n' taters of what Mochapack is responsible for. I think it's mostly a matter of
I've still got some digging around in |
Probably won't be able to get around to this for a while, but some notes after completing #63 : This will be pretty straightforward. To simplify it, I'm only going to add a flag for |
User Story
It's a pretty big barrier to entry for testing to get a good environment set up for Electron projects. It would be great to be able to run
electron-mocha
instead ofmocha
for Electron apps that are built using Webpack (specificallyelectron-webpack
).Proposed Solution
Add a flag such as
--electron
to runelectron-mocha
wherever vanillamocha
would otherwise be used. This has been discussed over here: jprichardson/electron-mocha#102Drawbacks
electron-mocha
includes a few flags that are not standard. These would need to be handed off to it somehow. Flags not used by regularmocha
should quickly throw an error if a user tries to include them without--electron
(this would probably provide some extra motivation for [Feature] Pass through arguments into Mocha #34 to be tackled)electron-webpack
their project structure might deviate from what's expected. This means there would have to be a way to informelectron-mocha
of what files to considerrenderer
vs.main
Alternatives
Currently have a POC project
electron-playground
which involves maintaining separate scripts for testing:.vue
files)electron
and runs in themain
processelectron
and runs in therenderer
process.The tests that require electron are named
.e.spec.ts
and those that require webpacking are namedw.spec.ts
to ensure the test runner does not try and run something it can't handle per specific script.This is cumbersome.
electron-mocha
does involve spinning up a process formain
andrenderer
tests separately, but this could probably be handled gracefully bymochapack
. That would condense all 3 unit test scripts here into one. Basically instead of running one instance ofmocha
, it would spin up two concurrently but relying on the same bundled code.e2e tests can and should be handled separately, so handling those in a separate script is not an issue.
The text was updated successfully, but these errors were encountered: