wdio-monocart-service 1.0.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/LICENSE +21 -0
- package/README.md +27 -0
- package/lib/index.d.ts +29 -0
- package/lib/index.js +78 -0
- package/package.json +44 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 cenfun
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# wdio-monocart-service
|
|
2
|
+
[](https://www.npmjs.com/package/wdio-monocart-service)
|
|
3
|
+
[](https://www.npmjs.com/package/wdio-monocart-service)
|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
> A [WebdriverIO](https://github.com/webdriverio/webdriverio) service for [monocart coverage reports](https://github.com/cenfun/monocart-coverage-reports)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
```sh
|
|
11
|
+
npm i wdio-monocart-service
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
```js
|
|
16
|
+
// wdio.conf.js
|
|
17
|
+
{
|
|
18
|
+
services: [
|
|
19
|
+
['monocart', {
|
|
20
|
+
name: 'My WebdriverIO Coverage Report',
|
|
21
|
+
outputDir: 'coverage-reports'
|
|
22
|
+
}]
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Check repo [monocart coverage reports](https://github.com/cenfun/monocart-coverage-reports) for more options.
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
CoverageReportOptions,
|
|
3
|
+
ReportDescription,
|
|
4
|
+
V8CoverageEntry,
|
|
5
|
+
Watermarks,
|
|
6
|
+
CoverageResults,
|
|
7
|
+
CoverageSummary,
|
|
8
|
+
MetricsSummary,
|
|
9
|
+
CoverageFile,
|
|
10
|
+
CoverageRange,
|
|
11
|
+
IgnoredRange,
|
|
12
|
+
AddedResults,
|
|
13
|
+
CoverageReport
|
|
14
|
+
} from "monocart-coverage-reports";
|
|
15
|
+
|
|
16
|
+
export type {
|
|
17
|
+
CoverageReportOptions,
|
|
18
|
+
ReportDescription,
|
|
19
|
+
V8CoverageEntry,
|
|
20
|
+
Watermarks,
|
|
21
|
+
CoverageResults,
|
|
22
|
+
CoverageSummary,
|
|
23
|
+
MetricsSummary,
|
|
24
|
+
CoverageFile,
|
|
25
|
+
CoverageRange,
|
|
26
|
+
IgnoredRange,
|
|
27
|
+
AddedResults,
|
|
28
|
+
CoverageReport
|
|
29
|
+
}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { CoverageReport } from 'monocart-coverage-reports';
|
|
2
|
+
|
|
3
|
+
export default class CoverageReportService {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `serviceOptions` contains all options specific to the service
|
|
7
|
+
* e.g. if defined as follows:
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* services: [['monocart', { outputDir: 'coverage-reports' }]]
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* the `serviceOptions` parameter will be: `{ outputDir: 'coverage-reports' }`
|
|
14
|
+
*/
|
|
15
|
+
constructor(serviceOptions, capabilities, config) {
|
|
16
|
+
this.coverageReport = new CoverageReport({
|
|
17
|
+
... serviceOptions
|
|
18
|
+
});
|
|
19
|
+
this.coverageReport.cleanCache();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* this browser object is passed in here for the first time
|
|
24
|
+
*/
|
|
25
|
+
before(config, capabilities, browser) {
|
|
26
|
+
this.browser = browser;
|
|
27
|
+
// something before all tests are run, e.g.
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async after(exitCode, config, capabilities) {
|
|
31
|
+
// something after all tests are run
|
|
32
|
+
if (this.coverageReport.hasCache()) {
|
|
33
|
+
await this.coverageReport.generate();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async beforeTest(test, context) {
|
|
38
|
+
// something before each Mocha/Jasmine test run
|
|
39
|
+
const puppeteer = await this.browser.getPuppeteer();
|
|
40
|
+
if (puppeteer) {
|
|
41
|
+
const page = (await puppeteer.pages())[0];
|
|
42
|
+
if (page) {
|
|
43
|
+
await Promise.all([
|
|
44
|
+
page.coverage.startJSCoverage({
|
|
45
|
+
resetOnNavigation: false,
|
|
46
|
+
includeRawScriptCoverage: true
|
|
47
|
+
}),
|
|
48
|
+
page.coverage.startCSSCoverage({
|
|
49
|
+
resetOnNavigation: false
|
|
50
|
+
})
|
|
51
|
+
]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async afterTest(test, context) {
|
|
58
|
+
const puppeteer = await this.browser.getPuppeteer();
|
|
59
|
+
if (puppeteer) {
|
|
60
|
+
const page = (await puppeteer.pages())[0];
|
|
61
|
+
if (page) {
|
|
62
|
+
const [jsCoverage, cssCoverage] = await Promise.all([
|
|
63
|
+
page.coverage.stopJSCoverage(),
|
|
64
|
+
page.coverage.stopCSSCoverage()
|
|
65
|
+
]);
|
|
66
|
+
// to raw V8 script coverage
|
|
67
|
+
const coverageList = [... jsCoverage.map((it) => {
|
|
68
|
+
return {
|
|
69
|
+
source: it.text,
|
|
70
|
+
... it.rawScriptCoverage
|
|
71
|
+
};
|
|
72
|
+
}), ... cssCoverage];
|
|
73
|
+
await this.coverageReport.add(coverageList);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wdio-monocart-service",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "WebdriverIO Monocart Coverage Reports",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./lib/index.d.ts",
|
|
10
|
+
"default": "./lib/index.js"
|
|
11
|
+
},
|
|
12
|
+
"./package.json": "./package.json"
|
|
13
|
+
},
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "npx wdio run ./wdio.conf.js",
|
|
17
|
+
"link": "sf link ./ -f",
|
|
18
|
+
"patch": "npm run test && sf publish patch -r"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"lib"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"monocart-coverage-reports": "^2.5.7"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@babel/core": "^7.23.9",
|
|
29
|
+
"@babel/preset-env": "^7.23.9",
|
|
30
|
+
"@babel/register": "^7.23.7",
|
|
31
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
32
|
+
"@wdio/browser-runner": "^8.32.3",
|
|
33
|
+
"@wdio/cli": "^8.32.3",
|
|
34
|
+
"@wdio/mocha-framework": "^8.32.3",
|
|
35
|
+
"@wdio/spec-reporter": "^8.32.2",
|
|
36
|
+
"eslint": "^8.57.0",
|
|
37
|
+
"eslint-config-plus": "^1.0.6",
|
|
38
|
+
"eslint-plugin-html": "^8.0.0",
|
|
39
|
+
"eslint-plugin-react": "^7.33.2",
|
|
40
|
+
"eslint-plugin-wdio": "^8.24.12",
|
|
41
|
+
"react": "^18.2.0",
|
|
42
|
+
"react-dom": "^18.2.0"
|
|
43
|
+
}
|
|
44
|
+
}
|