Repository: jhipster/jhipster-lite
Pull request #9766 (2024-05-08 07:07:14)

Run frontend tests by default in watch mode
While developing it's much easier and idiomatic to just type `npm test` to get tests running continuously than `npm run test:watch`. The other way to run all tests is `npm run test:coverage`, that will also compute (and check if configured) code coverage.


Patch:
diff --git a/package.json b/package.json
index da936ee7d..171d335de 100644
--- a/package.json
+++ b/package.json
@@ -36,10 +36,10 @@
     "prettier:format": "prettier . --write",
     "preview": "vite preview",
     "start": "npm run dev",
-    "test": "npm run vitest -- run --coverage --",
-    "test:watch": "npm run vitest --",
+    "test": "npm run test:watch",
+    "test:coverage": "vitest run --coverage",
+    "test:watch": "vitest --",
     "tikui:serve": "tikui-core serve",
-    "vitest": "vitest",
     "webapp:serve": "vite"
   },
   "dependencies": {
diff --git a/pom.xml b/pom.xml
index cc3e8fa6c..853456b21 100644
--- a/pom.xml
+++ b/pom.xml
@@ -486,7 +486,7 @@
             </goals>
             <phase>test</phase>
             <configuration>
-              <arguments>run test</arguments>
+              <arguments>run test:coverage</arguments>
               <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
             </configuration>
           </execution>
diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
index 9f56f829d..2bda8d51a 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactory.java
@@ -60,7 +60,9 @@ public class AngularModuleFactory {
         .addScript(scriptKey("start"), scriptCommand("ng serve"))
         .addScript(scriptKey("build"), scriptCommand("ng build --output-path=target/classes/static"))
         .addScript(scriptKey("watch"), scriptCommand("ng build --watch --configuration development"))
-        .addScript(scriptKey("test"), scriptCommand("ng test --coverage"))
+        .addScript(scriptKey("test"), scriptCommand("npm run test:watch"))
+        .addScript(scriptKey("test:coverage"), scriptCommand("ng test --coverage"))
+        .addScript(scriptKey("test:watch"), scriptCommand("ng test --watch"))
         .addScript(scriptKey("lint"), scriptCommand("ng lint"))
         .and()
       .files()
diff --git a/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java b/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java
index 9e09dc3f0..b14061e5f 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactory.java
@@ -56,9 +56,10 @@ public class ReactCoreModulesFactory {
         .addScript(scriptKey("preview"), scriptCommand("vite preview"))
         .addScript(scriptKey("start"), scriptCommand("vite"))
         .addScript(scriptKey("lint"), scriptCommand("eslint --ext .js,.ts,.tsx src/main/webapp/app/**/*"))
-        .addScript(scriptKey("test"), scriptCommand("vitest run --coverage"))
+        .addScript(scriptKey("test"), scriptCommand("npm run test:watch"))
+        .addScript(scriptKey("test:coverage"), scriptCommand("vitest run --coverage"))
         .addScript(scriptKey("test:watch"), scriptCommand("vitest --"))
-        .and()
+      .and()
       .files()
         .batch(SOURCE, to("."))
           .addFile("tsconfig.json")
diff --git a/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactory.java
index 2a329898c..e16d8a449 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactory.java
@@ -65,7 +65,9 @@ public class SvelteModuleFactory {
           scriptCommand("prettier --ignore-path .gitignore --check && eslint --ignore-path .gitignore .")
         )
         .addScript(scriptKey("format"), scriptCommand("prettier --ignore-path .gitignore --write"))
-        .addScript(scriptKey("test"), scriptCommand("vitest run --coverage"))
+        .addScript(scriptKey("test"), scriptCommand("npm run test:watch"))
+        .addScript(scriptKey("test:coverage"), scriptCommand("vitest run --coverage"))
+        .addScript(scriptKey("test:watch"), scriptCommand("vitest --"))
         .and()
       .optionalReplacements()
         .in(path("package.json"))
diff --git a/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java b/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java
index dd63db7c0..79f3febb0 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactory.java
@@ -68,7 +68,8 @@ public class VueModulesFactory {
         .addScript(scriptKey("lint"), scriptCommand("eslint --ext .js,.ts,.vue src"))
         .addScript(scriptKey("preview"), scriptCommand("vite preview"))
         .addScript(scriptKey("start"), scriptCommand("vite"))
-        .addScript(scriptKey("test"), scriptCommand("vitest run --coverage"))
+        .addScript(scriptKey("test"), scriptCommand("npm run test:watch"))
+        .addScript(scriptKey("test:coverage"), scriptCommand("vitest run --coverage"))
         .addScript(scriptKey("test:watch"), scriptCommand("vitest --"))
         .and()
       .files()
diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactory.java
index e3a44fa5a..58128d1b9 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactory.java
@@ -167,7 +167,7 @@ public class FrontendMavenModuleFactory {
           .phase(TEST)
           .configuration(
             """
-            <arguments>run test</arguments>
+            <arguments>run test:coverage</arguments>
             <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
             """
           )


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
index 9a13b3cec..92fc3836f 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/angular/core/domain/AngularModuleFactoryTest.java
@@ -46,12 +46,14 @@ class AngularModuleFactoryTest {
       .containing(nodeDependency("@typescript-eslint/eslint-plugin"))
       .containing(nodeDependency("@typescript-eslint/parser"))
       .containing(nodeDependency("eslint"))
-      .containing("\"ng\": \"ng\"")
-      .containing("\"watch\": \"ng build --watch --configuration development\"")
-      .containing("\"start\": \"ng serve\"")
-      .containing("\"build\": \"ng build --output-path=target/classes/static\"")
-      .containing("\"test\": \"ng test --coverage\"")
-      .containing("\"lint\": \"ng lint\"")
+      .containing(nodeScript("ng", "ng"))
+      .containing(nodeScript("watch", "ng build --watch --configuration development"))
+      .containing(nodeScript("start", "ng serve"))
+      .containing(nodeScript("build", "ng build --output-path=target/classes/static"))
+      .containing(nodeScript("test", "npm run test:watch"))
+      .containing(nodeScript("test:watch", "ng test --watch"))
+      .containing(nodeScript("test:coverage", "ng test --coverage"))
+      .containing(nodeScript("lint", "ng lint"))
       .containing("  \"jestSonar\": {\n    \"reportPath\": \"target/test-results\",\n    \"reportFile\": \"TESTS-results-sonar.xml\"\n  }")
       .and()
       .hasFile(".lintstagedrc.cjs")
diff --git a/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactoryTest.java
index cd9008eb7..8da9471ec 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/react/core/domain/ReactCoreModulesFactoryTest.java
@@ -45,7 +45,8 @@ class ReactCoreModulesFactoryTest {
       .containing(nodeScript("preview", "vite preview"))
       .containing(nodeScript("start", "vite"))
       .containing(nodeScript("lint", "eslint --ext .js,.ts,.tsx src/main/webapp/app/**/*"))
-      .containing(nodeScript("test", "vitest run --coverage"))
+      .containing(nodeScript("test", "npm run test:watch"))
+      .containing(nodeScript("test:coverage", "vitest run --coverage"))
       .containing(nodeScript("test:watch", "vitest --"))
       .and()
       .hasFile(".lintstagedrc.cjs")
diff --git a/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactoryTest.java
index 08349c9a6..852c0615e 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/svelte/core/domain/SvelteModuleFactoryTest.java
@@ -45,16 +45,18 @@ class SvelteModuleFactoryTest {
       .containing(nodeDependency("vite"))
       .containing(nodeDependency("vitest"))
       .containing(nodeDependency("vitest-sonar-reporter"))
-      .containing("\"dev\": \"vite dev --port 9000\"")
-      .containing("\"start\": \"vite dev --port 9000\"")
-      .containing("\"build\": \"vite build\"")
-      .containing("\"package\": \"vite package\"")
-      .containing("\"preview\": \"vite preview\"")
-      .containing("\"check\": \"svelte-check --tsconfig ./tsconfig.json\"")
-      .containing("\"check:watch\": \"svelte-check --tsconfig ./tsconfig.json --watch\"")
-      .containing("\"lint\": \"prettier --ignore-path .gitignore --check && eslint --ignore-path .gitignore .\"")
-      .containing("\"format\": \"prettier --ignore-path .gitignore --write\"")
-      .containing("\"test\": \"vitest run --coverage\"")
+      .containing(nodeScript("dev", "vite dev --port 9000"))
+      .containing(nodeScript("start", "vite dev --port 9000"))
+      .containing(nodeScript("build", "vite build"))
+      .containing(nodeScript("package", "vite package"))
+      .containing(nodeScript("preview", "vite preview"))
+      .containing(nodeScript("check", "svelte-check --tsconfig ./tsconfig.json"))
+      .containing(nodeScript("check:watch", "svelte-check --tsconfig ./tsconfig.json --watch"))
+      .containing(nodeScript("lint", "prettier --ignore-path .gitignore --check && eslint --ignore-path .gitignore ."))
+      .containing(nodeScript("format", "prettier --ignore-path .gitignore --write"))
+      .containing(nodeScript("test", "npm run test:watch"))
+      .containing(nodeScript("test:coverage", "vitest run --coverage"))
+      .containing(nodeScript("test:watch", "vitest --"))
       .containing("\"type\": \"module\"")
       .and()
       .hasFiles(".eslintignore", ".eslintrc.cjs", "tsconfig.json", "svelte.config.js", "vite.config.js", "vitest.config.ts")
diff --git a/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.java
index 1adf078b3..61ee593ae 100644
--- a/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/client/vue/core/domain/VueModulesFactoryTest.java
@@ -46,13 +46,14 @@ class VueModulesFactoryTest {
         .containing(nodeDependency("sinon"))
         .containing(nodeDependency("axios"))
         .containing(nodeDependency("vue-router"))
-        .containing("\"build\": \"vue-tsc -p tsconfig.build.json --noEmit && vite build --emptyOutDir\"")
-        .containing("\"dev\": \"vite\"")
-        .containing("\"lint\": \"eslint --ext .js,.ts,.vue src\"")
-        .containing("\"preview\": \"vite preview\"")
-        .containing("\"start\": \"vite\"")
-        .containing("\"test\": \"vitest run --coverage\"")
-        .containing("\"test:watch\": \"vitest --\"")
+        .containing(nodeScript("build", "vue-tsc -p tsconfig.build.json --noEmit && vite build --emptyOutDir"))
+        .containing(nodeScript("dev", "vite"))
+        .containing(nodeScript("lint", "eslint --ext .js,.ts,.vue src"))
+        .containing(nodeScript("preview", "vite preview"))
+        .containing(nodeScript("start", "vite"))
+        .containing(nodeScript("test", "npm run test:watch"))
+        .containing(nodeScript("test:coverage", "vitest run --coverage"))
+        .containing(nodeScript("test:watch", "vitest --"))
         .and()
       .hasFile(".lintstagedrc.cjs")
         .containing(
diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactoryTest.java
index 7e4efead3..b932a4890 100644
--- a/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/frontendmaven/domain/FrontendMavenModuleFactoryTest.java
@@ -166,7 +166,7 @@ class FrontendMavenModuleFactoryTest {
                       <goal>npm</goal>
                     </goals>
                     <configuration>
-                      <arguments>run test</arguments>
+                      <arguments>run test:coverage</arguments>
                       <npmInheritsProxyConfigFromMaven>false</npmInheritsProxyConfigFromMaven>
                     </configuration>
                   </execution>