This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 375674e4558 change the source type to module for JS dsl + fix test 
scripts (#8796)
375674e4558 is described below

commit 375674e455848e27904a5e89e8814604b777c459
Author: Hugo Guerrero <1001939+hguerr...@users.noreply.github.com>
AuthorDate: Wed Nov 30 00:45:53 2022 -0500

    change the source type to module for JS dsl + fix test scripts (#8796)
    
    * allow ES modules in JS DSL
    
    * update routes for tests
    
    * add tests for modules
---
 .../camel/dsl/js/JavaScriptRoutesBuilderLoader.java   |  2 +-
 .../dsl/js/JavaScriptRoutesBuilderLoaderTest.java     | 19 ++++++++++++++++---
 dsl/camel-js-dsl/src/test/resources/module.mjs        |  1 +
 .../routes/routes-with-component-configuration.js     |  2 +-
 .../test/resources/routes/routes-with-endpoint-dsl.js |  4 ++--
 .../src/test/resources/routes/routes-with-modules.js  |  4 ++++
 .../routes/routes-with-rest-configuration.js          |  2 +-
 7 files changed, 26 insertions(+), 8 deletions(-)

diff --git 
a/dsl/camel-js-dsl/src/main/java/org/apache/camel/dsl/js/JavaScriptRoutesBuilderLoader.java
 
b/dsl/camel-js-dsl/src/main/java/org/apache/camel/dsl/js/JavaScriptRoutesBuilderLoader.java
index b0c99ce6acb..93c74d40c63 100644
--- 
a/dsl/camel-js-dsl/src/main/java/org/apache/camel/dsl/js/JavaScriptRoutesBuilderLoader.java
+++ 
b/dsl/camel-js-dsl/src/main/java/org/apache/camel/dsl/js/JavaScriptRoutesBuilderLoader.java
@@ -77,7 +77,7 @@ public class JavaScriptRoutesBuilderLoader extends 
EndpointRouteBuilderLoaderSup
         // Run the script.
         //
         context.eval(
-                newBuilder(LANGUAGE_ID, reader, "Unnamed").buildLiteral());
+                newBuilder(LANGUAGE_ID, reader, 
"Unnamed").mimeType("application/javascript+module").buildLiteral());
 
         //
         // Close the polyglot context when the camel context stops
diff --git 
a/dsl/camel-js-dsl/src/test/java/org/apache/camel/dsl/js/JavaScriptRoutesBuilderLoaderTest.java
 
b/dsl/camel-js-dsl/src/test/java/org/apache/camel/dsl/js/JavaScriptRoutesBuilderLoaderTest.java
index 34b0afc59fa..8e81496c0b7 100644
--- 
a/dsl/camel-js-dsl/src/test/java/org/apache/camel/dsl/js/JavaScriptRoutesBuilderLoaderTest.java
+++ 
b/dsl/camel-js-dsl/src/test/java/org/apache/camel/dsl/js/JavaScriptRoutesBuilderLoaderTest.java
@@ -52,7 +52,8 @@ public class JavaScriptRoutesBuilderLoaderTest {
     @Test
     void componentsCanBeCustomized() throws Exception {
         try (DefaultCamelContext context = new DefaultCamelContext()) {
-            Resource resource = 
context.getResourceLoader().resolveResource("/routes/routes-with-component-configuration.js");
+            Resource resource = context.getResourceLoader()
+                    
.resolveResource("/routes/routes-with-component-configuration.js");
             context.getRoutesLoader().loadRoutes(resource);
 
             assertThat(context.getComponent("seda", 
SedaComponent.class)).satisfies(c -> {
@@ -64,7 +65,8 @@ public class JavaScriptRoutesBuilderLoaderTest {
     @Test
     void contextCanBeCustomized() throws Exception {
         try (DefaultCamelContext context = new DefaultCamelContext()) {
-            Resource resource = 
context.getResourceLoader().resolveResource("/routes/routes-with-context-configuration.js");
+            Resource resource = context.getResourceLoader()
+                    
.resolveResource("/routes/routes-with-context-configuration.js");
             context.getRoutesLoader().loadRoutes(resource);
 
             assertThat(context.isTypeConverterStatisticsEnabled()).isTrue();
@@ -91,7 +93,8 @@ public class JavaScriptRoutesBuilderLoaderTest {
     @Test
     void restCanBeConfigured() throws Exception {
         try (DefaultCamelContext context = new DefaultCamelContext()) {
-            Resource resource = 
context.getResourceLoader().resolveResource("/routes/routes-with-rest-configuration.js");
+            Resource resource = context.getResourceLoader()
+                    
.resolveResource("/routes/routes-with-rest-configuration.js");
             context.getRoutesLoader().loadRoutes(resource);
 
             assertThat(context.getRestConfiguration()).satisfies(c -> {
@@ -122,4 +125,14 @@ public class JavaScriptRoutesBuilderLoaderTest {
             });
         }
     }
+
+    @Test
+    void modulesCanBeImported() throws Exception {
+        try (DefaultCamelContext context = new DefaultCamelContext()) {
+            Resource resource = 
context.getResourceLoader().resolveResource("/routes/routes-with-modules.js");
+            context.getRoutesLoader().loadRoutes(resource);
+
+            assertThat(context.getRouteDefinitions()).hasSize(1);
+        }
+    }
 }
diff --git a/dsl/camel-js-dsl/src/test/resources/module.mjs 
b/dsl/camel-js-dsl/src/test/resources/module.mjs
new file mode 100644
index 00000000000..9e325124f60
--- /dev/null
+++ b/dsl/camel-js-dsl/src/test/resources/module.mjs
@@ -0,0 +1 @@
+export const greeting = "Hello World!";
\ No newline at end of file
diff --git 
a/dsl/camel-js-dsl/src/test/resources/routes/routes-with-component-configuration.js
 
b/dsl/camel-js-dsl/src/test/resources/routes/routes-with-component-configuration.js
index efe56967048..ca3e03ff61b 100644
--- 
a/dsl/camel-js-dsl/src/test/resources/routes/routes-with-component-configuration.js
+++ 
b/dsl/camel-js-dsl/src/test/resources/routes/routes-with-component-configuration.js
@@ -1,5 +1,5 @@
 
 const SedaType = Java.type("org.apache.camel.component.seda.SedaComponent");
 
-s = context.getComponent('seda', SedaType)
+const s = context.getComponent('seda', SedaType)
 s.setQueueSize(1234)
\ No newline at end of file
diff --git 
a/dsl/camel-js-dsl/src/test/resources/routes/routes-with-endpoint-dsl.js 
b/dsl/camel-js-dsl/src/test/resources/routes/routes-with-endpoint-dsl.js
index fc8456d92a7..eaf7eed0b0d 100644
--- a/dsl/camel-js-dsl/src/test/resources/routes/routes-with-endpoint-dsl.js
+++ b/dsl/camel-js-dsl/src/test/resources/routes/routes-with-endpoint-dsl.js
@@ -15,8 +15,8 @@
  * limitations under the License.
  */
 
-f = timer("tick");
-t = log("info");
+const f = timer("tick");
+const t = log("info");
 
 from(f)
     .to(t);
\ No newline at end of file
diff --git a/dsl/camel-js-dsl/src/test/resources/routes/routes-with-modules.js 
b/dsl/camel-js-dsl/src/test/resources/routes/routes-with-modules.js
new file mode 100644
index 00000000000..fc759ebed6e
--- /dev/null
+++ b/dsl/camel-js-dsl/src/test/resources/routes/routes-with-modules.js
@@ -0,0 +1,4 @@
+import { greeting } from "src/test/resources/module.mjs";
+
+from('timer:tick')
+    .to('log:info')
\ No newline at end of file
diff --git 
a/dsl/camel-js-dsl/src/test/resources/routes/routes-with-rest-configuration.js 
b/dsl/camel-js-dsl/src/test/resources/routes/routes-with-rest-configuration.js
index c54a31bd39a..c739f9c19e8 100644
--- 
a/dsl/camel-js-dsl/src/test/resources/routes/routes-with-rest-configuration.js
+++ 
b/dsl/camel-js-dsl/src/test/resources/routes/routes-with-rest-configuration.js
@@ -1,4 +1,4 @@
 
-c = restConfiguration()
+const c = restConfiguration()
 c.setComponent('undertow')
 c.setPort('1234')

Reply via email to