dodona-edu / universal-judge

Universal judge for educational software testing
https://docs.dodona.be/en/tested
MIT License
9 stars 5 forks source link

Typescript implementation not working correctly when running pytests #554

Closed BrentBlanckaert closed 1 month ago

BrentBlanckaert commented 1 month ago

PR: #553

When I run the test test_global_variable for typescript I get an error talking about the fact that it can't find ts-node:

[TESTed]$ python -m pytest tests/test_functionality.py::test_global_variable[typescript]
{"command": "start-judgement"}
{"title": "Tab", "command": "start-tab"}
{"command": "start-context"}
{"description": {"description": "GLOBAL_VAR", "format": "typescript"}, "command": "start-testcase"}
{"expected": "", "channel": "stderr", "command": "start-test"}
{"generated": "\nnode:internal/modules/run_main:115\n    triggerUncaughtException(\n    ^\nError [ERR_MODULE_NOT_FOUND]: Cannot find package 'ts-node' imported from /tmp/pytest-of-brent/pytest-146/test_global_variable_typescrip0/execution0/\n    at packageResolve (node:internal/modules/esm/resolve:841:9)\n
    at moduleResolve (node:internal/modules/esm/resolve:914:18)\n    at defaultResolve (node:internal/modules/esm/resolve:1119:11)\n    at nextResolve (node:internal/modules/esm/hooks:791:28)\n    at Hooks.resolve (node:internal/modules/esm/hooks:238:30)\n    at ModuleLoader.resolve (node:internal/modules/
esm/loader:504:35)\n    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:38)\n    at ModuleLoader.import (node:internal/modules/esm/loader:474:34)\n    at Hooks.register (node:internal/modules/esm/hooks:150:53)\n    at initializeHooks (node:internal/modules/esm/utils:317:17) {\n  code: 'ERR_MODULE_NOT_FOUND'\n}\n\nNode.js v22.2.0\n", "status": {"enum": "wrong", "human": "Onverwachte uitvoer"}, "command": "close-test"}
{"expected": "\"GLOBAL\"", "channel": "return", "command": "start-test"}
{"message": "Ontbrekend resultaat", "command": "append-message"}
{"generated": "", "status": {"enum": "wrong", "human": "Ontbrekende returnwaarde"}, "command": "close-test"}
{"status": {"enum": "wrong", "human": "Ontbrekend resultaat"}, "command": "escalate-status"}
{"message": {"description": "Standaardfout was:\n\nnode:internal/modules/run_main:115\n    triggerUncaughtException(\n    ^\nError [ERR_MODULE_NOT_FOUND]: Cannot find package 'ts-node' imported from /tmp/pytest-of-brent/pytest-146/test_global_variable_typescrip0/execution0/\n    at packageResolve (node:int
ernal/modules/esm/resolve:841:9)\n    at moduleResolve (node:internal/modules/esm/resolve:914:18)\n    at defaultResolve (node:internal/modules/esm/resolve:1119:11)\n    at nextResolve (node:internal/modules/esm/hooks:791:28)\n    at Hooks.resolve (node:internal/modules/esm/hooks:238:30)\n    at ModuleLoad
er.resolve (node:internal/modules/esm/loader:504:35)\n    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:241:38)\n    at ModuleLoader.import (node:internal/modules/esm/loader:474:34)\n    at Hooks.register (node:internal/modules/esm/hooks:150:53)\n    at initializeHooks (node:internal/modules/esm/utils:317:17) {\n  code: 'ERR_MODULE_NOT_FOUND'\n}\n\nNode.js v22.2.0\n", "format": "code"}, "command": "append-message"}
{"command": "close-testcase"}
{"command": "close-context"}
{"command": "close-tab"}
{"command": "close-judgement"}

This might be because I don't call ts-node directly but I use node like so:

node --no-warnings --loader ts-node/esm <file_name>.mts

The weird thing about this is that my imlementation does work when I run the following command where the config file links to the exact same test/solution:

python -m tested -c exercise/simple-example/config.json

Because of this I suppect that there might be something missing in the flake.nix file.

BrentBlanckaert commented 1 month ago

When running node --no-warnings --loader ts-node/esm <file_name>.mts in the root folder or any of its subfolders I face no problems. Specifically when I run outside of the project it will generate a simular error.

BrentBlanckaert commented 1 month ago

This issues is fixed by using tsx instead. However I still get an error that the module "fs" is unknown.

{"command": "start-context"}
{"description": {"description": "invoertekst-1\n", "format": "console"}, "command": "start-testcase"}
{"message": {"description": "<div class='code'>ts(3,21): error TS2307: Cannot find module &#x27;fs&#x27; or its corresponding type declarations.</div>", "format": "html", "permission": "student"}, "command": "append-message"}
{"status": {"enum": "compilation error"}, "command": "escalate-status"}
{"accepted": false, "command": "close-testcase"}
{"command": "close-context"}
BrentBlanckaert commented 1 month ago

This issue has been resolved in #553