-
Notifications
You must be signed in to change notification settings - Fork 638
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
testing: add runIfMain #152
Comments
import.meta.url is now available in 0.2.10 so runTestsIfMain should be doable now. |
I guess this belongs to EDIT: if __name__ == "__main__":
do_something() is a very commonly used idiom in Python. Maybe we could add import { runIfMain } from "deno";
runIfMain(doSomething);
// or
runIfMain(() => {
doSomething1();
doSomething2();
}); Just thinking out loud. |
@ry any more thoughts on this? |
@bartlomieju Yes - I think if we implement if (imports.meta.url == window.location.toString()) {
runTests();
} |
FYI One can test if the script is main by using this: if (window.location.toString() == import.meta.url) {
console.log("main");
} We should be able to adapt for See the manual entry. |
Closed in #215 |
CC @ry |
Once we support
imports.meta.url
and have a way for testing if the current script is the main script, we want to have a two line snippit of code that will allow any test to be executed as a standalone testdeno foo_test.ts
rather than running the main entry point.Essentially something like this:
https://github.com/tensorflow/tensorflow/blob/c4e61ac1fd0b3b48461e2876b20fe56c09faa2ff/tensorflow/python/lib/io/tf_record_test.py#L484
The most basic form would be something like this:
But perhaps we can make this shorter by having a function like
runIfMain(imports.meta.url)
This came up in: #129
The text was updated successfully, but these errors were encountered: