Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript implementation not working correctly when running pytests #554

Closed
BrentBlanckaert opened this issue Oct 23, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@BrentBlanckaert
Copy link
Collaborator

BrentBlanckaert commented Oct 23, 2024

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 BrentBlanckaert added the bug Something isn't working label Oct 23, 2024
@BrentBlanckaert BrentBlanckaert self-assigned this Oct 23, 2024
@BrentBlanckaert
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

This issue has been resolved in #553

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant