elsa-core/test/integration/Elsa.JavaScript.IntegrationTests
Marko Lahma 14173a19eb
Update Jint to 4.15.3 and stop blocking the calling thread on promises (#7894)
* chore(javascript): update Jint to 4.15.3 and stop blocking on promises

`Engine.Evaluate(...).UnwrapIfPromise()` blocks the calling thread while the
engine's event loop drains, which is exactly the wrong thing to do inside an
`async` method — an expression that awaits a .NET `Task`, such as one calling
`getSecret()`, held a thread pool thread for the duration of the I/O.
`Engine.EvaluateAsync` awaits the returned promise instead, and takes the
cancellation token while it is at it.

The Jint version is moved from 4.4.2 to 4.15.3. `EvaluateAsync` arrived in
4.14.0, but the pin lands past 4.15.2 deliberately: once expressions genuinely
suspend and resume instead of draining the event loop on the calling thread,
they exercise the async suspension machinery 4.15.2 corrected — an `await` on a
right-hand side no longer stores the suspension sentinel, async generators and
`for await...of` preserve loop iteration state across a suspension, and a
suspension node is unwrapped correctly. Shipping the non-blocking change on an
earlier 4.14/4.15 would enable exactly the code paths those releases fixed.

One default changed along the way: since 4.14 `Interop.ArrayConversion` defaults
to `LiveView`, so a CLR array reaches script as a live view over the original
array rather than as a copy. That is observable — a script that sorts an array
would now reorder the workflow's own array, and the value round-trips back as
its original element type rather than as `object[]`. The evaluator therefore
pins the previous `Copy` behaviour so the upgrade is not a behavioural change;
hosts that prefer the live view can opt in through
`JintOptions.ConfigureEngineOptions`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0179sA2T7HuRfRfSc2JirFik

* test(javascript): pin the array copy lane and adopt JsString.Create

The array audit. The parent commit fixes `ArrayConversion` to `Copy`, because
4.14 changed the default to `LiveView` and the two differ in behaviour a script
can observe. The existing tests assert what a copy *produces*, which a live view
also satisfies for a value nothing mutates; asking the engine how many
conversions of each kind it performed (4.15.1's interop conversion counters)
pins the lane itself. The second assertion is the more interesting one: an
ordinary evaluation converts no CLR array at all, because Elsa converts
collection-valued variables itself in `ObjectConverterHelper` long before Jint's
array lane could see them. That makes the `ArrayConversion` setting a narrow
compatibility pin rather than something every evaluation depends on.

`JsString.Create` (public since Jint 4.15.3) is adopted in
`JsonElementConverter`, where the string case was the only one still routed
through `JsValue.FromObject` — re-entering the whole conversion pipeline, the
registered object converters and this one included, to arrive at the same call
the number and boolean cases beside it already make directly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016uV6H9cTntzsoKiaJRBn4f

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-17 01:02:04 +02:00
..
ArrayConversionTests.cs Update Jint to 4.15.3 and stop blocking the calling thread on promises (#7894) 2026-08-17 01:02:04 +02:00
Elsa.JavaScript.IntegrationTests.csproj Add JavaScript secret functions 2026-06-01 09:26:05 +02:00
GuidTests.cs Refactor flowchart activity execution logic to improve modularity and add enhanced support for FlowJoin activity types. 2025-12-10 21:34:00 +01:00
JavaScriptAndNetTypeTest.cs Parse VariableTestValues more robustly, leveraging ExpandoObject and type conversion logic. (#6883) 2025-08-31 08:50:07 +02:00
JintJavaScriptEvaluatorTests.cs Add integration tests for JavaScript function availability and behavior validation 2025-10-21 21:31:47 +02:00
JintJavaScriptFunctionBehaviorTests.cs Add DispatchWorkflow tests with new workflow definitions (#7035) 2025-11-06 20:47:20 +01:00
JsonConverterTest.cs Add integration tests for RunJavaScript activity and introduce WorkflowTestFixture 2025-10-21 20:02:27 +02:00
JsonElementConverterTests.cs Add integration tests for RunJavaScript activity and introduce WorkflowTestFixture 2025-10-21 20:02:27 +02:00
RunJavaScriptTests.cs Enhance WorkflowTestFixture and RunJavaScript tests with additional examples and helper methods 2025-10-21 20:36:24 +02:00
SecretsJavaScriptTests.cs Add JavaScript secret functions 2026-06-01 09:26:05 +02:00
ToJsonTests.cs Add integration tests for RunJavaScript activity and introduce WorkflowTestFixture 2025-10-21 20:02:27 +02:00