From 938e601f10503367ea12afeaaa9ea1db2d42ad36 Mon Sep 17 00:00:00 2001 From: iHiD <286476+iHiD@users.noreply.github.com> Date: Wed, 18 Nov 2026 22:26:51 +0900 Subject: [PATCH 1/2] Report missing tests from the main jest run instead of a separate --listTests run Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- bin/run.sh | 67 +++++---------------------------------------------- src/output.ts | 9 +++++++ 2 files changed, 15 insertions(+), 61 deletions(-) diff --git a/bin/run.sh b/bin/run.sh index 0779f33..e1a8079 100755 --- a/bin/run.sh +++ b/bin/run.sh @@ -351,67 +351,9 @@ echo " ➤ Execution (tests: does the solution work?) " echo "╚═════════════════════════════════════════════════════════════╝" echo "" -echo "⚙️ corepack pnpm jest <...> --listTests" -echo "" -jest_tests=$(cd "${COREPACK_ROOT_DIR}" && "${bin_jest}" "${OUTPUT}*" --listTests --passWithNoTests --detectOpenHandles) || false - -if [ -z "${jest_tests}" ]; then - echo "❌ no jest tests (*.spec.js) discovered." - - runner_result="The submitted code was not subjected to any type or execution tests. At least one test was expected." - echo "{ \"version\": 1, \"status\": \"error\", \"message\": \"${runner_result}\" }" > $result_file - sed -Ei ':a;N;$!ba;s/\r{0,1}\n/\\n/g' $result_file - - echo "" - echo "If the solution previously contained configuration files, " - echo "they were disabled and now need to be restored." - echo "" - - # Restore configuration files - if test -f "${OUTPUT}babel.config.js.💥.bak"; then - echo "✔️ restoring babel.config.js in output" - unlink "${OUTPUT}babel.config.js" - mv "${OUTPUT}babel.config.js.💥.bak" "${OUTPUT}babel.config.js" || true - fi; - - if test -f "${OUTPUT}package.json.💥.bak"; then - echo "✔️ restoring package.json in output" - if test -f "${OUTPUT}package.json"; then - unlink "${OUTPUT}package.json" - fi - mv "${OUTPUT}package.json.💥.bak" "${OUTPUT}package.json" || true - fi; - - if test -f "${OUTPUT}pnpm-lock.yaml.💥.bak"; then - echo "✔️ restoring pnpm-lock.yaml in output" - if test -f "${OUTPUT}pnpm-lock.yaml"; then - unlink "${OUTPUT}pnpm-lock.yaml" - fi - mv "${OUTPUT}pnpm-lock.yaml.💥.bak" "${OUTPUT}pnpm-lock.yaml" || true - fi; - - if test -f "${OUTPUT}.npmrc.💥.bak"; then - echo "✔️ restoring .npmrc in output" - if test -f "${OUTPUT}.npmrc"; then - unlink "${OUTPUT}.npmrc" - fi - mv "${OUTPUT}.npmrc.💥.bak" "${OUTPUT}.npmrc" || true - fi; - - echo "" - echo "---------------------------------------------------------------" - echo "The results of this run have been written to 'results.json'." - echo "👁️ ${result_file}" - - # Test runner didn't fail! - exit 0 -fi - -echo "✔️ jest tests (*.spec.js) discovered." -echo $jest_tests - -# Run tests -echo "" +# Run tests. If Jest finds no test files, the reporter writes the "no tests" +# error to results.json. Checking for that here would mean starting Jest a +# second time (with --listTests) just to list the test files. echo "⚙️ corepack pnpm jest <...>" echo "" @@ -435,6 +377,9 @@ test_exit=$? if [ $test_exit -eq 1 ]; then echo "❌ not all tests (*.spec.js) passed." +elif grep -q "not subjected to any type or execution tests" "${result_file}"; then + # Jest found no test files, and the reporter wrote the "no tests" error. + echo "❌ no jest tests (*.spec.js) discovered." else echo "✅ all tests (*.spec.js) passed." fi; diff --git a/src/output.ts b/src/output.ts index fe1efde..7ee648e 100644 --- a/src/output.ts +++ b/src/output.ts @@ -63,6 +63,15 @@ export class Output { } public finish(aggregatedResults: AggregatedResult): void { + // If Jest found no test files, report that no tests ran. Checking here + // saves run.sh from starting Jest a second time to list the test files. + if (!this.results.status && aggregatedResults.numTotalTestSuites === 0) { + this.error( + 'The submitted code was not subjected to any type or execution ' + + 'tests. At least one test was expected.' + ) + } + if (!this.results.status) { this.results.status = aggregatedResults.numRuntimeErrorTestSuites === 0 && From f899b546e4f5b45fa51e0f0900361bdd6b868506 Mon Sep 17 00:00:00 2001 From: iHiD <286476+iHiD@users.noreply.github.com> Date: Thu, 19 Nov 2026 16:42:11 +0900 Subject: [PATCH 2/2] Write the "no tests" result in the version 1 format, as before Version 3 results can't have an empty list of tests, so when Jest finds no test files the reporter now writes exactly what run.sh wrote before: version 1, status "error" and the same message, with no tests key. Co-authored-by: iHiD <286476+iHiD@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 --- src/output.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/output.ts b/src/output.ts index 7ee648e..6ec9fb8 100644 --- a/src/output.ts +++ b/src/output.ts @@ -65,11 +65,22 @@ export class Output { public finish(aggregatedResults: AggregatedResult): void { // If Jest found no test files, report that no tests ran. Checking here // saves run.sh from starting Jest a second time to list the test files. + // Version 3 output can't have an empty list of tests, so this uses the + // version 1 format, which has no tests key. if (!this.results.status && aggregatedResults.numTotalTestSuites === 0) { - this.error( - 'The submitted code was not subjected to any type or execution ' + - 'tests. At least one test was expected.' + const artifact = JSON.stringify( + { + version: 1, + status: 'error', + message: + 'The submitted code was not subjected to any type or execution ' + + 'tests. At least one test was expected.', + }, + undefined, + 2 ) + fs.writeFileSync(this.outputFile, artifact) + return } if (!this.results.status) {