@telefonica/acceptance-testing 3.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -200,7 +200,10 @@ test('example screenshot test', async () => {
200
200
  });
201
201
  ```
202
202
 
203
- `createApiEndpointMock` automatically mocks CORS response headers and preflight (`OPTIONS`) requests for you.
203
+ - `createApiEndpointMock` automatically mocks CORS response headers and preflight (`OPTIONS`) requests for
204
+ you.
205
+ - Both `interceptRequest` and `createApiEndpointMock` return a jest
206
+ [mock function](https://jestjs.io/docs/mock-function-api/#reference).
204
207
 
205
208
  ### Using globs
206
209
 
@@ -251,26 +254,63 @@ await elementHandle.uploadFile(prepareFile('/path/to/file'));
251
254
 
252
255
  ## Collecting coverage
253
256
 
254
- This library automatically collects code coverage after each test by reading the `window.__coverage__` object
255
- if available.
257
+ Set the `COLLECT_ACCEPTANCE_COVERAGE` environment variable to enable coverage collection.
256
258
 
257
- To create that object you should instrument the code with an `istanbul` compatible tool (for example
258
- [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul)).
259
+ The code must be instrumented with [nyc](https://github.com/istanbuljs/nyc/blob/main/docs/instrument.md),
260
+ [babel-plugin-istanbul](https://github.com/istanbuljs/babel-plugin-istanbul) or any
261
+ [istanbul](https://github.com/istanbuljs/istanbuljs) compatible tool.
259
262
 
260
- The coverage report for each test will be saved as `json` files. To change the destination folder, set the
261
- `coveragePath` property in your config. The default value is `reports/coverage-acceptance`.
263
+ ### Frontend coverage information
264
+
265
+ After each test the coverage information will be collected by reading the `window.__coverage__` object from
266
+ the opened page.
267
+
268
+ ### Backend coverage information
269
+
270
+ To collect coverage from your backend, you must create an endpoint that serves the coverage information and
271
+ specify it the `coverageUrls` property in your config. The library will make a `GET` request to each URL and
272
+ save the report from the response as a `json` file. The default value is `[]`.
273
+
274
+ The backend coverage will be collected after all the tests in the suite have run.
275
+
276
+ The response must be a JSON with the following structure: `{coverage: data}`.
277
+
278
+ Example route in NextJS to serve coverage information:
279
+
280
+ ```ts
281
+ import {NextResponse} from 'next/server';
282
+
283
+ export const GET = (): NextResponse => {
284
+ const coverage = (globalThis as any).__coverage__;
285
+ if (coverage) {
286
+ return NextResponse.json({coverage});
287
+ }
288
+ return NextResponse.json({error: 'Not found'}, {status: 404});
289
+ };
290
+
291
+ export const dynamic = 'force-dynamic';
292
+ ```
293
+
294
+ ### Configuration
295
+
296
+ The coverage information will be saved as `json` files. To change the destination folder, set the
297
+ `coveragePath` property in your config. The default value is `reports/coverage-acceptance`. The `json` files
298
+ will be stored inside `<coveragePath>/.nyc_output`.
262
299
 
263
300
  Example config:
264
301
 
265
302
  ```json
266
303
  {
267
304
  "acceptanceTests": {
268
- "coveragePath": "coverage/acceptance"
305
+ "coveragePath": "coverage/acceptance",
306
+ "coverageUrls": ["http://localhost:3000/api/coverage"]
269
307
  }
270
308
  }
271
309
  ```
272
310
 
273
- After running the tests, you can use a tool like `nyc` to generate the coverage summaries.
311
+ ### Generate coverage reports
312
+
313
+ After running the tests, you can use a tool like `nyc` to generate the coverage reports.
274
314
 
275
315
  ## Troubleshooting
276
316