question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature] Allow usage of custom Mocha initializer

See original GitHub issue
  • I’d be willing to implement this feature

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 of mocha for Electron apps that are built using Webpack (specifically electron-webpack).

Proposed Solution

Add a flag such as --electron to run electron-mocha wherever vanilla mocha would otherwise be used. This has been discussed over here: https://github.com/jprichardson/electron-mocha/issues/102

Drawbacks

  • It’s another dependency to keep up with (though it could probably be labeled as a peer dependency since not all users would need it)
  • electron-mocha includes a few flags that are not standard. These would need to be handed off to it somehow. Flags not used by regular mocha should quickly throw an error if a user tries to include them without --electron (this would probably provide some extra motivation for https://github.com/sysgears/mochapack/issues/34 to be tackled)
  • If devs are not building with electron-webpack their project structure might deviate from what’s expected. This means there would have to be a way to inform electron-mocha of what files to consider renderer vs. main

Alternatives

Currently have a POC project electron-playground which involves maintaining separate scripts for testing:

  • Code that has to be run through Webpack before testing (such as .vue files)
  • Code that relies on electron and runs in the main process
  • Code that relies on electron and runs in the renderer process.
  • e2e tests

The tests that require electron are named .e.spec.ts and those that require webpacking are named w.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 for main and renderer tests separately, but this could probably be handled gracefully by mochapack. That would condense all 3 unit test scripts here into one. Basically instead of running one instance of mocha, 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.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:21 (20 by maintainers)

github_iconTop GitHub Comments

2reactions
Jack-Barrycommented, May 6, 2020

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 --byom to point to a Mocha constructor function/factory. That function can do the work of determining any settings specific to itself, rather than having to keep track of more CLI options in mochapack. If mochapack picks up a value for byom then it just uses that module to initiate an instance of Mocha in the initMocha method or somewhere around that.

2reactions
Jack-Barrycommented, Jan 20, 2020

Finally caught up on things, jumping back on this throughout the rest of the month 🔨

Read more comments on GitHub >

github_iconTop Results From Across the Web

prepare option to allow async initialization before loading test ...
I came across a situation where async initialization before loading all test files has become necessary. The --require option allows us to ...
Read more >
Mocha 6.1.0 Python Scripting Guide - Boris FX
Creating a Custom Tracking Data Export; Customising Existing Exporters ... Most code in this guide uses the Mocha Pro python package for examples....
Read more >
Documentation - Mocha
Constructs a new Mocha instance with options . Parameters: Name, Type, Attributes, Description. options, Object, <optional>.
Read more >
Mocha beforeEach Explained With a Side-by-Side Comparison
The beforeEach method is a feature (hook) in test libraries that you can use to set preconditions for each test. Just like the...
Read more >
TypeScript and Mocha Hooks - Level Up Coding
Root Mocha Hooks apply to all tests in the entire test setup. How you use them is inevitably your decision — however, I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found