From cfbd3009d27c97bb6906a5e007aa89686068e45f Mon Sep 17 00:00:00 2001 From: {{name}} <{{email}}> Date: Sat, 21 Mar 2026 02:04:03 +0200 Subject: [PATCH 1/2] Fixed tests structure to eliminate nested mocha it() clauses and improved error messages. --- .../Models/JsonExecutionResult.cs | 9 ++++++--- ...xecuteAndRunAllUnitTestsWithMochaExecutionStrategy.cs | 7 +------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/Models/JsonExecutionResult.cs b/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/Models/JsonExecutionResult.cs index 36ca92e12a..089819400d 100644 --- a/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/Models/JsonExecutionResult.cs +++ b/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/Models/JsonExecutionResult.cs @@ -10,6 +10,9 @@ namespace OJS.Workers.ExecutionStrategies.Models public class JsonExecutionResult { private const string InvalidJsonReplace = "]}[},!^@,Invalid,!^@,{]{["; + private const string MissingJsonStructureError = "Invalid console output! Please make sure there are no console.log statements in the solution. The system expects JSON output from Mocha test results."; + private const string MissingPassingFieldError = "Invalid console output! Please make sure there are no console.log statements in the solution. Missing or invalid 'passing' array in test results."; + private const string MissingFailuresFieldError = "Invalid console output! Please make sure there are no console.log statements in the solution. Missing or invalid 'failures' array with 'err.message' fields."; public IList TestErrors { get; set; } @@ -68,7 +71,7 @@ public static JsonExecutionResult Parse(string result, bool forceErrorExtracting } catch { - error = "Invalid console output!"; + error = MissingJsonStructureError; } var testsIndexes = new List(); @@ -80,7 +83,7 @@ public static JsonExecutionResult Parse(string result, bool forceErrorExtracting } catch { - error = "Invalid console output!"; + error = MissingPassingFieldError; } } @@ -97,7 +100,7 @@ public static JsonExecutionResult Parse(string result, bool forceErrorExtracting } catch { - error = "Invalid console output!"; + error = MissingFailuresFieldError; } } diff --git a/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/NodeJs/NodeJsPreprocessExecuteAndRunAllUnitTestsWithMochaExecutionStrategy.cs b/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/NodeJs/NodeJsPreprocessExecuteAndRunAllUnitTestsWithMochaExecutionStrategy.cs index feb3b1f205..8b3917c493 100644 --- a/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/NodeJs/NodeJsPreprocessExecuteAndRunAllUnitTestsWithMochaExecutionStrategy.cs +++ b/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/NodeJs/NodeJsPreprocessExecuteAndRunAllUnitTestsWithMochaExecutionStrategy.cs @@ -107,23 +107,18 @@ protected override async Task> ExecuteAgainstTestsI protected static string FormatTests(IEnumerable tests, bool isTypeScript) { var formattedTests = new List(); - var testCounter = 1; foreach (var test in tests) { // Use simple sequential test names - var testName = $"Test{testCounter}"; var testContent = test.Input.Trim(); // Format the test with proper it() wrapper var formattedTest = $@" {(isTypeScript ? "// @ts-ignore" : "")} - it('{testName}', function () {{ - {testContent} - }})"; + {testContent}"; formattedTests.Add(formattedTest); - testCounter++; } // Join all formatted tests From 1ebc58721670c17289a60a601a7f7d63fc4e9125 Mon Sep 17 00:00:00 2001 From: {{name}} <{{email}}> Date: Fri, 27 Mar 2026 12:22:33 +0200 Subject: [PATCH 2/2] Removed console.logs from user code to fix parsing errors in moha process output --- ...ScriptProjectMochaUnitTestsExecutionStrategy.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/NodeJs/Typescript/TypeScriptProjectMochaUnitTestsExecutionStrategy.cs b/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/NodeJs/Typescript/TypeScriptProjectMochaUnitTestsExecutionStrategy.cs index 83d040e68d..7f1b76e64b 100644 --- a/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/NodeJs/Typescript/TypeScriptProjectMochaUnitTestsExecutionStrategy.cs +++ b/Services/Common/OJS.Workers/OJS.Workers.ExecutionStrategies/NodeJs/Typescript/TypeScriptProjectMochaUnitTestsExecutionStrategy.cs @@ -23,12 +23,24 @@ protected override async Task> ExecuteAgainstTestsI { SaveZipSubmission(executionContext.FileContent, this.WorkingDirectory); + var esBuildExecutionArguments = new[] + { + "src/index.ts", + "--bundle", + "--platform=node", + "--format=cjs", + "--target=node21", + "--packages=external", + "--drop:console", + "--outfile=dist/app.bundle.js" + }; + var executor = this.CreateStandardExecutor(); var bundleResult = await executor.Execute( this.Settings.EsBuildModulePath, executionContext.TimeLimit, executionContext.MemoryLimit, - executionArguments: ["src/index.ts", "--bundle", "--platform=node", "--format=cjs", "--target=node21", "--packages=external", "--outfile=dist/app.bundle.js"], + executionArguments: esBuildExecutionArguments, workingDirectory: this.WorkingDirectory, cancellationToken: cancellationToken);