diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index f1a3065..bc68f40 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -39,9 +39,6 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2 - - name: Install Node packages - run: ./gradlew --warning-mode=fail pnpmInstall - - name: Build and test run: ./gradlew --warning-mode=fail build diff --git a/README.md b/README.md index ff727a4..94a8c1a 100644 --- a/README.md +++ b/README.md @@ -47,26 +47,10 @@ application deployment). ### OS Compatibility I run Arm64/aarch64 builds of [Ubuntu Linux][] and [Windows 11 Professional][] -under [Parallels Desktop for Mac][] on Apple Silicon. There's some work to allow -WebDriver to use [Chromium][] or [Firefox][] on Linux, as no aarch64 build of -[Google Chrome][] is available. The [node-gradle/gradle-node-plugin][] breaks on -Windows 11 when it tries to execute `uname`: - -```text -PS C:\Users\msb\src\mbland\tomcat-servlet-testing-example> ./gradlew.bat -Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be -reused, use --status for details - -FAILURE: Build failed with an exception. - -* Where: -Build file 'C:\Users\msb\src\mbland\tomcat-servlet-testing-example\strcalc\build.gradle.kts' line: 8 - -* What went wrong: -An exception occurred applying plugin request [id: 'com.github.node-gradle.node'] -> Failed to apply plugin 'com.github.node-gradle.node'. - > A problem occurred starting process 'command 'uname'' -``` +under [Parallels Desktop for Mac][] on Apple Silicon. `vite.config.js` contains +a workaround to allow WebDriver to use [Chromium][] or [Firefox][] on Linux, as +no aarch64 build of [Google Chrome][] is available. (I hope to contribute +this workaround upstream, at which point I'll remove it from `vite.config.js`.) Also, [it doesn't appear as though nested virtualzation will ever be supported by the aarch 64 Windows 11 on an Apple M1][no-vm-nesting]. This means the @@ -802,7 +786,6 @@ TODO(mbland): Document how the following are configured: - [Selenium: Design patterns and development strategies][] - [TestTomcat](./strcalc/src/test/java/com/mike_bland/training/testing/utils/TestTomcat.java) (for medium tests) -- [node-gradle/gradle-node-plugin][] ## Implementing core logic using Test Driven Development and unit tests @@ -821,7 +804,6 @@ Coming soon... [headless Chrome]: https://developer.chrome.com/blog/headless-chrome/ [test doubles]: https://mike-bland.com/2023/09/06/test-doubles.html [Apache Solr]: https://solr.apache.org/ -[node-gradle/gradle-node-plugin]: https://github.com/node-gradle/gradle-node-plugin [Ubuntu Linux]: https://ubuntu.com/desktop [Windows 11 Professional]: https://kb.parallels.com/125375/ [Parallels Desktop for Mac]: https://www.parallels.com/products/desktop/ diff --git a/settings.gradle.kts b/settings.gradle.kts index 92f2305..f200cf0 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,7 +8,6 @@ plugins { // Apply the foojay-resolver plugin to allow automatic download of JDKs id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0" - id("com.github.node-gradle.node") version "7.0.1" apply false id("io.freefair.lombok") version "8.4" apply false id("com.github.ben-manes.versions") version "0.50.0" apply false } diff --git a/strcalc/build.gradle.kts b/strcalc/build.gradle.kts index eaacf48..b2b97b5 100644 --- a/strcalc/build.gradle.kts +++ b/strcalc/build.gradle.kts @@ -8,7 +8,6 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask plugins { war jacoco - id("com.github.node-gradle.node") id("io.freefair.lombok") id("com.github.ben-manes.versions") } @@ -51,16 +50,8 @@ jacoco { toolVersion = "0.8.11" } -// The frontend sources are under src/main/frontend. The Node plugin generates -// the pnpm_build and pnpm_test-ci task definitions from the "scripts" field of -// package.json. -node { - nodeProjectDir = file("src/main/frontend") -} - -// Set inputs and outputs for the pnpm_build and pnpn_test-ci frontend tasks. -// This enables Gradle to cache the results instead of executing these tasks -// unconditionally on every build. +// Set inputs and outputs for the frontend tasks. This enables Gradle to cache +// the results instead of executing these tasks unconditionally on every build. // // The vite.config.js file in src/main/frontend specifies: // @@ -68,28 +59,43 @@ node { // - The default test results directory, build/test-results/test-frontend // - The coverage directory, build/reports/frontend/coverage // -// The vite.config.ci-browser.js file, used by pnpm_test-ci, also specifies +// The vite.config.ci-browser.js file, used by frontendTest, also specifies // the build/test-results/test-frontend-browser directory. val frontendDir = project.layout.projectDirectory.dir("src/main/frontend") val frontendSources = fileTree(frontendDir) { exclude("node_modules", ".*", "*.md") } val frontendOutputDir = project.layout.buildDirectory.dir("webapp").get() +fun frontendCmd(task: Exec, vararg commands: String) { + task.workingDir(frontendDir) + task.commandLine("pnpm", *commands) +} -val frontendBuild = tasks.named("pnpm_build") { +val frontendInstall = tasks.register("frontendInstall") { + description = "Install src/main/frontend npm packages" + inputs.files(frontendDir.files("package.json", "pnpm-lock.yaml")) + outputs.upToDateWhen { true } + frontendCmd(this, "install") +} + +val frontendBuild = tasks.register("frontendBuild") { description = "Build src/main/frontend JavaScript into build/webapp" - inputs.files(frontendSources) + dependsOn(frontendInstall) + inputs.files(frontendSources.filter { !it.name.endsWith(".test.js") }) outputs.dir(frontendOutputDir) + frontendCmd(this, "build") } -val frontendTest = tasks.named("pnpm_test-ci") { +val frontendTest = tasks.register("frontendTest") { description = "Test frontend JavaScript in src/main/frontend" - dependsOn(frontendBuild) inputs.files(frontendSources) + frontendCmd(this, "test-ci") val resultsDir = java.testResultsDir.get() - outputs.dir(resultsDir.dir("test-frontend")) - outputs.dir(resultsDir.dir("test-frontend-browser")) + outputs.dirs( + resultsDir.dir("test-frontend"), + resultsDir.dir("test-frontend-browser") + ) } // Configure the "war" task generated by the Gradle War plugin to depend upon @@ -219,7 +225,7 @@ val relativeToRootDir = fun(absPath: java.nio.file.Path): java.nio.file.Path { val mergeTestReports = fun(resultsDir: File) { val taskName = resultsDir.name - // The `pnpm_test-ci` output is already merged. Trying to merge it again + // The `frontendTest` output is already merged. Trying to merge it again // results in an empty file, so skip it. if (taskName.startsWith("test-frontend")) return