Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@diffblue/java-combiner

Package Overview
Dependencies
Maintainers
5
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@diffblue/java-combiner - npm Package Compare versions

Comparing version 0.1.6-rc3 to 0.1.6

5

build/testCombiner.d.ts

@@ -19,3 +19,3 @@ import { ILooseTestData, ITestData } from './test';

* @param {string} b
* @returns
* @returns {number}
*/

@@ -31,5 +31,6 @@ export declare function cmpLines(a: ITestData, b: ITestData): 0 | 1 | -1;

* @param {string} packageName The desired package name of the class
* @param {boolean} sort Determine whether tests will be sorted by source file location
* @param {string} [legacyPackageName] Override pacakagename if supplied. Deprecated. For backwards compatibility only.
* @returns {ClangStyle}
*/
export declare function genTestClass(tests: ILooseTestData[], className: string, packageName: string, legacyPackageName?: string): string;
export declare function genTestClass(tests: ILooseTestData[], className: string, packageName: string, legacyPackageName?: string, sort?: boolean): string;

65

build/testCombiner.js

@@ -74,21 +74,25 @@ "use strict";

exports.deduplicateTestNames = deduplicateTestNames;
/**
* Given coveredLines output from testgen, return first number of each range
*
* @param {string} line coverage data. Example: 'main.java:22-24,10-20,9',
* @returns {number[]} array of lowest numbers per range
*/
function getLines(line) {
// text processing to get covered lines from coveredLines
const splitString = line.split(':')[1].split(',');
splitString[0] = splitString[0].slice(1);
return splitString.map((s) => {
return Number(s.indexOf('-') ? s.split('-')[0] : s);
});
const coveredLines = line.split(':')[1];
const ranges = coveredLines.split(',');
return ranges.map((range) => Number(range.split('-')[0]));
}
/**
* Given a test, return the first line of its source code file covered
*
* @param {ITestData} test
* @returns {number}
*/
function firstLine(test) {
// first line of source file covered by test
if (!(typeof (test.sourceFilePath) === 'string' && test.coveredLines)) {
return 0;
}
// type hack
const file = test.sourceFilePath = test.sourceFilePath || '';
const file = test.sourceFilePath;
// get lines of source file covered by test
const mainLines = lodash_1.flatMap(test.coveredLines.filter((cl) => cl.indexOf(file) !== -1), getLines);
const mainLines = lodash_1.flatMap(test.coveredLines.filter((coveredLine) => coveredLine.includes(file)), getLines);
// pick the first line
return mainLines.sort((a, b) => a - b)[0];
return Math.min(...mainLines);
}

@@ -102,3 +106,3 @@ /**

* @param {string} b
* @returns
* @returns {number}
*/

@@ -109,20 +113,14 @@ function cmpLines(a, b) {

exports.cmpLines = cmpLines;
/**
* order tests by source file coverage locations
*
* @param {ITestData[]} tests
* @returns {ITestData[]}
*/
function orderTests(tests) {
// group tests by source file covered
const testsBySourceFile = {};
for (const t of tests) {
if (!(t.sourceFilePath && t.coveredLines)) {
return [];
}
if (Object.keys(testsBySourceFile).includes(t.sourceFilePath)) {
testsBySourceFile[t.sourceFilePath].push(t);
}
else {
testsBySourceFile[t.sourceFilePath] = [t];
}
}
const testsBySourceFile = lodash_1.groupBy(tests, 'sourceFilePath');
// sort tests by line covered
Object.keys(testsBySourceFile).forEach((t) => testsBySourceFile[t].sort(cmpLines));
lodash_1.mapValues(testsBySourceFile, (testsForSourceFile) => testsForSourceFile.sort(cmpLines));
// concatenate tests for all source files
return lodash_1.flatMap(Object.keys(testsBySourceFile), (k) => testsBySourceFile[k]);
return lodash_1.flatMap(Object.keys(testsBySourceFile).sort(), (sourceFile) => testsBySourceFile[sourceFile]);
}

@@ -137,6 +135,7 @@ /**

* @param {string} packageName The desired package name of the class
* @param {boolean} sort Determine whether tests will be sorted by source file location
* @param {string} [legacyPackageName] Override pacakagename if supplied. Deprecated. For backwards compatibility only.
* @returns {ClangStyle}
*/
function genTestClass(tests, className, packageName, legacyPackageName) {
function genTestClass(tests, className, packageName, legacyPackageName, sort = true) {
if (legacyPackageName) {

@@ -149,5 +148,5 @@ // Deprecated 3rd parameter (testedClasses) used; overwrite packageName with 4th parameter

const classAnnotations = new Set([].concat(...tests.map((test) => test.classAnnotations)));
// decomplicate this
const standardisedTests = utils_1.standardiseTests(tests);
const orderedTests = standardisedTests[0].coveredLines.length ? orderTests(standardisedTests) : standardisedTests;
// order the tests by locations covered if there's coverage data
const orderedTests = sort && standardisedTests[0].coveredLines.length ? orderTests(standardisedTests) : standardisedTests;
const uniqueTests = orderedTests[0] && orderedTests[0].id ? deduplicateTestNames(orderedTests) : orderedTests;

@@ -154,0 +153,0 @@ const combinedTests = combineTests_1.combineTests({ tests: uniqueTests, existingImports: [] });

@@ -0,1 +1,6 @@

0.1.6 (2019-09-11)
==================
* Add option to sort tests by files and lines covered in genTestClass
0.1.5 (2019-08-12)

@@ -2,0 +7,0 @@ ==================

{
"name": "@diffblue/java-combiner",
"description": "Java test combining library",
"version": "0.1.6-rc3",
"version": "0.1.6",
"main": "build/index.js",

@@ -53,3 +53,2 @@ "types": "build/index.d.ts",

"dependencies": {
"@types/lodash": "4.14.138",
"duplex-child-process": "^1.0.0",

@@ -65,2 +64,3 @@ "lodash": "4.17.15"

"@types/fs-extra": "8.0.0",
"@types/lodash": "4.14.138",
"@types/mocha": "5.2.7",

@@ -67,0 +67,0 @@ "fs-extra": "8.1.0",

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