Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ui5/middleware-code-coverage

Package Overview
Dependencies
Maintainers
4
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ui5/middleware-code-coverage - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

15

CHANGELOG.md
# Changelog
## [1.1.0](https://github.com/SAP/ui5-tooling-extensions/compare/middleware-code-coverage-v1.0.3...middleware-code-coverage-v1.1.0) (2023-09-19)
### Features
* **middleware-code-coverage:** allow coverage watermarks configuration via frontend ([#145](https://github.com/SAP/ui5-tooling-extensions/issues/145)) ([ece9fa6](https://github.com/SAP/ui5-tooling-extensions/commit/ece9fa64e04a93d69d910a41016ad197fa0beae9))
### Dependencies
* bump istanbul-lib-instrument from 5.2.1 to 6.0.0 ([fbf8b29](https://github.com/SAP/ui5-tooling-extensions/commit/fbf8b29664fb6a9f953ea88dd22b14911be0dffe))
* bump istanbul-lib-report from 3.0.0 to 3.0.1 ([9bc4b39](https://github.com/SAP/ui5-tooling-extensions/commit/9bc4b39ba91aebcd34e3b1d91cdd0cf545cc7f46))
* bump istanbul-reports from 3.1.5 to 3.1.6 ([bd5a78a](https://github.com/SAP/ui5-tooling-extensions/commit/bd5a78abaf0cf8a1218db9b2e076442398e4c184))
* bump xml2js from 0.6.0 to 0.6.2 ([18904fe](https://github.com/SAP/ui5-tooling-extensions/commit/18904fee24f2a06ace088d2eb639154acb1375a6))
## [1.0.3](https://github.com/SAP/ui5-tooling-extensions/compare/middleware-code-coverage-v1.0.2...middleware-code-coverage-v1.0.3) (2023-04-18)

@@ -4,0 +19,0 @@

16

lib/coverage-reporter.js

@@ -15,3 +15,3 @@ import libReport from "istanbul-lib-report";

*
* @param {object} globalCoverageMap
* @param {object} coverageData
* @param {*} config

@@ -29,7 +29,17 @@ * @param {object} resources Resource collections

*/
export default async function(globalCoverageMap, config, resources, log) {
export default async function(coverageData, config, resources, log) {
let {coverage: globalCoverageMap, watermarks} = coverageData;
// For compatibility reasons with the old structure, we need first to check
// whether the "coverage" property is present in coverageData or use the
// whole coverageData object (old structure).
globalCoverageMap = globalCoverageMap || coverageData;
const coverageMap =
istanbulLibCoverage.createCoverageMap(globalCoverageMap);
const {report: reportConfig} = config;
const reportConfig = {...config.report};
// Frontend config for watermarks should take precedence if present.
reportConfig.watermarks = {...reportConfig.watermarks, ...watermarks};
// Get & stash code from the resources

@@ -36,0 +46,0 @@ // Later this would be needed to create the reports

28

package.json
{
"name": "@ui5/middleware-code-coverage",
"version": "1.0.3",
"version": "1.1.0",
"description": "UI5 Tooling middleware to instrument code coverage with Istanbul",

@@ -31,24 +31,28 @@ "author": {

],
"engines": {
"node": "^16.18.0 || >=18.12.0"
},
"dependencies": {
"body-parser": "^1.20.2",
"istanbul-lib-coverage": "^3.2.0",
"istanbul-lib-instrument": "^5.2.1",
"istanbul-lib-report": "^3.0.0",
"istanbul-reports": "^3.1.5",
"istanbul-lib-instrument": "^6.0.0",
"istanbul-lib-report": "^3.0.1",
"istanbul-reports": "^3.1.6",
"router": "^1.3.8",
"serve-static": "^1.15.0",
"xml2js": "^0.5.0"
"xml2js": "^0.6.2"
},
"devDependencies": {
"@istanbuljs/esm-loader-hook": "^0.2.0",
"ava": "^5.2.0",
"depcheck": "^1.4.3",
"eslint": "^8.38.0",
"ava": "^5.3.1",
"depcheck": "^1.4.6",
"eslint": "^8.49.0",
"eslint-config-google": "^0.14.0",
"eslint-plugin-ava": "^14.0.0",
"esmock": "^2.2.1",
"get-port": "^6.1.2",
"esmock": "^2.5.1",
"get-port": "^7.0.0",
"nyc": "^15.1.0",
"sinon": "^15.0.3",
"supertest": "^6.3.3"
"sinon": "^15.2.0",
"supertest": "^6.3.3",
"execa": "^8.0.1"
},

@@ -55,0 +59,0 @@ "scripts": {

@@ -11,8 +11,9 @@ # UI5 Middleware Code Coverage

## Sample
You find this middleware in action in the [OpenUI5 Sample App](https://github.com/SAP/openui5-sample-app).
## Requirements
This middleware requires UI5 Tooling v3 and is meant for UI5 1.113 and above.
> **Warning**
>
> The `qunit-coverage-istanbul.js` module is planned to be part of OpenUI5 1.113.0, which is not released yet. If you would like to try out the code coverage module beforehand, use the nightly CDN version of UI5 when bootstrapping your tests.

@@ -96,3 +97,3 @@ ## Install

```html title="unitTests.qunit.html"
```diff html title="unitTests.qunit.html"
<!DOCTYPE html>

@@ -115,3 +116,4 @@ <html>

<script src="../../resources/sap/ui/qunit/qunit-junit.js"></script>
<script src="../../resources/sap/ui/qunit/qunit-coverage-istanbul.js"
- <script src="../../resources/sap/ui/qunit/qunit-coverage.js"
+ <script src="../../resources/sap/ui/qunit/qunit-coverage-istanbul.js"
data-sap-ui-cover-only="ui5/sample/"

@@ -175,84 +177,31 @@ data-sap-ui-cover-never="ui5/sample/test/"></script>

## How it works
### Front-End Configuration
The middleware adds an HTTP endpoint to the development server.
You can override [`watermarks`](https://github.com/istanbuljs/nyc/blob/ab7c53b2f340b458789a746dff2abd3e2e4790c3/README.md#high-and-low-watermarks) (since UI5 1.119.0) via data attributes in the script tag for `qunit-coverage-istanbul.js`':
The custom middleware intercepts every `.js`-file before it is sent to the client. The file is then instrumented on the fly, including the dynamic creation of a `sourcemap`.
```diff html title="unitTests.qunit.html"
...
The instrumented code and the `sourcemap` are subsequently delivered to the client instead of the original `.js`-file.
<script src="../../resources/sap/ui/qunit/qunit-coverage-istanbul.js"
data-sap-ui-cover-only="ui5/sample/"
data-sap-ui-cover-never="ui5/sample/test/"
+ data-sap-ui-cover-watermarks-statements="[90,95]"
+ data-sap-ui-cover-watermarks-functions="[90,95]"
+ data-sap-ui-cover-watermarks-branches="[90,95]"
+ data-sap-ui-cover-watermarks-lines="[90,95]"></script>
## API
This REST API is the underlying foundation of the middleware.
**Note:** The `/.ui5/` path is reserved for UI5 Core modules and must not be used for third-party modules.
---
### GET `{path/to/resource}?instrument=true`
A resource could be instrumented for code coverage by appending `?instrument=true` as a query parameter. **Note:** If a resource has already been excluded via `excludePatterns` in middleware's configuration, the query parameter is ignored.
**Example:**
```js
// OpenUI5
GET /resources/sap/m/ComboBox.js?instrument=true
GET /resources/sap/m/ComboBoxBase.js?instrument=true
GET /resources/sap/m/ComboBoxBaseRenderer.js?instrument=true
GET /resources/sap/m/ComboBoxRenderer.js?instrument=true
GET /resources/sap/m/ComboBoxTextField.js?instrument=true
GET /resources/sap/m/ComboBoxTextFieldRenderer.js?instrument=true
...
```
---
## How It Works
### GET `/.ui5/coverage/ping`
The middleware adds an HTTP endpoint to the development server. For more information about the endpoints, see the [API document](./docs/API.md).
Healthcheck. Useful when checking for the middleware's existence.
The custom middleware intercepts every `.js`-file before it is sent to the client. The file is then instrumented on the fly, which includes the dynamic creation of a `sourcemap`.
**Example:**
The instrumented code and the `sourcemap` are subsequently delivered to the client instead of the original `.js`-file.
```js
fetch("/.ui5/coverage/ping", {
method: "GET",
});
```
---
### POST `/.ui5/coverage/report`
Sends `__coverage__` data to the middleware. A static report is generated with the provided data. Reports could be accessed via the `/.ui5/coverage/report/${reportType}` route. The available report types could be found [here](https://github.com/istanbuljs/istanbuljs/tree/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib).
**Note:** Report types could be defined and limited via the middleware's configuration.
**Example:**
```js
fetch("/.ui5/coverage/report", {
method: "POST",
body: JSON.stringify(window.__coverage__),
headers: {
"Content-Type": "application/json",
},
});
```
---
### GET `/.ui5/coverage/report/${reportType}`
Returns the generated report(s) from the last generation via the `/.ui5/coverage/report` route.
**Example:**
```js
GET /.ui5/coverage/report/html
GET /.ui5/coverage/report/lcov
```
## Integration
The middleware is integrated into OpenUI5 out of the box, but it is not limited just to it. With the configuration and the public API, developers could set up the middleware to suit their projects' needs.
The middleware is integrated into OpenUI5 out of the box, but you are not limited by this. With the [configuration](#configuration) and the [public API](./docs/API.md), you can set up the middleware to suit your projects' needs.

@@ -263,45 +212,3 @@ ### OpenUI5 QUnit Integration

### Custom Integration
Below is an example of a sample scenario to integrate UI5 Middleware Code Coverage.
```js
// A module in the browser
const isMiddlewareAvailable = await fetch("/.ui5/coverage/ping", {
method: "GET",
});
if (isMiddlewareAvailable) {
const generatedReports = await fetch("/.ui5/coverage/report", {
method: "POST",
body: JSON.stringify(window.__coverage__),
headers: {
"Content-Type": "application/json",
},
});
// Extract the html report from the list of reports
const htmlReport = generatedReports.availableReports.find(
(report) => report.report === "html"
);
if (htmlReport) {
const body = document.body;
const iFrameElem = document.createElement("iframe");
iFrameElem.src = "/.ui5/coverage/report/" + htmlReport.destination;
iFrameElem.style.border = "none";
iFrameElem.style.width = "100%";
iFrameElem.style.height = "100vh";
iFrameElem.sandbox = "allow-scripts";
body.appendChild(iFrameElem);
}
}
```
## Code of Conduct

@@ -308,0 +215,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc