Skip to content

Commit 6a15407

Browse files
author
David Hasani
committed
update test to use auth in CI
1 parent 82c54a7 commit 6a15407

File tree

1 file changed

+66
-100
lines changed

1 file changed

+66
-100
lines changed

ui-tests-starter/tst/software/aws/toolkits/jetbrains/uitests/TransformChatTest.kt

+66-100
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package software.aws.toolkits.jetbrains.uitests
55

66
import com.intellij.driver.sdk.waitForProjectOpen
77
import com.intellij.ide.starter.ci.CIServer
8+
import com.intellij.ide.starter.config.ConfigurationStorage
89
import com.intellij.ide.starter.di.di
910
import com.intellij.ide.starter.driver.engine.runIdeWithDriver
1011
import com.intellij.ide.starter.ide.IdeProductProvider
@@ -13,7 +14,7 @@ import com.intellij.ide.starter.models.TestCase
1314
import com.intellij.ide.starter.project.LocalProjectInfo
1415
import com.intellij.ide.starter.runner.CurrentTestMethod
1516
import com.intellij.ide.starter.runner.Starter
16-
import org.junit.jupiter.api.Assertions.assertEquals
17+
import org.junit.jupiter.api.AfterAll
1718
import org.junit.jupiter.api.Assertions.assertTrue
1819
import org.junit.jupiter.api.BeforeEach
1920
import org.junit.jupiter.api.Test
@@ -22,108 +23,10 @@ import org.kodein.di.bindSingleton
2223
import java.io.File
2324
import java.nio.file.Path
2425
import java.nio.file.Paths
25-
import kotlin.io.path.createParentDirectories
26-
import kotlin.io.path.writeText
2726

2827
class TransformChatTest {
2928

30-
init {
31-
di = DI {
32-
extend(di)
33-
bindSingleton<CIServer>(overrides = true) { TestCIServer }
34-
}
35-
}
36-
37-
private val testResourcesPath = "src/test/tstData"
38-
39-
@BeforeEach
40-
fun setUp() {
41-
// Setup test environment
42-
setupTestEnvironment()
43-
}
44-
private fun setupTestEnvironment() {
45-
// Ensure Puppeteer is installed
46-
val npmInstall = ProcessBuilder()
47-
.command("npm", "install", "puppeteer")
48-
.inheritIO()
49-
.start()
50-
.waitFor()
51-
52-
assertEquals(0, npmInstall, "Failed to install Puppeteer")
53-
54-
}
55-
56-
@Test
57-
fun `can open up IDE`() {
58-
val testCase = TestCase(
59-
IdeProductProvider.IC,
60-
LocalProjectInfo(
61-
Paths.get("tstData", "Hello")
62-
)
63-
).useRelease("2024.3")
64-
65-
66-
Paths.get(System.getProperty("user.home"), ".aws", "sso", "cache", "ee1d2538cb8d358377d7661466c866af747a8a3f.json")
67-
.createParentDirectories()
68-
.writeText(
69-
"""
70-
auth goes here
71-
""".trimIndent()
72-
)
73-
74-
Paths.get(System.getProperty("user.home"), ".aws", "sso", "cache", "d3b447f809607422aac1470dd17fbb32e358cdb3.json")
75-
.writeText(
76-
"""
77-
auth goes here
78-
""".trimIndent()
79-
)
80-
81-
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
82-
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
83-
pluginConfigurator.installPluginFromPath(
84-
Path.of(path)
85-
)
86-
}
87-
88-
copyExistingConfig(Paths.get("tstData", "config"))
89-
updateGeneralSettings()
90-
}.runIdeWithDriver()
91-
.useDriverAndCloseIde {
92-
waitForProjectOpen()
93-
Thread.sleep(20000)
94-
95-
96-
val result = executeScript(scr)
97-
assertTrue(result.contains("Choose a module to transform"))
98-
assertTrue(result.contains("Choose the target code version"))
99-
assertTrue(result.contains("Skip tests form appeared: true"))
100-
assertTrue(result.contains("One or multiple diffs form appeared: true"))
101-
assertTrue(result.contains("couldn't run the Maven clean install command"))
102-
}
103-
}
104-
105-
private fun executeScript(scriptContent: String): String {
106-
val scriptFile = File("$testResourcesPath/temp-script.js")
107-
scriptFile.parentFile.mkdirs()
108-
scriptFile.writeText(scriptContent)
109-
110-
val process = ProcessBuilder()
111-
.command("node", scriptFile.absolutePath)
112-
.redirectErrorStream(true)
113-
.start()
114-
115-
val output = process.inputStream.bufferedReader().use { it.readText() }
116-
val exitCode = process.waitFor()
117-
118-
scriptFile.delete()
119-
120-
assertEquals(0, exitCode, "Script execution failed with output: $output")
121-
return output
122-
}
123-
124-
}
125-
126-
private val scr = """
29+
private val transformHappyPathScript = """
12730
const puppeteer = require('puppeteer');
12831
async function testNavigation() {
12932
const browser = await puppeteer.connect({
@@ -188,3 +91,66 @@ async function testNavigation() {
18891
}
18992
testNavigation().catch(console.error)
19093
""".trimIndent()
94+
95+
init {
96+
di = DI {
97+
extend(di)
98+
bindSingleton<CIServer>(overrides = true) { TestCIServer }
99+
val defaults = ConfigurationStorage.instance().defaults.toMutableMap().apply {
100+
put("LOG_ENVIRONMENT_VARIABLES", (!System.getenv("CI").toBoolean()).toString())
101+
}
102+
103+
bindSingleton<ConfigurationStorage>(overrides = true) {
104+
ConfigurationStorage(this, defaults)
105+
}
106+
}
107+
}
108+
109+
@BeforeEach
110+
fun setUp() {
111+
setupTestEnvironment()
112+
}
113+
114+
@Test
115+
fun `can run a transformation from the chat`() {
116+
val testCase = TestCase(
117+
IdeProductProvider.IC,
118+
LocalProjectInfo(
119+
Paths.get("tstData", "Hello")
120+
)
121+
).useRelease(System.getProperty("org.gradle.project.ideProfileName"))
122+
123+
// inject connection
124+
useExistingConnectionForTest()
125+
126+
Starter.newContext(CurrentTestMethod.hyphenateWithClass(), testCase).apply {
127+
System.getProperty("ui.test.plugins").split(File.pathSeparator).forEach { path ->
128+
pluginConfigurator.installPluginFromPath(
129+
Path.of(path)
130+
)
131+
}
132+
133+
copyExistingConfig(Paths.get("tstData", "configAmazonQTests"))
134+
updateGeneralSettings()
135+
}.runIdeWithDriver()
136+
.useDriverAndCloseIde {
137+
waitForProjectOpen()
138+
// required wait time for the system to be fully ready
139+
Thread.sleep(30000)
140+
val result = executePuppeteerScript(transformHappyPathScript)
141+
assertTrue(result.contains("Choose a module to transform"))
142+
assertTrue(result.contains("Choose the target code version"))
143+
assertTrue(result.contains("Skip tests form appeared: true"))
144+
assertTrue(result.contains("One or multiple diffs form appeared: true"))
145+
assertTrue(result.contains("couldn't run the Maven clean install command"))
146+
}
147+
}
148+
149+
companion object {
150+
@JvmStatic
151+
@AfterAll
152+
fun clearAwsXml() {
153+
clearAwsXmlFile()
154+
}
155+
}
156+
}

0 commit comments

Comments
 (0)