question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

testing: add runIfMain

See original GitHub issue

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 test deno 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:

if (args[1] == imports.meta.url) {
  testMain();
}

But perhaps we can make this shorter by having a function like runIfMain(imports.meta.url)

This came up in: https://github.com/denoland/deno_std/pull/129

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
rycommented, Feb 12, 2019

@bartlomieju Yes - I think if we implement window.location as described in https://github.com/denoland/deno/issues/1750 then we can do

if (imports.meta.url == window.location.toString()) {
  runTests();
}
0reactions
bartlomiejucommented, May 6, 2019

CC @ry

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoid if __name__ == '__main__' in Python ... - Stack Overflow
My question is, can I avoid having to add this code to all files with the subclasses since the only thing that changes...
Read more >
Unit Testing for your applications - PureBasic Forums - English
I had a requirement to include unit testing in a project I'm ... way to only run if the file is the main...
Read more >
denolife/Lobby - Gitter
But I was getting prompts for my own static imports, I think. So is the test runner analyzing the test script and dynamically...
Read more >
Adding Test Runs in Test Execution - Tricentis
Adding Test Runs in Test Execution. A Test Run is an executable version of a certain Test Case. The idea is that a...
Read more >
deno標準テストモジュールの使い方 - Qiita
denoの標準ライブラリであるdeno_stdにはtestingモジュールが含まれています ... runIfMain } from 'https://deno.land/std@v0.26.0/testing/mod.ts'; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found