Skip to content

Commit

Permalink
Add strcalc/src/main/frontend
Browse files Browse the repository at this point in the history
This adds a JavaScript project built using Node.js, the pnpm package
manager, and the Vite development and packaging environment, and
node-gradle/gradle-node-plugin:

- https://nodejs.org/
- https://pnpm.io/
- https://vitejs.dev/
- https://github.com/node-gradle/gradle-node-plugin

The `./gradlew pnpm_build` task emits the compiled HTML and JavaScript
into `strcalc/build/webapp`. Reconfigured the Gradle War plugin's `war`
task to add files from this directory into
`strcalc/build/libs/strcalc.war`.

I need to finish documenting this (added a TODO in README.md) and to add
tests specifically for the JavaScript code. However, the entire project
is building and testing successfully with this new infrastructure.
  • Loading branch information
mbland committed Nov 9, 2023
1 parent 723b4c4 commit 9ee83ae
Show file tree
Hide file tree
Showing 14 changed files with 523 additions and 13 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,24 @@ jobs:
java-version: 21
check-latest: true

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
cache-dependency-path: 'strcalc/src/main/frontend/pnpm-lock.yaml'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Install Node packages
run: ./gradlew pnpmInstall

- name: Build and test
run: ./gradlew build

Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ tmp

# IDEA coverage report dir
htmlReport

# The strcalc/main/frontend project will write files to strcalc/src/main/webapp
# for the War plugin to package into strcalc/build/libs/strcalc.war.
strcalc/src/main/webapp

node_modules
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,16 @@ plugin:

Coming soon...

TODO(mbland): Document how the following are configured:

- [Gradle WAR Plugin][] - now writes to/includes files from `strcalc/build/webapp`
- [Selenium WebDriver][]
- [TestTomcat](./strcalc/src/test/java/com/mike_bland/training/testing/utils/TestTomcat.java)
(for medium tests)
- [Vite JavaScript development environment][]
- [pnpm Node.js package manager][]
- [node-gradle/gradle-node-plugin][]

## Implementing core logic using Test Driven Development and unit tests

Coming soon...
Expand Down Expand Up @@ -678,3 +688,6 @@ Coming soon...
[coverallsapp/github-action GitHub Actions plugin]: https://github.com/coverallsapp/github-action
[GitHub Actions marketplace]: https://github.com/marketplace?type=actions
[JaCoCo related GitHub Actions plugins]: https://github.com/marketplace?category=&type=actions&verification=&query=jacoco
[Vite JavaScript development environment]: https://vitejs.dev/
[pnpm Node.js package manager]: https://pnpm.io/
[node-gradle/gradle-node-plugin]: https://github.com/node-gradle/gradle-node-plugin
13 changes: 13 additions & 0 deletions strcalc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
plugins {
war
jacoco
id("com.github.node-gradle.node") version "7.0.1"
}

repositories {
Expand Down Expand Up @@ -43,6 +44,10 @@ jacoco {
toolVersion = "0.8.11"
}

node {
nodeProjectDir = file("src/main/frontend")
}

// The small/medium/large test schema is implemented via JUnit5 composite tags
// and custom Test tasks. See:
//
Expand All @@ -67,8 +72,14 @@ val smallTests = tasks.named<Test>("test") {
setCommonTestOptions(this)
}
val testClasses = tasks.named("testClasses")
val pnpmBuild = tasks.named("pnpm_build")
val war = tasks.named("war")

tasks.war {
dependsOn(pnpmBuild)
from(project.layout.buildDirectory.dir("webapp").get())
}

val setLargerTestOptions = { testTask: Test ->
testTask.group = "verification"
testTask.dependsOn(testClasses)
Expand All @@ -93,13 +104,15 @@ val mediumCoverageTests = tasks.register<Test>("test-medium-coverage") {
description = "Runs medium integration tests annotated with " +
"@MediumCoverageTest."
setLargerTestOptions(this)
dependsOn(pnpmBuild)
useJUnitPlatform { includeTags("medium & coverage") }
shouldRunAfter(smallTests)
}

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)
extensions.configure(JacocoTaskExtension::class) {
Expand Down
24 changes: 24 additions & 0 deletions strcalc/src/main/frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
11 changes: 11 additions & 0 deletions strcalc/src/main/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>String Calculator - Mike Bland Training</title>
</head>
<body>
<div id="app"></div><script type="module" src="/main.js"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions strcalc/src/main/frontend/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import './style.css'

document.querySelector('#app').innerHTML = `
<p class="placeholder">Hello, World!</p>
`
14 changes: 14 additions & 0 deletions strcalc/src/main/frontend/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"devDependencies": {
"vite": "^4.4.5"
}
}
Loading

0 comments on commit 9ee83ae

Please sign in to comment.