Skip to content

Commit

Permalink
chore: add ui tests, revert changelog and add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kmruiz committed May 13, 2024
1 parent 6bd2a7c commit 7577506
Show file tree
Hide file tree
Showing 37 changed files with 1,050 additions and 53 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/draft-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,34 @@ jobs:
exit 1
fi
- name: Run All Tests
- name: Run Unit and Integration Tests
run: |
./gradlew "unitTest" ":packages:jetbrains-plugin:test"
- name: Prepare License Key
env:
JB_TEST_KEY: ${{ secrets.JB_TEST_KEY }}
run: |
mkdir -p packages/jetbrains-plugin/build/idea-sandbox/config-uiTest
echo "$JB_TEST_KEY" | base64 -d > packages/jetbrains-plugin/build/idea-sandbox/config-uiTest/idea.key
- name: Start UI Test Environment
run: |
export DISPLAY=:99.0
Xvfb -ac :99 -screen 0 1920x1080x24 &
sleep 10
mkdir -p packages/jetbrains-plugin/build/reports
./gradlew :packages:jetbrains-plugin:runIdeForUiTests > packages/jetbrains-plugin/build/reports/idea.log &
- name: Wait for IDE to start
uses: jtalk/url-health-check-action@v3
with:
url: "http://127.0.0.1:8082"
max-attempts: 15
retry-delay: 30s
- name: Run UI Tests
run: |
export DISPLAY=:99.0
./gradlew --quiet --console=plain :packages:jetbrains-plugin:uiTest
- name: Patch Plugin XML
run: |
./gradlew ":packages:jetbrains-plugin:patchPluginXml"
Expand Down
51 changes: 42 additions & 9 deletions .github/workflows/quality-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ jobs:
report_paths: '**/build/test-results/test/TEST-*.xml'
- name: Generate Coverage Report
run: |
./gradlew --quiet --console=plain "jacocoTestReport"
./gradlew --quiet --console=plain "jacocoTestReport" -x "packages:jetbrains-plugin:uiTest"
- uses: actions/upload-artifact@v4
name: Upload Unit Test Coverage
with:
name: unit-test-coverage
path: "**/build/reports/jacoco/test/jacocoTestReport.xml"
path: "**/jacocoTestReport.xml"

functional-tests:
name: 'Functional & UI Tests'
Expand All @@ -144,12 +144,45 @@ jobs:
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'adopt'
distribution: 'zulu'
java-version: '17'
cache: 'gradle'
- name: Functional Tests
- name: Integration Tests
run: |
./gradlew --quiet --console=plain "clean" ":packages:jetbrains-plugin:cleanTest" ":packages:jetbrains-plugin:test"
- name: Prepare License Key
env:
JB_TEST_KEY: ${{ secrets.JB_TEST_KEY }}
run: |
mkdir -p packages/jetbrains-plugin/build/idea-sandbox/config-uiTest
echo "$JB_TEST_KEY" | base64 -d > packages/jetbrains-plugin/build/idea-sandbox/config-uiTest/idea.key
- name: Start UI Test Environment
run: |
export DISPLAY=:99.0
Xvfb -ac :99 -screen 0 1920x1080x24 &
sleep 10
mkdir -p packages/jetbrains-plugin/build/reports
./gradlew :packages:jetbrains-plugin:runIdeForUiTests > packages/jetbrains-plugin/build/reports/idea.log &
- name: Wait for IDE to start
uses: jtalk/url-health-check-action@v3
with:
url: "http://127.0.0.1:8082"
max-attempts: 15
retry-delay: 30s
- name: Run UI Tests
run: |
export DISPLAY=:99.0
./gradlew --quiet --console=plain :packages:jetbrains-plugin:uiTest
- uses: actions/upload-artifact@v4
name: Upload UI Test Failures
if: success() || failure() # always run even if the previous step fails
with:
name: ui-test-failures
path: |
**/build/reports/**/*.html
**/build/reports/**/*.log
**/build/reports/*/*.png
**/video/**/*.avi
- name: Publish Test Report
uses: mikepenz/action-junit-report@v4
if: success() || failure() # always run even if the previous step fails
Expand All @@ -162,7 +195,7 @@ jobs:
name: Upload Functional Test Coverage
with:
name: functional-test-coverage
path: "**/build/reports/jacoco/test/jacocoTestReport.xml"
path: "**/jacocoTestReport.xml"

