-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Enable/document code coverage for extension testing #1096
Comments
Is it actually possible to run the tests with a coverage tool just yet? |
hmm... ping? :-) |
There's a very good sample here https://github.com/codecov/example-typescript-vscode-extension |
@DonJayamanne thank you - I'll have a look at that for sure :-) |
I'm facing the same issue. I don't wanna have a boilerplate configuration to run my test and get a code coverage (I'm talking about the @DonJayamanne example). It would be just greate to do this: "cover": "istanbul cover ./node_modules/vscode/bin/test" |
I managed to get this working for my extension, but it was a faff... Info is here: and here: I had to pre-instrument the files (since nyc doesn't seem to be able to inject itself when running tests because of how Code sits in the middle), manually save coverage from within the test files, manually re-map the JS to TS and also write empty coverage files so that un-executed files appear in the report! |
Istanbul is marked as deprecated. They recommend users move to const NYC = require('nyc');
// create an nyc instance, config here is the same as your package.json
const nyc = new NYC({
cwd: join(__dirname, '..', '..', '..'), // in debugging sessions, the cwd seems to be unset
reporter: ['text', 'html'],
instrument: true,
hookRequire: true,
hookRunInContext: true,
hookRunInThisContext: true,
});
nyc.createTempDirectory(); // create nyc' temp directory
nyc.wrap(); // hook into require() calls, etc.
runMyTests();
nyc.writeCoverageFile();
nyc.report(); // write out the reports! |
@connor4312 Nice. Thanks for sharing :) |
@connor4312 Thanks for sharing this snippet! Would you happen to have a more complete example? I've been trying to integrate your code into |
@dcermak here you go, this is now open source: https://github.com/microsoft/vscode-pwa/blob/master/src/test/testRunner.ts |
@connor4312 Thank you, that is greatly appreciated! |
Closing as a couple for samples and examples have been provided. Not sure we need to add documentation. |
From @gorkem on May 18, 2017 17:20
The way to use a code coverage framework such as istabuljs with extension tests should be explained on https://code.visualstudio.com/docs/extensions/testing-extensions
Copied from original issue: microsoft/vscode#26879
The text was updated successfully, but these errors were encountered: