Skip to content

Commit

Permalink
Integrate frontend tests & reports into gradle/CI
Browse files Browse the repository at this point in the history
Enables the GitHub actions build to successfully execute the frontend
JavaScript tests and publish the test and coverage results.

Had to rename some of the package.json scripts to use '-' instead of
':', e.g., "test:ci" to "test-ci". Gradle interprets colons in command
line task names specially, which meant it was impossible to invoke
"pnpm_test:ci".

Adding the frontend coverage also necessitated adding a second Coveralls
upload GitHub Action, and specifying a `file` for the original action.
The original action uploads a JaCoCo XML file relative to
strcalc/src/main/java. The new action uploads an LCOV file relative to
strcalc/src/main/frontend.
  • Loading branch information
mbland committed Nov 13, 2023
1 parent c7aa7e5 commit 08f984d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,18 @@ jobs:
name: test-results
path: '**/build/test-results/test*/TESTS-TestSuites.xml'

- name: Send test coverage to Coveralls.io
- name: Send Java backend test coverage to Coveralls.io
uses: coverallsapp/github-action@v2
if: always()
with:
# The .xml file only contains paths relative to this one.
base-path: 'strcalc/src/main/java'
file: 'strcalc/build/reports/jacoco/jacocoXmlTestReport/jacocoXmlTestReport.xml'

- name: Send JavaScript frontend test coverage to Coveralls.io
uses: coverallsapp/github-action@v2
if: always()
with:
# The lcov file only contains paths relative to this one.
base-path: 'strcalc/src/main/frontend'
file: 'strcalc/build/reports/frontend/coverage/lcov.info'
14 changes: 10 additions & 4 deletions strcalc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ val smallTests = tasks.named<Test>("test") {
}
val testClasses = tasks.named("testClasses")
val pnpmBuild = tasks.named("pnpm_build")
val pnpmTestCi = tasks.named("pnpm_test-ci")
val war = tasks.named("war")

tasks.war {
Expand Down Expand Up @@ -106,15 +107,15 @@ val mediumCoverageTests = tasks.register<Test>("test-medium-coverage") {
setLargerTestOptions(this)
dependsOn(pnpmBuild)
useJUnitPlatform { includeTags("medium & coverage") }
shouldRunAfter(smallTests)
shouldRunAfter(smallTests, pnpmTestCi)
}

val mediumTests = tasks.register<Test>("test-medium") {
description = "Runs medium integration tests annotated with @MediumTest."
setLargerTestOptions(this)
dependsOn(pnpmBuild)
useJUnitPlatform { includeTags("medium & !coverage") }
shouldRunAfter(smallTests, mediumCoverageTests)
shouldRunAfter(smallTests, mediumCoverageTests, pnpmTestCi)
extensions.configure(JacocoTaskExtension::class) {
isEnabled = false
}
Expand All @@ -125,7 +126,7 @@ val largeTests = tasks.register<Test>("test-large") {
setLargerTestOptions(this)
dependsOn(war)
useJUnitPlatform { includeTags("large") }
shouldRunAfter(mediumCoverageTests, mediumTests)
shouldRunAfter(mediumCoverageTests, mediumTests, pnpmTestCi)
extensions.configure(JacocoTaskExtension::class) {
isEnabled = false
}
Expand All @@ -138,7 +139,7 @@ val allTestSizes = arrayOf(
val allTests = tasks.register<Task>("test-all") {
description = "Runs the small, medium, and large test suites in order."
group = "verification"
dependsOn(allTestSizes)
dependsOn(pnpmTestCi, allTestSizes)
}

internal val testResultsDir = java.testResultsDir
Expand All @@ -154,6 +155,11 @@ val relativeToRootDir = fun(absPath: java.nio.file.Path): java.nio.file.Path {
// - https://docs.gradle.org/current/userguide/ant.html
val mergeTestReports = fun(resultsDir: File) {
val taskName = resultsDir.name

// The `pnpm_test-ci` output is already merged. Trying to merge it again
// results in an empty file, so skip it.
if (taskName == "test-frontend") return

val relResultsDir = relativeToRootDir(resultsDir.toPath())
val reportTaskName = "merged-report-$taskName"

Expand Down
5 changes: 3 additions & 2 deletions strcalc/src/main/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"preview": "vite preview",
"lint": "eslint --color --max-warnings 0 .",
"test": "vitest",
"test:run": "vitest --run",
"test:ui": "vitest --ui",
"test-run": "vitest run",
"test-ui": "vitest --ui --coverage",
"test-ci": "vitest run --coverage --reporter=junit --reporter=default",
"coverage": "vitest run --coverage"
},
"devDependencies": {
Expand Down
10 changes: 9 additions & 1 deletion strcalc/src/main/frontend/vite.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const BUILD_DIR = '../../../build/'
export default {
base: '/strcalc',
build: {
outDir: '../../../build/webapp'
outDir: BUILD_DIR + 'webapp'
},
test: {
outputFile: BUILD_DIR + 'test-results/test-frontend/TESTS-TestSuites.xml',
coverage: {
reporter: ['text', 'html', 'lcov'],
reportsDirectory: BUILD_DIR + 'reports/frontend/coverage'
}
}
}

0 comments on commit 08f984d

Please sign in to comment.