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.2 to 0.1.3

66

build/mergeTests.js

@@ -7,40 +7,5 @@ "use strict";

const parse_1 = require("./parse");
const testCombiner_1 = require("./testCombiner");
const utils_1 = require("./utils");
// tslint:disable:no-magic-numbers
/**
* Given an array of import statements, sort them and return string formatted to
* include in a Java file
*
* @param {string[]} imports Array of classes to import
* @returns {string} String of java code to insert into file
*/
function createImportString(imports) {
const javaImports = [];
const javaStaticImports = [];
const internalImports = [];
const staticImports = [];
imports.forEach((i) => {
if (i.match(/^java./)) {
javaImports.push(`import ${i};`);
}
else if (i.match(/^static/)) {
if (i.match(/^static java./)) {
javaStaticImports.push(`import ${i};`);
}
else {
staticImports.push(`import ${i};`);
}
}
else {
internalImports.push(`import ${i};`);
}
});
javaImports.sort();
javaStaticImports.sort();
internalImports.sort();
staticImports.sort();
const allImports = [staticImports, internalImports, javaStaticImports, javaImports];
return '\n' + allImports.filter((element) => element.length).map((element) => element.join('\n') + '\n').join('\n');
}
/**
* Remove number from function name, separating it from it's base name, e.g.

@@ -68,3 +33,2 @@ *

*/
// tslint:disable-next-line:cyclomatic-complexity
function splitExistingCode(fileContents) {

@@ -235,3 +199,4 @@ /** The code being parsed, split into an array at points where a test or import can be inserted */

const { importsToAdd, staticImportsToAdd } = await insertTests(splitCode, functionLocations, importLocations, standardisedTests, clangStyle);
insertAnnotations(splitCode, standardisedTests, classAnnotationLocations, classLocation);
const allImports = [...importLocations.map((il) => il[0]), ...importsToAdd];
insertAnnotations(splitCode, standardisedTests, classAnnotationLocations, classLocation, allImports);
insertImports(splitCode, pkgLocation, importLocations, importsToAdd, staticImportsToAdd);

@@ -318,14 +283,16 @@ return splitCode.join('');

*/
function insertAnnotations(splitCode, tests, classAnnotationLocations, classLocation) {
/** Set of annotations already on the class */
const existingAnnotations = new Set(classAnnotationLocations.map(([name]) => name));
function insertAnnotations(splitCode, tests, classAnnotationLocations, classLocation, allImports) {
/** Set of annotations already on the class, shortened */
const existingAnnotations = new Set(classAnnotationLocations.map(([name]) => combineTests_1.shortenClassNames({ imports: allImports, body: name })));
// Shorten any shortenable test class annotations
for (const test of tests) {
if (test.classAnnotations) {
for (const newAnnotation of test.classAnnotations) {
if (!existingAnnotations.has(newAnnotation)) {
splitCode.splice(classLocation, 0, `${newAnnotation}\n`);
existingAnnotations.add(newAnnotation);
}
test.classAnnotations.forEach((ca) => {
// Shorten class annotations
const shortenedAnnotation = combineTests_1.shortenClassNames({ imports: allImports, body: ca });
// Add annotations to code if they don't exist already
if (!existingAnnotations.has(shortenedAnnotation)) {
splitCode.splice(classLocation, 0, `${shortenedAnnotation}\n`);
existingAnnotations.add(shortenedAnnotation);
}
}
});
}

@@ -350,4 +317,3 @@ }

if (importsToAdd.length || staticImportsToAdd.length) {
const additionalImportsString = createImportString(importsToAdd.concat(staticImportsToAdd.map((i) => `static ${i}`)))
.replace(/\n+$/, '');
const additionalImportsString = testCombiner_1.createImportString(importsToAdd.concat(staticImportsToAdd.map((i) => `static ${i}`)), true);
splitCode.splice(importInsertLocation, 0, `\n${additionalImportsString}`);

@@ -354,0 +320,0 @@ }

@@ -9,3 +9,2 @@ "use strict";

*/
// tslint:disable:no-magic-numbers
exports.ChunkType = {

@@ -12,0 +11,0 @@ code: 0,

import { ILooseTestData, ITestData } from './test';
/**
* Create an import string
* Given an array of import statements, sort them and return string formatted to
* include in a Java file
*
* @export
* @param {string[]} imports
* @returns {string}
* @param {string[]} imports Array of classes to import
* @returns {string} String of java code to insert into file
*/
export declare function createImportString(imports: string[]): string;
export declare function createImportString(imports: string[], newLines?: boolean): string;
export declare function deduplicateTestNames(tests: ITestData[]): ITestData[];

@@ -11,0 +12,0 @@ /**

@@ -17,9 +17,10 @@ "use strict";

/**
* Create an import string
* Given an array of import statements, sort them and return string formatted to
* include in a Java file
*
* @export
* @param {string[]} imports
* @returns {string}
* @param {string[]} imports Array of classes to import
* @returns {string} String of java code to insert into file
*/
function createImportString(imports) {
function createImportString(imports, newLines) {
const javaImports = [];

@@ -49,2 +50,6 @@ const javaStaticImports = [];

staticImports.sort();
if (newLines) {
const allImports = [staticImports, internalImports, javaStaticImports, javaImports];
return '\n' + allImports.filter((element) => element.length).map((element) => element.join('\n') + '\n').join('\n').replace(/\n+$/, '');
}
return [staticImports, internalImports, javaStaticImports, javaImports]

@@ -51,0 +56,0 @@ .reduce((prev, current) => `${prev}${current.length ? `${current.join('\n')}\n\n` : ''}`, '');

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

0.1.3 (2019-06-19)
==================
* Fix class annotation duplication
0.1.2 (2019-06-17)

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

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

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

"lint": "tslint --project tsconfig.json",
"mutate": "stryker run",
"test": "mocha",

@@ -55,2 +56,7 @@ "test-debug": "mocha --inspect-brk=0.0.0.0:9229"

"devDependencies": {
"@stryker-mutator/core": "2.0.0",
"@stryker-mutator/html-reporter": "2.0.0",
"@stryker-mutator/mocha-framework": "2.0.0",
"@stryker-mutator/mocha-runner": "2.0.0",
"@stryker-mutator/typescript": "2.0.0",
"@types/body-parser": "1.17.0",

@@ -57,0 +63,0 @@ "@types/chai": "4.1.7",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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