Deno: "deno test" should run all the functions named test* in current directory

Created on 30 May 2018  路  12Comments  路  Source: denoland/deno

And only in files that end in _test.ts.

Example:

// foo_test.ts
function testBar() {
  if (1 != 2) {
    throw Error("Test failed.");
  }
}

Most helpful comment

I think it鈥檚 better to have these thing prescribed - it鈥檚 very arbitrary and better if everyone just uses the same system

All 12 comments

Can't it be up to the community to create something that runs all files ending with _test.js? This seems a bit unnecessary...

I think it鈥檚 better to have these thing prescribed - it鈥檚 very arbitrary and better if everyone just uses the same system

It also wouldn't preclude someone from running some other test harness or some other pattern, they simply wouldn't execute deno test.

I think it's good if everyone uses the same system, but we shouldn't force the use of the test* pattern. Maybe it should be the default, but it will be better allowing custom patterns like deno test tests/*.

Attempting to implement this: https://github.com/robbym/deno/commit/d4b66fb9a8e0ce1ddd8b5c14f60a2b34c9bda1f8

How does one get stuff, like all the function names in a file, from the C API?
Functionality not there yet?

@robbym Yeah functionality is not there yet. Hold off on this for a bit... We've got one more sprint and then we'll be up and running on the prototype's runtime. It'll make more sense to talk about it once we've got that working.

So, you can do this if the function is exported:

// foo_test.ts
export function testFoo() {
  console.log("foo");
}

// test.ts
(async () => {
  const name = "foo_test.ts";
  const t = await import(name);
  t.testFoo();
})();

Is there a way to access these if the function is not exported?

Edit: One possible solution is to support users grouping their test function in a class that's Test prefixed e.g. TestFoo. https://stackoverflow.com/a/32071275/1240268 :/

Edit2: I think there's a nice way to do this with the current test(... api actually.

@ry close in favor of testing module in standard library?

Once import() is working I will add this to std testing similar to --fmt.

This is still desired. @hayd looking forward to it.

Resolved in #2783!

CC @ry

Nice work :D

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zugende picture zugende  路  3Comments

CruxCv picture CruxCv  路  3Comments

ry picture ry  路  3Comments

metakeule picture metakeule  路  3Comments

ry picture ry  路  3Comments