test-coverage:
name: 'Test Coverage'
Expand All @@ -184,16 +217,15 @@ jobs:
merge-multiple: true
- uses: madrapps/[email protected]
with:
paths: "**/build/reports/jacoco/test/jacocoTestReport.xml"
paths: "**/jacocoTestReport.xml"
token: ${{ secrets.GITHUB_TOKEN }}
min-coverage-overall: 70
min-coverage-changed-files: 85
min-coverage-changed-files: 70
title: "Coverage Report"
update-comment: true
continue-on-error: true
pass-emoji: ""
fail-emoji: "🚫"
debug-mode: true

fitness-check:
name: "Fitness Check"
Expand All @@ -218,7 +250,8 @@ jobs:
jmh-output-path: build/reports/jmh/results.json
github-token: ${{ secrets.GITHUB_TOKEN }}
fail-on-regression: true
failure-threshold: -5
# the typo is on purpose, it's like this in the plugin
failue-threshold: -5

verify-plugin:
name: "Verify Plugin"
Expand Down
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ replay_pid*
/.gradle
/build
/.idea
/**/build
/**/build

# This file is generated at compile time.
packages/jetbrains-plugin/src/main/resources/build.properties
/**/video
/**/.DS_Store
2 changes: 0 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ MongoDB plugin for IntelliJ IDEA.

### Added

- We are testing the release flow.

### Changed

