Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
020adc7
[WIP] Better imports manager for JS + removed thisInstance builder
zishkaz Feb 4, 2023
bd1d38c
Implemented AST scrapper for better imports handling
zishkaz Feb 11, 2023
b89bdcd
Fixed wrong argument sequence in function call
zishkaz Feb 12, 2023
f6cde43
Implemented require import manager for JavaScript
zishkaz Feb 13, 2023
032de9c
Implemented package.json parser
zishkaz Feb 13, 2023
5b07b01
[WIP] Redesigned exports managers + better file division in utbot-js …
zishkaz Feb 13, 2023
7cc2b5d
Implemented JavaScript exports manager based on package.json
zishkaz Feb 13, 2023
1614f4c
Fix phantom !0 in tern
rudolf101 Feb 14, 2023
2086b7a
Switch to IU for this branch
zishkaz Jan 13, 2023
079af6a
After VCS fix
zishkaz Feb 17, 2023
f384001
Merge branch 'main' into sergeyl/js-update
rudolf101 Feb 17, 2023
32f0fed
Fix after merge
rudolf101 Feb 17, 2023
49034ad
Fix text annotation for generated tests
rudolf101 Feb 17, 2023
e8c0140
Implement support for multiple files for tern
rudolf101 Feb 17, 2023
02f3dac
[WIP] Module imports for JavaScript
zishkaz Feb 18, 2023
bd8d919
Implemented import/export providers (except generated test files)
zishkaz Feb 18, 2023
178534e
[WIP] JavaScript test generation for multi-file projects
zishkaz Feb 18, 2023
bae6e13
Added array support for JavaScript test generation
zishkaz Feb 19, 2023
6e01ae8
[WIP] Map data structure support for JavaScript
zishkaz Feb 21, 2023
9a398f0
[WIP] JavaScript NPM packages installation enhancement
zishkaz Feb 21, 2023
2a76020
Enhanced package installation for JavaScript
zishkaz Feb 27, 2023
f834e52
Fixed id error for UtAssembleModel in JavaScript
zishkaz Feb 27, 2023
d62cfc9
Enhanced Map datastructure fuzzing for JavaScript
zishkaz Mar 2, 2023
83527be
Add JSON file consistency check
rudolf101 Mar 3, 2023
5de67a7
Add message about time expiration for npm packages installation
rudolf101 Mar 3, 2023
db15ad2
JavaScript test generation for Set data structure implemented
zishkaz Mar 3, 2023
d90e12c
[WIP] Better imports manager for JS + removed thisInstance builder
zishkaz Feb 4, 2023
6c64136
Implemented AST scrapper for better imports handling
zishkaz Feb 11, 2023
bd413e1
Fixed wrong argument sequence in function call
zishkaz Feb 12, 2023
b0ced75
Implemented require import manager for JavaScript
zishkaz Feb 13, 2023
6534255
Implemented package.json parser
zishkaz Feb 13, 2023
a342a22
[WIP] Redesigned exports managers + better file division in utbot-js …
zishkaz Feb 13, 2023
7d9a6f6
Implemented JavaScript exports manager based on package.json
zishkaz Feb 13, 2023
b58c9ee
Fix phantom !0 in tern
rudolf101 Feb 14, 2023
a08aaa6
Switch to IU for this branch
zishkaz Jan 13, 2023
203a199
After VCS fix
zishkaz Feb 17, 2023
db20b04
Fix after merge
rudolf101 Feb 17, 2023
c9ca0f7
Fix text annotation for generated tests
rudolf101 Feb 17, 2023
321e864
Implement support for multiple files for tern
rudolf101 Feb 17, 2023
5d0c761
[WIP] Module imports for JavaScript
zishkaz Feb 18, 2023
a2950f2
Implemented import/export providers (except generated test files)
zishkaz Feb 18, 2023
33d3ef9
[WIP] JavaScript test generation for multi-file projects
zishkaz Feb 18, 2023
9298cbf
Added array support for JavaScript test generation
zishkaz Feb 19, 2023
dce90a4
[WIP] Map data structure support for JavaScript
zishkaz Feb 21, 2023
2dcc1e4
[WIP] JavaScript NPM packages installation enhancement
zishkaz Feb 21, 2023
0008d19
Enhanced package installation for JavaScript
zishkaz Feb 27, 2023
64b572a
Fixed id error for UtAssembleModel in JavaScript
zishkaz Feb 27, 2023
b9ba32e
Enhanced Map datastructure fuzzing for JavaScript
zishkaz Mar 2, 2023
c750637
Add JSON file consistency check
rudolf101 Mar 3, 2023
7eb3ee8
Add message about time expiration for npm packages installation
rudolf101 Mar 3, 2023
f02dfff
JavaScript test generation for Set data structure implemented
zishkaz Mar 3, 2023
4fb92f2
Removed extra dep
zishkaz Mar 3, 2023
636a406
[WIP] removing "fuzzers" dep form JavaScript
zishkaz Mar 3, 2023
e7ed1b2
Merge remote-tracking branch 'origin/sergeyl/js-update' into sergeyl/…
zishkaz Mar 3, 2023
398d9d4
[WIP] No "fuzzers" dep in JavaScript (except UtFuzzedExecution)
zishkaz Mar 3, 2023
6a1c884
Removed all "org.utbot.fuzzer" deps in utbot-js module
zishkaz Mar 6, 2023
1f8a4b5
Fixed test generation action for JavaScript
zishkaz Mar 6, 2023
1ea6965
Fixed temp files generation for multiple params
zishkaz Mar 6, 2023
ab8700a
Merge branch 'main' into sergeyl/js-update
rudolf101 Mar 6, 2023
b846ac1
Merge remote-tracking branch 'origin/sergeyl/js-update' into sergeyl/…
zishkaz Mar 6, 2023
fff737e
Fix imports
rudolf101 Mar 6, 2023
60129b1
Implemented package.json based imports for CjJsRenderer
zishkaz Mar 7, 2023
ea5a3ae
Reworked exports manager + fixed non-indexing test files
rudolf101 Feb 17, 2023
512d622
Rollback fix of non-indexing test files
zishkaz Mar 7, 2023
22f2f27
Fixed non-indexing test files
zishkaz Mar 7, 2023
e457ffe
Merge branch 'main' into sergeyl/js-update
zishkaz Mar 7, 2023
5f56fee
After merge fix
zishkaz Mar 7, 2023
b9418e2
Added new samples to utbot-js
zishkaz Mar 7, 2023
2bea5eb
Minor refactoring
zishkaz Mar 7, 2023
56d1518
Change ideType to IC
rudolf101 Mar 7, 2023
2823330
Merge branch 'main' into sergeyl/js-update
zishkaz Mar 7, 2023
8b769e0
Fix gradle.properties code style
rudolf101 Mar 7, 2023
ed08428
Add newline at end of file
rudolf101 Mar 7, 2023
3dc1e51
Merge branch 'main' into sergeyl/js-update
rudolf101 Mar 9, 2023
831159b
After merge fix
rudolf101 Mar 9, 2023
5f5d593
Attempt to fix active memory usage
zishkaz Mar 9, 2023
2535a2e
Fixed base coverage analysis
zishkaz Mar 10, 2023
77635ca
Refactor some tern regexps
rudolf101 Mar 10, 2023
63808a6
Merge remote-tracking branch 'origin/sergeyl/js-update' into sergeyl/…
rudolf101 Mar 10, 2023
8f33177
Refactored SetValueProvider and MapValueProvider
zishkaz Mar 10, 2023
8126aa7
Merge remote-tracking branch 'origin/sergeyl/js-update' into sergeyl/…
zishkaz Mar 10, 2023
e2c4894
Fixed exports management for corrupted utbot exports section
zishkaz Mar 10, 2023
4f44211
Hotfix
zishkaz Mar 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.github.ajalt.clikt.parameters.options.*
import com.github.ajalt.clikt.parameters.types.choice
import mu.KotlinLogging
import org.utbot.cli.js.JsUtils.makeAbsolutePath
import service.CoverageMode
import service.coverage.CoverageMode
import settings.JsDynamicSettings
import settings.JsExportsSettings.endComment
import settings.JsExportsSettings.startComment
Expand Down Expand Up @@ -82,6 +82,7 @@ class JsGenerateTestsCommand :
val sourceFileAbsolutePath = makeAbsolutePath(sourceCodeFile)
logger.info { "Generating tests for [$sourceFileAbsolutePath] - started" }
val fileText = File(sourceCodeFile).readText()
currentFileText = fileText
val outputAbsolutePath = output?.let { makeAbsolutePath(it) }
val testGenerator = JsTestGenerator(
fileText = fileText,
Expand Down Expand Up @@ -118,36 +119,31 @@ class JsGenerateTestsCommand :
}
}

