@wdio/json-reporter 9.0.0-alpha.9 → 9.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/build/index.js CHANGED
@@ -1,47 +1,84 @@
1
- import WDIOReporter from '@wdio/reporter';
2
- import { mapHooks, mapTests } from './utils.js';
3
- export default class JsonReporter extends WDIOReporter {
4
- constructor(options) {
5
- if (options.logFile && options.logFile.endsWith('.log')) {
6
- options.logFile = options.logFile.slice(0, -4) + '.json';
7
- }
8
- super(options);
9
- }
10
- onRunnerEnd(runner) {
11
- const json = this.#prepareJson(runner);
12
- this.write(JSON.stringify(json));
1
+ // src/index.ts
2
+ import WDIOReporter from "@wdio/reporter";
3
+
4
+ // src/utils.ts
5
+ function mapHooks(hooks) {
6
+ return hooks.map((hook) => ({
7
+ start: hook.start,
8
+ end: hook.end,
9
+ duration: hook.duration,
10
+ title: hook.title,
11
+ associatedSuite: hook.parent,
12
+ associatedTest: hook.currentTest,
13
+ state: hook.errors && hook.errors.length && hook.state ? hook.state : "passed",
14
+ error: hook.error
15
+ }));
16
+ }
17
+ function mapTests(tests) {
18
+ return tests.map((test) => ({
19
+ name: test.title,
20
+ start: test.start,
21
+ end: test.end,
22
+ duration: test.duration,
23
+ state: test.state,
24
+ error: test.error
25
+ }));
26
+ }
27
+
28
+ // src/index.ts
29
+ var JsonReporter = class extends WDIOReporter {
30
+ constructor(options) {
31
+ if (options.logFile && options.logFile.endsWith(".log")) {
32
+ options.logFile = options.logFile.slice(0, -4) + ".json";
13
33
  }
14
- #prepareJson(runner) {
15
- const resultSet = {
16
- start: runner.start,
17
- end: runner.end,
18
- capabilities: runner.capabilities,
19
- framework: runner.config.framework,
20
- mochaOpts: runner.config.mochaOpts,
21
- suites: [],
22
- specs: [],
23
- state: { passed: 0, failed: 0, skipped: 0 },
34
+ super(options);
35
+ }
36
+ onRunnerEnd(runner) {
37
+ const json = this.#prepareJson(runner);
38
+ this.write(JSON.stringify(json));
39
+ }
40
+ #prepareJson(runner) {
41
+ const resultSet = {
42
+ start: runner.start,
43
+ end: runner.end,
44
+ capabilities: runner.capabilities,
45
+ framework: runner.config.framework,
46
+ mochaOpts: runner.config.mochaOpts,
47
+ suites: [],
48
+ specs: [],
49
+ state: { passed: 0, failed: 0, skipped: 0 }
50
+ };
51
+ for (const spec of runner.specs) {
52
+ resultSet.specs.push(spec);
53
+ for (const suiteKey of Object.keys(this.suites)) {
54
+ const suite = this.suites[suiteKey];
55
+ const testSuite = {
56
+ name: suite.title,
57
+ duration: suite._duration,
58
+ start: suite.start,
59
+ end: suite.end,
60
+ sessionId: runner.sessionId,
61
+ tests: mapTests(suite.tests),
62
+ hooks: mapHooks(suite.hooks)
24
63
  };
25
- for (const spec of runner.specs) {
26
- resultSet.specs.push(spec);
27
- for (const suiteKey of Object.keys(this.suites)) {
28
- const suite = this.suites[suiteKey];
29
- const testSuite = {
30
- name: suite.title,
31
- duration: suite._duration,
32
- start: suite.start,
33
- end: suite.end,
34
- sessionId: runner.sessionId,
35
- tests: mapTests(suite.tests),
36
- hooks: mapHooks(suite.hooks)
37
- };
38
- resultSet.state.failed += testSuite.hooks.filter((hook) => hook.error).length;
39
- resultSet.state.passed += testSuite.tests.filter((test) => test.state === 'passed').length;
40
- resultSet.state.failed += testSuite.tests.filter((test) => test.state === 'failed').length;
41
- resultSet.state.skipped += testSuite.tests.filter((test) => test.state === 'skipped').length;
42
- resultSet.suites.push(testSuite);
43
- }
44
- }
45
- return resultSet;
64
+ resultSet.state.failed += testSuite.hooks.filter(
65
+ (hook) => hook.error
66
+ ).length;
67
+ resultSet.state.passed += testSuite.tests.filter(
68
+ (test) => test.state === "passed"
69
+ ).length;
70
+ resultSet.state.failed += testSuite.tests.filter(
71
+ (test) => test.state === "failed"
72
+ ).length;
73
+ resultSet.state.skipped += testSuite.tests.filter(
74
+ (test) => test.state === "skipped"
75
+ ).length;
76
+ resultSet.suites.push(testSuite);
77
+ }
46
78
  }
47
- }
79
+ return resultSet;
80
+ }
81
+ };
82
+ export {
83
+ JsonReporter as default
84
+ };
@@ -0,0 +1,82 @@
1
+ const __importMetaUrl = require('url').pathToFileURL(__filename).href;
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/mergeResults.ts
32
+ var mergeResults_exports = {};
33
+ __export(mergeResults_exports, {
34
+ default: () => mergeResults
35
+ });
36
+ module.exports = __toCommonJS(mergeResults_exports);
37
+ var import_promises = __toESM(require("node:fs/promises"), 1);
38
+ var import_node_path = __toESM(require("node:path"), 1);
39
+ var DEFAULT_FILENAME = "wdio-merged.json";
40
+ async function mergeResults(dir = process.argv[2], filePattern = process.argv[3], customFileName = process.argv[4]) {
41
+ const doesDirExist = import_promises.default.access(dir).then(() => true, () => false);
42
+ if (!doesDirExist) {
43
+ throw new Error(`Directory "${dir}" does not exist.`);
44
+ }
45
+ const rawData = await getDataFromFiles(dir, filePattern);
46
+ const mergedResults = mergeData(rawData);
47
+ if (customFileName) {
48
+ const fileName = customFileName || DEFAULT_FILENAME;
49
+ const filePath = import_node_path.default.join(dir, fileName);
50
+ await import_promises.default.writeFile(filePath, JSON.stringify(mergedResults));
51
+ }
52
+ return mergedResults;
53
+ }
54
+ async function getDataFromFiles(dir, filePattern) {
55
+ const fileNames = (await import_promises.default.readdir(dir)).filter((file) => file.match(filePattern));
56
+ const data = [];
57
+ await Promise.all(fileNames.map(async (fileName) => {
58
+ data.push(JSON.parse((await import_promises.default.readFile(`${dir}/${fileName}`)).toString()));
59
+ }));
60
+ return data;
61
+ }
62
+ function mergeData(rawData) {
63
+ if (rawData.length === 0) {
64
+ return {};
65
+ }
66
+ const mergedResults = {
67
+ ...rawData[0],
68
+ capabilities: [rawData[0].capabilities]
69
+ };
70
+ for (const data of rawData.slice(1)) {
71
+ mergedResults.suites.push(...data.suites);
72
+ mergedResults.specs.push(...data.specs);
73
+ mergedResults.state.passed += data.state.passed;
74
+ mergedResults.state.failed += data.state.failed;
75
+ mergedResults.state.skipped += data.state.skipped;
76
+ mergedResults.capabilities.push(data.capabilities);
77
+ }
78
+ mergedResults.suites.forEach((suite) => {
79
+ mergedResults.end = suite.end && mergedResults.end && suite.end > mergedResults.end ? suite.end : mergedResults.end;
80
+ });
81
+ return mergedResults;
82
+ }
@@ -1,46 +1,50 @@
1
- import fs from 'node:fs/promises';
2
- import path from 'node:path';
3
- const DEFAULT_FILENAME = 'wdio-merged.json';
4
- export default async function mergeResults(dir = process.argv[2], filePattern = process.argv[3], customFileName = process.argv[4]) {
5
- const doesDirExist = fs.access(dir).then(() => true, () => false);
6
- if (!doesDirExist) {
7
- throw new Error(`Directory "${dir}" does not exist.`);
8
- }
9
- const rawData = await getDataFromFiles(dir, filePattern);
10
- const mergedResults = mergeData(rawData);
11
- if (customFileName) {
12
- const fileName = customFileName || DEFAULT_FILENAME;
13
- const filePath = path.join(dir, fileName);
14
- await fs.writeFile(filePath, JSON.stringify(mergedResults));
15
- }
16
- return mergedResults;
1
+ // src/mergeResults.ts
2
+ import fs from "node:fs/promises";
3
+ import path from "node:path";
4
+ var DEFAULT_FILENAME = "wdio-merged.json";
5
+ async function mergeResults(dir = process.argv[2], filePattern = process.argv[3], customFileName = process.argv[4]) {
6
+ const doesDirExist = fs.access(dir).then(() => true, () => false);
7
+ if (!doesDirExist) {
8
+ throw new Error(`Directory "${dir}" does not exist.`);
9
+ }
10
+ const rawData = await getDataFromFiles(dir, filePattern);
11
+ const mergedResults = mergeData(rawData);
12
+ if (customFileName) {
13
+ const fileName = customFileName || DEFAULT_FILENAME;
14
+ const filePath = path.join(dir, fileName);
15
+ await fs.writeFile(filePath, JSON.stringify(mergedResults));
16
+ }
17
+ return mergedResults;
17
18
  }
18
19
  async function getDataFromFiles(dir, filePattern) {
19
- const fileNames = (await fs.readdir(dir)).filter((file) => file.match(filePattern));
20
- const data = [];
21
- await Promise.all(fileNames.map(async (fileName) => {
22
- data.push(JSON.parse((await fs.readFile(`${dir}/${fileName}`)).toString()));
23
- }));
24
- return data;
20
+ const fileNames = (await fs.readdir(dir)).filter((file) => file.match(filePattern));
21
+ const data = [];
22
+ await Promise.all(fileNames.map(async (fileName) => {
23
+ data.push(JSON.parse((await fs.readFile(`${dir}/${fileName}`)).toString()));
24
+ }));
25
+ return data;
25
26
  }
26
27
  function mergeData(rawData) {
27
- if (rawData.length === 0) {
28
- return {};
29
- }
30
- const mergedResults = {
31
- ...rawData[0],
32
- capabilities: [rawData[0].capabilities]
33
- };
34
- for (const data of rawData.slice(1)) {
35
- mergedResults.suites.push(...data.suites);
36
- mergedResults.specs.push(...data.specs);
37
- mergedResults.state.passed += data.state.passed;
38
- mergedResults.state.failed += data.state.failed;
39
- mergedResults.state.skipped += data.state.skipped;
40
- mergedResults.capabilities.push(data.capabilities);
41
- }
42
- mergedResults.suites.forEach((suite) => {
43
- mergedResults.end = (suite.end && mergedResults.end && suite.end > mergedResults.end ? suite.end : mergedResults.end);
44
- });
45
- return mergedResults;
28
+ if (rawData.length === 0) {
29
+ return {};
30
+ }
31
+ const mergedResults = {
32
+ ...rawData[0],
33
+ capabilities: [rawData[0].capabilities]
34
+ };
35
+ for (const data of rawData.slice(1)) {
36
+ mergedResults.suites.push(...data.suites);
37
+ mergedResults.specs.push(...data.specs);
38
+ mergedResults.state.passed += data.state.passed;
39
+ mergedResults.state.failed += data.state.failed;
40
+ mergedResults.state.skipped += data.state.skipped;
41
+ mergedResults.capabilities.push(data.capabilities);
42
+ }
43
+ mergedResults.suites.forEach((suite) => {
44
+ mergedResults.end = suite.end && mergedResults.end && suite.end > mergedResults.end ? suite.end : mergedResults.end;
45
+ });
46
+ return mergedResults;
46
47
  }
48
+ export {
49
+ mergeResults as default
50
+ };
package/build/types.d.ts CHANGED
@@ -8,7 +8,7 @@ export interface SuiteState {
8
8
  export interface ResultSet {
9
9
  start: Date;
10
10
  end?: Date;
11
- capabilities: Capabilities.RemoteCapability;
11
+ capabilities: Capabilities.ResolvedTestrunnerCapabilities;
12
12
  framework?: string;
13
13
  mochaOpts?: WebdriverIO.MochaOpts;
14
14
  jasmineOpts?: WebdriverIO.JasmineOpts;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,MAAM,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAE/D,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,SAAS;IACtB,KAAK,EAAE,IAAI,CAAA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MAAM,CAAA;IAChB,KAAK,EAAE,IAAI,CAAA;IACX,GAAG,CAAC,EAAE,IAAI,CAAA;IACV,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,KAAK,CAAA;CAChB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdio/json-reporter",
3
- "version": "9.0.0-alpha.9+9220932b7",
3
+ "version": "9.0.0",
4
4
  "description": "A WebdriverIO plugin to report results in json format.",
5
5
  "author": "Christian Bromann <mail@bromann.dev>",
6
6
  "homepage": "https://github.com/webdriverio/webdriverio/tree/main/packages/wdio-json-reporter",
@@ -25,21 +25,23 @@
25
25
  "type": "module",
26
26
  "exports": {
27
27
  "./mergeResults": {
28
- "types": "./build/mergeResults.d.ts",
28
+ "source": "./src/mergeResults.ts",
29
29
  "import": "./build/mergeResults.js",
30
- "require": "./build/cjs/mergeResults.js"
30
+ "require": "./build/mergeResults.cjs"
31
31
  },
32
- ".": "./build/index.js",
33
- "./package.json": "./package.json"
32
+ ".": {
33
+ "import": "./build/index.js",
34
+ "types": "./build/index.d.ts"
35
+ }
34
36
  },
35
37
  "types": "./build/index.d.ts",
36
38
  "typeScriptVersion": "3.8.3",
37
39
  "dependencies": {
38
- "@wdio/reporter": "9.0.0-alpha.9+9220932b7",
39
- "@wdio/types": "9.0.0-alpha.9+9220932b7"
40
+ "@wdio/reporter": "9.0.0",
41
+ "@wdio/types": "9.0.0"
40
42
  },
41
43
  "publishConfig": {
42
44
  "access": "public"
43
45
  },
44
- "gitHead": "9220932b7048d9b5b6c8397dda54842625be7ef2"
46
+ "gitHead": "957693463371a4cb329395dcdbce8fb0c930ab93"
45
47
  }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=mergeResults.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mergeResults.d.ts","sourceRoot":"","sources":["../../src/cjs/mergeResults.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- module.exports = async function (...args) {
4
- const mergeResults = (await import('../mergeResults.js')).default;
5
- return mergeResults(...args);
6
- };
@@ -1,5 +0,0 @@
1
- {
2
- "name": "@wdio/json-reporter-cjs",
3
- "type": "commonjs",
4
- "private": true
5
- }
package/build/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
package/build/utils.js DELETED
@@ -1,22 +0,0 @@
1
- export function mapHooks(hooks) {
2
- return hooks.map((hook) => ({
3
- start: hook.start,
4
- end: hook.end,
5
- duration: hook.duration,
6
- title: hook.title,
7
- associatedSuite: hook.parent,
8
- associatedTest: hook.currentTest,
9
- state: hook.errors && hook.errors.length && hook.state ? hook.state : 'passed',
10
- error: hook.error
11
- }));
12
- }
13
- export function mapTests(tests) {
14
- return tests.map((test) => ({
15
- name: test.title,
16
- start: test.start,
17
- end: test.end,
18
- duration: test.duration,
19
- state: test.state,
20
- error: test.error
21
- }));
22
- }
File without changes