You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(middleware-code-coverage): allow coverage watermarks configuration via frontend (#145)
This feature enables the extension of default or ui5.yaml's Istanbul
configuration, so that certain settings could be adjusted from the
frontend.
JIRA: CPOUI5FOUNDATION-709
---------
Co-authored-by: Matthias Oßwald <[email protected]>
Co-authored-by: Günter Klatt <[email protected]>
The middleware adds an HTTP endpoint to the development server.
176
-
177
-
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`.
178
-
179
-
The instrumented code and the `sourcemap` are subsequently delivered to the client instead of the original `.js`-file.
174
+
### Front-End Configuration
180
175
181
-
## API
176
+
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`':
182
177
183
-
This REST API is the underlying foundation of the middleware.
178
+
```diff html title="unitTests.qunit.html"
179
+
...
184
180
185
-
**Note:** The `/.ui5/` path is reserved for UI5 Core modules and must not be used for third-party modules.
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.
191
-
192
-
**Example:**
193
-
194
-
```js
195
-
// OpenUI5
196
-
197
-
GET /resources/sap/m/ComboBox.js?instrument=true
198
-
GET /resources/sap/m/ComboBoxBase.js?instrument=true
199
-
GET /resources/sap/m/ComboBoxBaseRenderer.js?instrument=true
200
-
GET /resources/sap/m/ComboBoxRenderer.js?instrument=true
201
-
GET /resources/sap/m/ComboBoxTextField.js?instrument=true
202
-
GET /resources/sap/m/ComboBoxTextFieldRenderer.js?instrument=true
189
+
...
203
190
```
204
191
205
-
---
206
-
207
-
### GET `/.ui5/coverage/ping`
208
-
209
-
Healthcheck. Useful when checking for the middleware's existence.
210
-
211
-
**Example:**
212
-
213
-
```js
214
-
fetch("/.ui5/coverage/ping", {
215
-
method: "GET",
216
-
});
217
-
```
218
-
219
-
---
220
-
221
-
### POST `/.ui5/coverage/report`
192
+
## How It Works
222
193
223
-
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).
194
+
The middleware adds an HTTP endpoint to the development server. For more information about the endpoints, see the [API document](./docs/API.md).
224
195
225
-
**Note:** Report types could be defined and limited via the middleware's configuration.
196
+
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`.
226
197
227
-
**Example:**
228
-
229
-
```js
230
-
fetch("/.ui5/coverage/report", {
231
-
method: "POST",
232
-
body: JSON.stringify(window.__coverage__),
233
-
headers: {
234
-
"Content-Type": "application/json",
235
-
},
236
-
});
237
-
```
238
-
239
-
---
240
-
241
-
### GET `/.ui5/coverage/report/${reportType}`
242
-
243
-
Returns the generated report(s) from the last generation via the `/.ui5/coverage/report` route.
244
-
245
-
**Example:**
246
-
247
-
```js
248
-
GET /.ui5/coverage/report/html
249
-
GET /.ui5/coverage/report/lcov
250
-
```
198
+
The instrumented code and the `sourcemap` are subsequently delivered to the client instead of the original `.js`-file.
251
199
252
200
## Integration
253
201
254
-
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.
202
+
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.
255
203
256
204
### OpenUI5 QUnit Integration
257
205
258
206
The `qunit-coverage-istanbul.js` (part of `sap.ui.core` library) file requests the instrumented source files by the middleware. While the tests are running, `qunit-coverage-istanbul.js` takes care of collecting and storing the coverage records into the `window.__coverage__` global variable. After the tests are executed, `qunit-coverage-istanbul.js` sends this data to the middleware, which then generates the code coverage report. Afterwards, the code coverage is displayed on the test page.
259
207
260
-
### Custom Integration
261
-
262
-
Below is an example of a sample scenario to integrate UI5 Middleware Code Coverage.
This REST API is the underlying foundation of the middleware.
4
+
5
+
**Note:** The `/.ui5/` path is reserved for UI5 Core modules and must not be used for third-party modules.
6
+
7
+
---
8
+
### GET `{path/to/resource}?instrument=true`
9
+
10
+
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 the middleware's configuration, the query parameter is ignored.
Health check. Useful when checking for the middleware's existence.
30
+
31
+
**Example:**
32
+
33
+
```js
34
+
fetch("/.ui5/coverage/ping", {
35
+
method:"GET",
36
+
});
37
+
```
38
+
39
+
---
40
+
41
+
### POST `/.ui5/coverage/report`
42
+
43
+
Sends `__coverage__` data to the middleware. A static report is generated with the data provided. Reports can be accessed via the `/.ui5/coverage/report/${reportType}` route. The available report types can be found [here](https://github.com/istanbuljs/istanbuljs/tree/73c25ce79f91010d1ff073aa6ff3fd01114f90db/packages/istanbul-reports/lib).
44
+
45
+
**Note:** Report types can be defined and limited via the middleware's configuration.
46
+
47
+
**Note:** You can also provide report settings from the front end via the request body. Currently, only [`watermarks`](https://github.com/istanbuljs/nyc/blob/ab7c53b2f340b458789a746dff2abd3e2e4790c3/README.md#high-and-low-watermarks) are supported (available since UI5 1.119.0). Front end-defined settings take precedence over default or `ui5.yaml`-configured ones. For their usage in OpenUI5 HTML test pages, see the [Front-End Configuration](../README.md#frontend-configuration) section of the main document.
48
+
49
+
**Example:**
50
+
51
+
```js
52
+
fetch("/.ui5/coverage/report", {
53
+
method:"POST",
54
+
body:JSON.stringify({
55
+
coverage:window.__coverage__,
56
+
watermarks: { // Optional: report setting
57
+
statements: [75, 90],
58
+
functions: [75, 90],
59
+
branches: [75, 90],
60
+
lines: [75, 90]
61
+
}
62
+
}),
63
+
headers: {
64
+
"Content-Type":"application/json",
65
+
},
66
+
});
67
+
```
68
+
69
+
---
70
+
71
+
### GET `/.ui5/coverage/report/${reportType}`
72
+
73
+
Returns the most recent report(s) via the `/.ui5/coverage/report` route.
74
+
75
+
**Example:**
76
+
77
+
```js
78
+
GET/.ui5/coverage/report/html
79
+
GET/.ui5/coverage/report/lcov
80
+
```
81
+
82
+
## Custom Integration
83
+
84
+
Sample scenario to integrate UI5 Middleware Code Coverage:
0 commit comments