New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@wdio/json-reporter

Package Overview
Dependencies
Maintainers
0
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wdio/json-reporter - npm Package Compare versions

Comparing version 9.0.0-alpha.426 to 9.0.0

125

build/index.js

@@ -1,47 +0,84 @@

import WDIOReporter from '@wdio/reporter';
import { mapHooks, mapTests } from './utils.js';
export default class JsonReporter extends WDIOReporter {
constructor(options) {
if (options.logFile && options.logFile.endsWith('.log')) {
options.logFile = options.logFile.slice(0, -4) + '.json';
}
super(options);
// src/index.ts
import WDIOReporter from "@wdio/reporter";
// src/utils.ts
function mapHooks(hooks) {
return hooks.map((hook) => ({
start: hook.start,
end: hook.end,
duration: hook.duration,
title: hook.title,
associatedSuite: hook.parent,
associatedTest: hook.currentTest,
state: hook.errors && hook.errors.length && hook.state ? hook.state : "passed",
error: hook.error
}));
}
function mapTests(tests) {
return tests.map((test) => ({
name: test.title,
start: test.start,
end: test.end,
duration: test.duration,
state: test.state,
error: test.error
}));
}
// src/index.ts
var JsonReporter = class extends WDIOReporter {
constructor(options) {
if (options.logFile && options.logFile.endsWith(".log")) {
options.logFile = options.logFile.slice(0, -4) + ".json";
}
onRunnerEnd(runner) {
const json = this.#prepareJson(runner);
this.write(JSON.stringify(json));
}
#prepareJson(runner) {
const resultSet = {
start: runner.start,
end: runner.end,
capabilities: runner.capabilities,
framework: runner.config.framework,
mochaOpts: runner.config.mochaOpts,
suites: [],
specs: [],
state: { passed: 0, failed: 0, skipped: 0 },
super(options);
}
onRunnerEnd(runner) {
const json = this.#prepareJson(runner);
this.write(JSON.stringify(json));
}
#prepareJson(runner) {
const resultSet = {
start: runner.start,
end: runner.end,
capabilities: runner.capabilities,
framework: runner.config.framework,
mochaOpts: runner.config.mochaOpts,
suites: [],
specs: [],
state: { passed: 0, failed: 0, skipped: 0 }
};
for (const spec of runner.specs) {
resultSet.specs.push(spec);
for (const suiteKey of Object.keys(this.suites)) {
const suite = this.suites[suiteKey];
const testSuite = {
name: suite.title,
duration: suite._duration,
start: suite.start,
end: suite.end,
sessionId: runner.sessionId,
tests: mapTests(suite.tests),
hooks: mapHooks(suite.hooks)
};
for (const spec of runner.specs) {
resultSet.specs.push(spec);
for (const suiteKey of Object.keys(this.suites)) {
const suite = this.suites[suiteKey];
const testSuite = {
name: suite.title,
duration: suite._duration,
start: suite.start,
end: suite.end,
sessionId: runner.sessionId,
tests: mapTests(suite.tests),
hooks: mapHooks(suite.hooks)
};
resultSet.state.failed += testSuite.hooks.filter((hook) => hook.error).length;
resultSet.state.passed += testSuite.tests.filter((test) => test.state === 'passed').length;
resultSet.state.failed += testSuite.tests.filter((test) => test.state === 'failed').length;
resultSet.state.skipped += testSuite.tests.filter((test) => test.state === 'skipped').length;
resultSet.suites.push(testSuite);
}
}
return resultSet;
resultSet.state.failed += testSuite.hooks.filter(
(hook) => hook.error
).length;
resultSet.state.passed += testSuite.tests.filter(
(test) => test.state === "passed"
).length;
resultSet.state.failed += testSuite.tests.filter(
(test) => test.state === "failed"
).length;
resultSet.state.skipped += testSuite.tests.filter(
(test) => test.state === "skipped"
).length;
resultSet.suites.push(testSuite);
}
}
}
return resultSet;
}
};
export {
JsonReporter as default
};

@@ -1,46 +0,50 @@

import fs from 'node:fs/promises';
import path from 'node:path';
const DEFAULT_FILENAME = 'wdio-merged.json';
export default async function mergeResults(dir = process.argv[2], filePattern = process.argv[3], customFileName = process.argv[4]) {
const doesDirExist = fs.access(dir).then(() => true, () => false);
if (!doesDirExist) {
throw new Error(`Directory "${dir}" does not exist.`);
}
const rawData = await getDataFromFiles(dir, filePattern);
const mergedResults = mergeData(rawData);
if (customFileName) {
const fileName = customFileName || DEFAULT_FILENAME;
const filePath = path.join(dir, fileName);
await fs.writeFile(filePath, JSON.stringify(mergedResults));
}
return mergedResults;
// src/mergeResults.ts
import fs from "node:fs/promises";
import path from "node:path";
var DEFAULT_FILENAME = "wdio-merged.json";
async function mergeResults(dir = process.argv[2], filePattern = process.argv[3], customFileName = process.argv[4]) {
const doesDirExist = fs.access(dir).then(() => true, () => false);
if (!doesDirExist) {
throw new Error(`Directory "${dir}" does not exist.`);
}
const rawData = await getDataFromFiles(dir, filePattern);
const mergedResults = mergeData(rawData);
if (customFileName) {
const fileName = customFileName || DEFAULT_FILENAME;
const filePath = path.join(dir, fileName);
await fs.writeFile(filePath, JSON.stringify(mergedResults));
}
return mergedResults;
}
async function getDataFromFiles(dir, filePattern) {
const fileNames = (await fs.readdir(dir)).filter((file) => file.match(filePattern));
const data = [];
await Promise.all(fileNames.map(async (fileName) => {
data.push(JSON.parse((await fs.readFile(`${dir}/${fileName}`)).toString()));
}));
return data;
const fileNames = (await fs.readdir(dir)).filter((file) => file.match(filePattern));
const data = [];
await Promise.all(fileNames.map(async (fileName) => {
data.push(JSON.parse((await fs.readFile(`${dir}/${fileName}`)).toString()));
}));
return data;
}
function mergeData(rawData) {
if (rawData.length === 0) {
return {};
}
const mergedResults = {
...rawData[0],
capabilities: [rawData[0].capabilities]
};
for (const data of rawData.slice(1)) {
mergedResults.suites.push(...data.suites);
mergedResults.specs.push(...data.specs);
mergedResults.state.passed += data.state.passed;
mergedResults.state.failed += data.state.failed;
mergedResults.state.skipped += data.state.skipped;
mergedResults.capabilities.push(data.capabilities);
}
mergedResults.suites.forEach((suite) => {
mergedResults.end = (suite.end && mergedResults.end && suite.end > mergedResults.end ? suite.end : mergedResults.end);
});
return mergedResults;
if (rawData.length === 0) {
return {};
}
const mergedResults = {
...rawData[0],
capabilities: [rawData[0].capabilities]
};
for (const data of rawData.slice(1)) {
mergedResults.suites.push(...data.suites);
mergedResults.specs.push(...data.specs);
mergedResults.state.passed += data.state.passed;
mergedResults.state.failed += data.state.failed;
mergedResults.state.skipped += data.state.skipped;
mergedResults.capabilities.push(data.capabilities);
}
mergedResults.suites.forEach((suite) => {
mergedResults.end = suite.end && mergedResults.end && suite.end > mergedResults.end ? suite.end : mergedResults.end;
});
return mergedResults;
}
export {
mergeResults as default
};
{
"name": "@wdio/json-reporter",
"version": "9.0.0-alpha.426+d760644c4",
"version": "9.0.0",
"description": "A WebdriverIO plugin to report results in json format.",

@@ -28,8 +28,10 @@ "author": "Christian Bromann <mail@bromann.dev>",

"./mergeResults": {
"types": "./build/mergeResults.d.ts",
"source": "./src/mergeResults.ts",
"import": "./build/mergeResults.js",
"require": "./build/mergeResults.cjs"
},
".": "./build/index.js",
"./package.json": "./package.json"
".": {
"import": "./build/index.js",
"types": "./build/index.d.ts"
}
},

@@ -39,4 +41,4 @@ "types": "./build/index.d.ts",

"dependencies": {
"@wdio/reporter": "9.0.0-alpha.426+d760644c4",
"@wdio/types": "9.0.0-alpha.426+d760644c4"
"@wdio/reporter": "9.0.0",
"@wdio/types": "9.0.0"
},

@@ -46,3 +48,3 @@ "publishConfig": {

},
"gitHead": "d760644c4c6e1ef910c0bee120cb422e25dbbe06"
"gitHead": "957693463371a4cb329395dcdbce8fb0c930ab93"
}

Sorry, the diff of this file is not supported yet

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