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

Support electron-mocha #87

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Support electron-mocha #87

wants to merge 4 commits into from

Conversation

feugy
Copy link

@feugy feugy commented Jul 21, 2017

Electron-mocha is a special flavour of mocha that runs test within Electron context.

It works fine with nyc, as long as instrumentation is done by using mocha hooks, like coffee-coverage does.

But I found out it requires some small adaptation to make it works.

package.json Outdated
@@ -47,18 +47,24 @@
"benchmark": "^2.0.0",
"chai": "^3.0.0",
"coveralls": "^2.11.2",
"electron": "1.6.11",
"electron-mocha": "4.0.0",
Copy link
Author

Choose a reason for hiding this comment

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

I took the liberty to add them as dev dependencies, in order to test them

package.json Outdated
"coverage-report": "istanbul report text-summary lcov",
"prepublish": "npm run test",
"test": "npm run build && nyc mocha --growl",
"test:electron": "npm run build && nyc electron-mocha --renderer test/**/*.coffee",
Copy link
Author

@feugy feugy Jul 21, 2017

Choose a reason for hiding this comment

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

mocha & electron-mocha both use mocha.opts file.
I added test:electron command to run the full test suite in electron context, which was a simple and good-enough test

But because electron-mocha doesn't support --growl flag, I had to move it above.

if (process.env.NYC_CONFIG) {
var config = JSON.parse(process.env.NYC_CONFIG);
outFile = resolve(config.cwd, config.tempDirectory, process.env.NYC_ROOT_ID + '.json');
}
Copy link
Author

Choose a reason for hiding this comment

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

This makes nyc aware of the report produced by coffee-coverage.
It generates the outFile in the proper place so nyc can parse it during its report phase.

try
dirName = path.dirname options.writeOnExit
mkdirs dirName
fs.writeFileSync options.writeOnExit, JSON.stringify(global[options.coverageVar])
catch err
console.error "Failed to write coverage data", err.stack ? err
if global.window?
# support electron-mocha end of run
window.addEventListener 'unload', report
Copy link
Author

Choose a reason for hiding this comment

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

This is required to support electron-mocha, because this hook don't have access to process's exit event.

before ->
Benchmark.options.maxTime = 1

it "should exclude files quickly", (done) ->
# Can't run benchmark on electron-mocha
return @skip() if global.window?
Copy link
Author

Choose a reason for hiding this comment

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

For an unknown reason, Benchmark is undefined when running this with electron-mocha.
As the intent was only to check that coverage was working, I though this could be acceptable to skip it.

@coveralls
Copy link

coveralls commented Jul 21, 2017

Coverage Status

Coverage decreased (-0.3%) to 76.545% when pulling 0ec8c32 on feugy:master into 36e8912 on benbria:master.

@coveralls
Copy link

coveralls commented Jul 21, 2017

Coverage Status

Coverage decreased (-0.3%) to 76.545% when pulling d9341fd on feugy:master into 36e8912 on benbria:master.

@coveralls
Copy link

coveralls commented Jul 21, 2017

Coverage Status

Coverage decreased (-47.6%) to 26.998% when pulling c8e91b1 on feugy:master into e80b5ba on benbria:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 76.545% when pulling 0c50cce on feugy:master into 36e8912 on benbria:master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 76.545% when pulling 0c50cce on feugy:master into 36e8912 on benbria:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 76.545% when pulling 0c50cce on feugy:master into 36e8912 on benbria:master.

@feugy
Copy link
Author

feugy commented Jul 21, 2017

Hello @jwalton.

I'm sorry, but I couldn't find any way to increase coverage on my code. Adding test:electron to CI to cover the new report in src/register.coffee didn't helped.

feugy added 4 commits August 26, 2018 08:20
Allow NYC usage with electron-mocha
Between coffeescript 2.0.2 and 2.3.1, an internal changes was introduce, and AST nodes don't necessary have locationData attached
@feugy
Copy link
Author

feugy commented Aug 26, 2018

Hello here!

It's been a while since I had to use coffee,-coverage and electron-mocha.
Yesterday I find out a regression introduced by the newest version of the coffeescript compiler.

Between coffeescript 2.0.2 and 2.3.1 (the latest at the moment), an internal changes was introduce, and AST nodes don't necessary have locationData attached.

I've added a test to replicate this situation, it occurs when using blocks such as single-line for loops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants