elsa-core/test/integration/Elsa.JavaScript.IntegrationTests
Marko Lahma 2e9a3ad04f
Trim per-evaluation work in the JavaScript evaluator (#7892)
* perf(javascript): trim per-evaluation work in the JavaScript evaluator

A Jint engine is built for every expression evaluation, so anything done during
setup is paid for on every evaluation. Four pieces of that work are avoidable:

* The three `IObjectConverter` implementations are stateless but were allocated
  fresh for every engine. They are now shared static instances.

* Every prepared-script cache lookup — including hits — computed a SHA-256 hash
  of the expression text, base64-encoded it and concatenated a prefix, purely to
  build the cache key. Using a dedicated key type instead keeps the entries
  distinct from other users of the shared cache while letting the expression
  itself be the key, so a hit is a dictionary lookup. Looking the entry up
  directly rather than through `GetOrCreate` also keeps the factory closure off
  the hit path.

* `ObjectConverterHelper.ConvertToJsObject` built an explicit `PropertyDescriptor`
  per property and called `DefineOwnProperty`. `CreateDataProperty` is public,
  produces exactly the same writable/enumerable/configurable descriptor, and is
  the engine's fast path for it.

* The variable write-back resolved the workflow input names — walking the whole
  activity execution context ancestor chain — before checking whether there was
  anything to write back. Only variables the expression actually referenced are
  copied into the engine, so for the common case of an expression that never
  mentions `variables.` the container is empty and all of that work is wasted.
  The input names are also now looked up through a set rather than a list.

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

* test(javascript): pin the parse-failure test to the same exception every time

Calling `ThrowsAnyAsync<Exception>` twice only proved that both evaluations threw
something, which is exactly the assertion a poisoned cache would still satisfy:
had the failed preparation left a null or half-built entry behind, the second
evaluation would have failed too, just with a different exception. The test now
captures both exceptions and asserts they are the same type with the same
message, so "keeps reporting the same parse failure" is what is actually checked.

The message is stable to compare: it is `Could not prepare script: Unexpected end
of input (1:9)`, and since both evaluations run the identical script literal the
position is identical as well. No file or path detail is involved.

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

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-17 01:16:38 +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
ScriptCacheTests.cs Trim per-evaluation work in the JavaScript evaluator (#7892) 2026-08-17 01:16:38 +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