### Deprecated
Expand Down
49 changes: 49 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,55 @@ with the plugin:
./gradlew :packages:jetbrains-plugin:runIde
```

The plugin will hot-reload any change in the source code if it's built. So running the
following command:

```sh
./gradlew build
```

Will apply the latest changes to the running IDE.

> [!INFO]
> It's important to note that this only works because the plugin is a dynamic plugin.
> If you find out that it consistently fail, we might have break one of the dynamic plugin
> rules so run the `./gradlew :packages:jetbrains-plugin:runPluginVerifier` task to check.
## Running UI Tests

UI tests require a working local environment, so before running them, please revisit the
`Getting Started` section.

Once the environment is set up, run the follow commandline script to run all the UI tests of
the project:

```sh
./gradle/run-ui-test.sh
```

It will take a while, and Remote Robot will take ownership of your mouse once it starts
a running IntelliJ environment, so please take a seat and watch it run.

If a test fails, there will be a video recording in `packages/jetbrains-plugin/video` in AVI format
(you might need VLC Player to view it if you use a Mac) and also a screenshot in `packages/jetbrains-plugin/build/reports`
alongside the hierarchy of the view (the "DOM").

## Running a single UI Test

We can run a single UI test for debugging using Gradle and IntelliJ IDEA. To do so, first we need
to start the plugin with the Remote Robot server, by running the following Gradle task:

```sh
./gradlew :packages:jetbrains-plugin:runIdeForUiTests
```

Once the IDE is started, now we can go to any test in IntelliJ IDEA and press the Play button
to run it. When the button is clicked, it will ask for which Gradle task to use to run the test,
and we will choose `uiTest` instead of `test`.

> [!CAUTION]
> :warning: Using `test` instead of `uiTest` won't run any test, so make sure to use `uiTest`. :warning:
## Managing third-party dependencies

We try to avoid third-party dependencies as much as possible, and only use the MongoDB driver,
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,4 @@


> [!CAUTION]
> :warning: This is a work in progress and not yet released. :warning:


> :warning: This is a work in progress and not yet released. :warning:
11 changes: 9 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension

group = "com.mongodb"
// This should be bumped when releasing a new version using the versionBump task:
Expand Down Expand Up @@ -44,6 +43,7 @@ subprojects {
testImplementation(rootProject.libs.testing.jupiter.vintage.engine)
testImplementation(rootProject.libs.testing.mockito.core)
testImplementation(rootProject.libs.testing.mockito.kotlin)
testImplementation(rootProject.libs.kotlin.coroutines.test)
}

tasks {
Expand Down Expand Up @@ -81,6 +81,10 @@ subprojects {
csv.required = false
html.outputLocation = layout.buildDirectory.dir("reports/jacocoHtml")
}

executionData(
files(withType(Test::class.java)).filter { it.name.endsWith(".exec") && it.exists() }
)
}
}

Expand All @@ -101,6 +105,7 @@ tasks.named<DependencyUpdatesTask>("dependencyUpdates").configure {

tasks {
register("unitTest") {
group = "verification"
dependsOn(
subprojects.filter {
it.project.name != "jetbrains-plugin" &&
Expand Down Expand Up @@ -136,13 +141,15 @@ tasks {
}

register("gitHooks") {
group = "environment"
exec {
rootProject.file(".git/hooks").mkdirs()
commandLine("cp", "./gradle/pre-commit", "./.git/hooks")
}
}

register("getVersion") {
group = "environment"
doLast {
println(rootProject.version)
}
Expand Down
10 changes: 10 additions & 0 deletions gradle/diktat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
enabled: false
- name: GENERIC_VARIABLE_WRONG_DECLARATION
enabled: false
- name: FILE_WILDCARD_IMPORTS
enabled: false
- name: TOO_LONG_FUNCTION
enabled: false
- name: KDOC_NO_EMPTY_TAGS
enabled: false
- name: WRONG_INDENTATION
enabled: false
- name: MAGIC_NUMBER
enabled: false
- name: TOO_MANY_PARAMETERS
enabled: true
configuration:
Expand Down
8 changes: 7 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
# IntelliJ platform dependencies
intellij-min="2023.1.5"
intellij-min="2024.1.1"
intellij-type="IU"
intellij-remoteRobot="0.11.22"
intellij-plugin="1.17.3"
Expand All @@ -25,6 +25,8 @@ okHttp="4.12.0"
retrofit="2.11.0"
jmh="1.37"
segment="3.5.1"
jsoup="1.17.2"
video-recorder="2.0"

[plugins]
intellij={ id="org.jetbrains.intellij", version.ref="intellij-plugin" }
Expand All @@ -41,16 +43,20 @@ mongodb-driver={ group="org.mongodb", name="mongodb-driver-kotlin-coroutine", ve
kotlin-stdlib={ group="org.jetbrains.kotlin", name="kotlin-stdlib", version.ref="kotlin-stdlib" }
kotlin-coroutines-core={ group="org.jetbrains.kotlinx", name="kotlinx-coroutines-core", version.ref="kotlinx-coroutines" }
kotlin-coroutines-swing={ group="org.jetbrains.kotlinx", name="kotlinx-coroutines-swing", version.ref="kotlinx-coroutines" }
kotlin-coroutines-test={ group="org.jetbrains.kotlinx", name="kotlinx-coroutines-test", version.ref="kotlinx-coroutines" }

segment={ group="com.segment.analytics.java", name="analytics", version.ref="segment" }

testing-jupiter-engine={ group="org.junit.jupiter", name="junit-jupiter-engine", version.ref="jupiter" }
testing-jupiter-vintage-engine={ group="org.junit.vintage", name="junit-vintage-engine", version.ref="jupiter" }

testing-jsoup= { group="org.jsoup", name="jsoup", version.ref="jsoup" }
testing-mockito-core={ group="org.mockito", name="mockito-core", version.ref="mockito" }
testing-mockito-kotlin={ group="org.mockito.kotlin", name="mockito-kotlin", version.ref="mockito-kotlin" }
testing-video-recorder={ group="com.automation-remarks", name="video-recorder-junit5", version.ref="video-recorder" }
testing-remoteRobot={ group="com.intellij.remoterobot", name="remote-robot", version.ref="intellij-remoteRobot"}
testing-remoteRobotDeps-remoteFixtures={ group="com.intellij.remoterobot", name="remote-fixtures", version.ref="intellij-remoteRobot"}
testing-remoteRobotDeps-ideLauncher={ group="com.intellij.remoterobot", name="ide-launcher", version.ref="intellij-remoteRobot"}
testing-remoteRobotDeps-okHttp={ group="com.squareup.okhttp3", name="okhttp", version.ref="okHttp" }
testing-intellij-ideImpl={ group="com.jetbrains.intellij.platform", name="ide-impl", version.ref="intellij-testBuild" }
testing-intellij-coreUi={ group="com.jetbrains.intellij.platform", name="core-ui", version.ref="intellij-testBuild" }
Expand Down
23 changes: 23 additions & 0 deletions gradle/run-ui-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

./gradlew --quiet --console=plain :packages:jetbrains-plugin:runIdeForUiTests > idea.log &
IDEA_PID=$!

waitForUrl() {
echo "Testing $1"
timeout -s TERM 90 bash -c \
'while [[ "$(curl -s -o /dev/null -L -w ''%{http_code}'' ${0})" != "200" ]];\
do echo "Waiting for ${0}" && sleep 2;\
done' $1
echo "OK!"
}

waitForUrl "http://localhost:8082"

./gradlew --quiet --console=plain :packages:jetbrains-plugin:cleanTest :packages:jetbrains-plugin:uiTest

RESULT=$?

mv idea.log packages/jetbrains-plugin/build/reports/idea.log
kill $IDEA_PID
exit $RESULT
Loading

0 comments on commit 7577506

Please sign in to comment.