@diffblue/java-combiner
Advanced tools
Comparing version 0.1.4 to 0.1.5-rc1
@@ -51,2 +51,3 @@ import { ILooseTestData } from './test'; | ||
}): Readonly<{ | ||
classRules: Set<string>; | ||
imports: string[]; | ||
@@ -53,0 +54,0 @@ staticImports: string[]; |
@@ -82,2 +82,3 @@ "use strict"; | ||
const reservedShortNames = new Set(existingImports.map(simpleClassName)); | ||
const classRules = new Set(); | ||
let imports = []; | ||
@@ -87,2 +88,7 @@ let staticImports = []; | ||
for (const test of standardisedTests) { | ||
if (test.classRules) { | ||
test.classRules.forEach((i) => { | ||
classRules.add(i); | ||
}); | ||
} | ||
if (test.imports) { | ||
@@ -102,5 +108,5 @@ imports = [...imports, ...resolveImports(reservedShortNames, test.imports)]; | ||
} | ||
return Object.freeze({ imports: imports, staticImports: staticImports, testMethods: testMethods }); | ||
return Object.freeze({ classRules: classRules, imports: imports, staticImports: staticImports, testMethods: testMethods }); | ||
} | ||
exports.combineTests = combineTests; | ||
//# sourceMappingURL=combineTests.js.map |
@@ -6,2 +6,3 @@ /** Generated test data from test-gen, supporting legacy field names */ | ||
id?: string; | ||
testId?: string; | ||
name?: string; | ||
@@ -13,2 +14,3 @@ testName?: string; | ||
testBody?: string; | ||
classRules?: string[]; | ||
} | ||
@@ -23,2 +25,3 @@ /** Generated test data from test-gen, with strict field names */ | ||
body: string; | ||
classRules?: string[]; | ||
} |
@@ -93,5 +93,7 @@ "use strict"; | ||
const standardisedTests = utils_1.standardiseTests(tests); | ||
// const uniqueTests = standardisedTests[0] && standardisedTests[0].id ? deduplicateTestNames(standardisedTests) : standardisedTests; | ||
const uniqueTests = standardisedTests[0].id ? deduplicateTestNames(standardisedTests) : standardisedTests; | ||
const combinedTests = combineTests_1.combineTests({ tests: uniqueTests, existingImports: [] }); | ||
const testImports = combinedTests.imports; | ||
const classRules = combinedTests.classRules; | ||
let staticImports = combinedTests.staticImports; | ||
@@ -106,9 +108,14 @@ const content = combinedTests.testMethods.join('\n\n').replace(/(\n|^)(.)/g, '$1 $2'); | ||
} | ||
let rule = '@org.junit.Rule'; | ||
if (testImports && testImports.length) { | ||
if (testImports.indexOf('org.junit.Rule') === -1) { | ||
testImports.push('org.junit.Rule'); | ||
} | ||
rule = '@Rule'; | ||
if (classRules.size > 0 && (testImports.indexOf('org.junit.Rule') === -1)) { | ||
testImports.push('org.junit.Rule'); | ||
} | ||
let rulesString = ''; | ||
for (const s of combinedTests.classRules) { | ||
rulesString = rulesString + ' ' + s.replace(/^(@[\w.]+)\s+/, ' $1\n ') + '\n\n'; | ||
} | ||
rulesString = rulesString.slice(0, -2); | ||
rulesString = combineTests_1.shortenClassNames({ imports: testImports, body: rulesString }); | ||
if (rulesString !== '') { | ||
rulesString = '\n' + rulesString + '\n'; | ||
} | ||
if (!staticImports) { | ||
@@ -119,4 +126,3 @@ staticImports = []; | ||
const packageStatement = packageName ? `package ${packageName};` : ''; | ||
const alwaysImports = ['org.junit.rules.Timeout']; | ||
const imports = testImports && testImports.length ? createImportString(testImports.concat(alwaysImports, staticImports.map((i) => `static ${i}`))) : LEGACY_IMPORTS; | ||
const imports = testImports && testImports.length ? createImportString(testImports.concat(staticImports.map((i) => `static ${i}`))) : LEGACY_IMPORTS; | ||
return `${packageStatement} | ||
@@ -126,9 +132,3 @@ | ||
public class ${classNameModified} { | ||
${rule} | ||
public final ExpectedException thrown = ExpectedException.none(); | ||
${rule} | ||
public final Timeout globalTimeout = new Timeout(10000); | ||
${rulesString} | ||
${content} | ||
@@ -135,0 +135,0 @@ } |
@@ -28,6 +28,7 @@ "use strict"; | ||
return tests.map((test) => ({ | ||
id: test.id || undefined, | ||
id: test.id || test.testId || undefined, | ||
body: test.body || test.testBody || test.test || undefinedThrowError('No test body found'), | ||
name: test.name || test.testName || undefinedThrowError('No test name'), | ||
classAnnotations: test.classAnnotations || [], | ||
classRules: test.classRules, | ||
imports: test.imports, | ||
@@ -34,0 +35,0 @@ staticImports: test.staticImports, |
{ | ||
"name": "@diffblue/java-combiner", | ||
"description": "Java test combining library", | ||
"version": "0.1.4", | ||
"version": "0.1.5-rc1", | ||
"main": "build/index.js", | ||
@@ -6,0 +6,0 @@ "types": "build/index.d.ts", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
90716
1490