-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: master
Are you sure you want to change the base?
Conversation
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", |
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 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", |
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.
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.
register-istanbul.js
Outdated
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'); | ||
} |
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.
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 |
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.
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? |
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.
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.
2 similar comments
Hello @jwalton. I'm sorry, but I couldn't find any way to increase coverage on my code. Adding |
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
Hello here! It's been a while since I had to use coffee,-coverage and electron-mocha. 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 I've added a test to replicate this situation, it occurs when using blocks such as single-line for loops. |
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.