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

[FEATURE] Add iframe coverage support #194

Merged
merged 6 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
**Table of Contents**
- [About](#about)
- [Quickstart](#quickstart)
- [Installation](#installation)
- [Configuration](#configuration)
- [Execution](#execution)
- [Karma configuration requirements](#karma-configuration-requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Execution](#execution)
- [Karma Configuration Requirements](#karma-configuration-requirements)
- [Options](#options)
- [url](#url)
- [type](#type)
- [paths](#paths)
- [configPath](#configPath)
- [mode](#mode)
- [html](#html)
- [script](#script)
- [testpage](#testpage)
- [urlParameters](#urlParameters)
- [config](#config)
- [tests](#tests)
- [url](#url)
- [type](#type)
- [paths](#paths)
- [configPath](#configpath)
- [mode](#mode)
- [html](#html)
- [script](#script)
- [testpage](#testpage)
- [urlParameters](#urlparameters)
- [config](#config)
- [tests](#tests)
- [API](#api)
- [helper](#helper)
- [configureIframeCoverage](#configureiframecoverage)
- [License](#license)


Expand Down Expand Up @@ -323,6 +326,31 @@ ui5: {
}
```

## API

### helper

This plugin also comes with a helper module to be used in your Karma configuration file.

#### configureIframeCoverage

Enables code coverage for iframes.
Can only be used in combination with the [karma-coverage](https://github.com/karma-runner/karma-coverage) plugin (v2.0.0+).

Must be called from the karma configuration function after the coverage plugin has been configured.
The `config` object must be passed as a parameter.

```js
module.exports = function(config) {
config.set({

// ...

});
require("karma-ui5/helper").configureIframeCoverage(config);
};
```

## License
(c) Copyright 2019 SAP SE or an SAP affiliate company

Expand Down
20 changes: 20 additions & 0 deletions helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Enables coverage reporting when an iframe is used.
*
* Will set/overwrite the config option:
* - config.coverageReporter.instrumenterOptions.istanbul.coverageGlobalScope
*
* @param {object} config karma configuration object
*/
const configureIframeCoverage = (config) => {
matz3 marked this conversation as resolved.
Show resolved Hide resolved
// set the coverageGlobalScope
config.coverageReporter = config.coverageReporter || {};
config.coverageReporter.instrumenterOptions = config.coverageReporter.instrumenterOptions || {};
config.coverageReporter.instrumenterOptions.istanbul = config.coverageReporter.instrumenterOptions.istanbul || {};
config.coverageReporter.instrumenterOptions.istanbul.coverageGlobalScope =
"(function() { var g=window;while(!g.__karma__&&g!==g.parent){g=g.parent;}; return g; })();";
};

module.exports = {
configureIframeCoverage
};
2 changes: 2 additions & 0 deletions lib/client/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ require("./discovery.js");
testWindow = null;
runTestPage(i + 1);
} else {
// Also merge coverage results from karma window
mergeCoverage(window.__coverage__);
karma.complete({
coverage: coverageMap ? coverageMap.toJSON() : undefined
});
Expand Down
Loading