Comments (7)
@bartlomieju Yes - I think if we implement window.location
as described in denoland/deno#1750 then we can do
if (imports.meta.url == window.location.toString()) {
runTests();
}
from deno_std.
import.meta.url is now available in 0.2.10 so runTestsIfMain should be doable now.
from deno_std.
I guess this belongs to testing/mod.ts
but that file contains this notice: // Do not add imports in this file in order to be compatible with Node.
. So import { args } from "deno";
isn't desired there. Any thoughts?
EDIT:
On the other hand
if __name__ == "__main__":
do_something()
is a very commonly used idiom in Python. Maybe we could add runIfMain
to deno
itself? Then Python example would be written as:
import { runIfMain } from "deno";
runIfMain(doSomething);
// or
runIfMain(() => {
doSomething1();
doSomething2();
});
Just thinking out loud.
from deno_std.
@ry any more thoughts on this?
from deno_std.
FYI window.location
has landed in Deno v0.3.0
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 testing.runIfMain(import.meta)
See the manual entry.
from deno_std.
Closed in #215
from deno_std.
CC @ry
from deno_std.
Related Issues (20)
- dotenv should read from the root .env file HOT 4
- todo: use `using` keyword HOT 2
- todo: give `assertNotEquals()` assertion signature
- bug(ini): `parse() uses Object.defineProperty when setting object property` test is flaky HOT 1
- test errors for createHttpClient() at deno_std/http/server_test.ts HOT 5
- suggestion: re-structure `std/log` to adhere to singe-export files HOT 6
- suggestion: remove `flattenArgs()` from `log/formatters.ts` public API
- bug(toml): `parse` duplicates the character next to reserved escape sequences
- bug(expect): The function signature of `toMatchObject` is incorrect HOT 1
- `parse` of `std/flags` is not marked deprecated in API doc HOT 1
- todo: cleanup deprecated `Deno.*` APIs HOT 1
- Deno std_assert lacks a method to validate if a native Error object has the same message attribute as another. HOT 3
- Bring back examples folder HOT 2
- Secure Curves in the Web Cryptography API - secp256k1, X25519, X448, Ed25519, Ed448 HOT 6
- Strange behavior of the `assertRejects()` method. HOT 2
- assertSnapshot fails to match carriage return
- expect.toEquals() class instance check different from jest HOT 3
- todo: re-align `warnOnDeprecatedApi()` with runtime
- `io` module is marked deprecated in API doc HOT 2
- Add option to prepend `export ` to dotenv stringify HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deno_std.