private fun manageExports(exports: List<String>) {
val exportSection = exports.joinToString("\n") { "exports.$it = $it" }
// Needed for continuous exports managing
private var currentFileText = ""

private fun manageExports(swappedText: (String?, String) -> String) {
val file = File(sourceCodeFile)
val fileText = file.readText()
when {
fileText.contains(exportSection) -> {}

fileText.contains(startComment) && !fileText.contains(exportSection) -> {
currentFileText.contains(startComment) -> {
val regex = Regex("$startComment((\\r\\n|\\n|\\r|.)*)$endComment")
regex.find(fileText)?.groups?.get(1)?.value?.let { existingSection ->
val exportRegex = Regex("exports[.](.*) =")
val existingExports = existingSection.split("\n").filter { it.contains(exportRegex) }
val existingExportsSet = existingExports.map { rawLine ->
exportRegex.find(rawLine)?.groups?.get(1)?.value ?: throw IllegalStateException()
}.toSet()
val resultSet = existingExportsSet + exports.toSet()
val resSection = resultSet.joinToString("\n") { "exports.$it = $it" }
val swappedText = fileText.replace(existingSection, "\n$resSection\n")
file.writeText(swappedText)
regex.find(currentFileText)?.groups?.get(1)?.value?.let { existingSection ->
val newText = swappedText(existingSection, currentFileText)
file.writeText(newText)
currentFileText = newText
}
}

else -> {
val line = buildString {
append("\n$startComment\n")
append(exportSection)
append("\n$endComment")
append("\n$startComment")
append(swappedText(null, currentFileText))
append(endComment)
}
file.appendText(line)
currentFileText = file.readText()
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.utbot.intellij.plugin.language.js

import service.CoverageMode
import javax.swing.ButtonGroup
import javax.swing.JRadioButton
import service.coverage.CoverageMode

object CoverageModeButtons {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ object JsDialogProcessor {

private fun createDialog(jsTestsModel: JsTestsModel?) = jsTestsModel?.let { JsDialogWindow(it) }

private fun unblockDocument(project: Project, document: Document) {
PsiDocumentManager.getInstance(project).apply {
commitDocument(document)
doPostponedOperationsAndUnblockDocument(document)
}
}

private fun createTests(model: JsTestsModel, containingFilePath: String, editor: Editor?, contents: String) {
val normalizedContainingFilePath = containingFilePath.replace(File.separator, "/")
(object : Task.Backgroundable(model.project, "Generate tests") {
Expand All @@ -154,7 +161,9 @@ object JsDialogProcessor {
model.testSourceRoot!!
)
val testFileName = normalizedContainingFilePath.substringAfterLast("/").replace(Regex(".js"), "Test.js")
val testGenerator = JsTestGenerator(fileText = contents,
currentFileText = model.file.getContent()
val testGenerator = JsTestGenerator(
fileText = contents,
sourceFilePath = normalizedContainingFilePath,
projectPath = model.project.basePath?.replace(File.separator, "/")
?: throw IllegalStateException("Can't access project path."),
Expand Down Expand Up @@ -208,44 +217,6 @@ object JsDialogProcessor {

private fun JSFile.getContent(): String = this.viewProvider.contents.toString()

private fun manageExports(
editor: Editor?, project: Project, model: JsTestsModel, exports: List<String>
) {
AppExecutorUtil.getAppExecutorService().submit {
invokeLater {
val exportSection = exports.joinToString("\n") { "exports.$it = $it" }
val fileText = model.file.getContent()
when {
fileText.contains(exportSection) -> {}

fileText.contains(startComment) && !fileText.contains(exportSection) -> {
val regex = Regex("$startComment((\\r\\n|\\n|\\r|.)*)$endComment")
regex.find(fileText)?.groups?.get(1)?.value?.let { existingSection ->
val exportRegex = Regex("exports[.](.*) =")
val existingExports = existingSection.split("\n").filter { it.contains(exportRegex) }
val existingExportsSet = existingExports.map { rawLine ->
exportRegex.find(rawLine)?.groups?.get(1)?.value ?: throw IllegalStateException()
}.toSet()
val resultSet = existingExportsSet + exports.toSet()
val resSection = resultSet.joinToString("\n") { "exports.$it = $it" }
val swappedText = fileText.replace(existingSection, "\n$resSection\n")
project.setNewText(editor, model.containingFilePath, swappedText)
}
}

else -> {
val line = buildString {
append("\n$startComment\n")
append(exportSection)
append("\n$endComment")
}
project.setNewText(editor, model.containingFilePath, fileText + line)
}
}
}
}
}

private fun Project.setNewText(editor: Editor?, filePath: String, text: String) {
editor?.let {
runWriteAction {
Expand All @@ -261,12 +232,38 @@ object JsDialogProcessor {
} ?: run {
File(filePath).writeText(text)
}
currentFileText = text
}

private fun unblockDocument(project: Project, document: Document) {
PsiDocumentManager.getInstance(project).apply {
commitDocument(document)
doPostponedOperationsAndUnblockDocument(document)
// Needed for continuous exports managing
private var currentFileText = ""

private fun manageExports(
editor: Editor?,
project: Project,
model: JsTestsModel,
swappedText: (String?, String) -> String
) {
AppExecutorUtil.getAppExecutorService().submit {
invokeLater {
when {
currentFileText.contains(startComment) -> {
val regex = Regex("$startComment((\\r\\n|\\n|\\r|.)*)$endComment")
regex.find(currentFileText)?.groups?.get(1)?.value?.let { existingSection ->
val newText = swappedText(existingSection, currentFileText)
project.setNewText(editor, model.containingFilePath, newText)
}
}

else -> {
val line = buildString {
append("\n")
appendLine(swappedText(null, currentFileText))
}
project.setNewText(editor, model.containingFilePath, currentFileText + line)
}
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project
import org.utbot.framework.codegen.domain.TestFramework
import org.utbot.intellij.plugin.models.BaseTestsModel
import service.CoverageMode
import service.coverage.CoverageMode
import settings.JsTestGenerationSettings.defaultTimeout

class JsTestsModel(
Expand Down
1 change: 0 additions & 1 deletion utbot-js/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
api(project(":utbot-framework"))
api(project(":utbot-fuzzers"))
// https://mvnrepository.com/artifact/com.google.javascript/closure-compiler
implementation("com.google.javascript:closure-compiler:v20221102")

Expand Down
30 changes: 30 additions & 0 deletions utbot-js/samples/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function simpleArray(arr) {
if (arr[0] === 5) {
return 5
}
return 1
}

simpleArray([0, 2])

class ObjectParameter {

constructor(a) {
this.first = a
}

performAction(value) {
return 2 * value
}
}

function arrayOfObjects(arr) {
if (arr[0].first === 2) {
return 1
}
return 10
}

let arr = []
arr[0] = new ObjectParameter(10)
arrayOfObjects(arr)
11 changes: 11 additions & 0 deletions utbot-js/samples/mapStructure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Maps in JavaScript are untyped, so only maps with basic key/value types are feasible to support
function simpleMap(map, compareValue) {
if (map.get("a") === compareValue) {
return 5
}
return 1
}

const map1 = new Map()
map1.set("b", 3.0)
simpleMap(map1, 5)
12 changes: 12 additions & 0 deletions utbot-js/samples/setStructure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Sets in JavaScript are untyped, so only sets with basic value types are feasible to support
function setTest(set, checkValue) {
if (set.has(checkValue)) {
return 5
}
return 1
}

let s = new Set()
s.add(5)
s.add(6)
setTest(s, 4)
Loading