Deno: Add "skip" and "only" functions on Deno.test

Created on 10 May 2020  路  4Comments  路  Source: denoland/deno

Improve Deno testing experience with "skip" and "only" features

skip

Adding "skip" to the test would cause the test to be skipped when the tests are run with deno test

Deno.test.skip('skipped test', () => {
  // ...
});

https://jestjs.io/docs/en/api.html#testskipname-fn
https://mochajs.org/#inclusive-tests

only

Adding "only" to the test would cause only tests with "only" to be ran when running deno test

Deno.test.only('only test example', () => {
  // ...
});

https://jestjs.io/docs/en/api.html#testonlyname-fn-timeout
https://mochajs.org/#exclusive-tests

info

deno --version
deno 1.0.0-rc1
v8 8.2.308
cli public API suggestion

All 4 comments

Ref https://github.com/denoland/deno/issues/4098#issuecomment-591019144. We have skip, and decided to add it as an option rather than with the function as a namespace containing similar functions (an illogical, non-extensible mess imo).

Something like only could be helpful (as an option). Though Deno.test() has no scopes so the effect of only becomes a bit more questionable. I'm +1 for it.

I'm a heavy user of stuff like .only while developing. The key is to make it fast to add while working and quick to remove.

Having to refactor...

Deno.test("some message", () => {
});

...to...

Deno.test({
  only: true
  name: "some message",
  () => {},
});

...is impractical. I think a Deno.test.only would be best because you just have to briefly add .only to the code.

(I prefer using .only as opposed to filtering via the command line because I can be sure I'm running only the specific test I'm looking at in the code and it's faster to add quickly)

One of the reasons I don't like the shorthand 馃槪 It's the same general problem of not being able to quickly add options to the shorthand, but more visible with only.

Since Deno.test() doesn't return anything currently, how about this:

Deno.test("abc", () => {
  // ...
}).only();

Generally put, it can return a handle allowing you to edit options ergonomically (only for the shorthand?). This would be a much nicer definition.

For anyone stumbling upon this issue in the future. Here is the docs for ignoring (skipping) tests https://github.com/denoland/deno/blob/master/docs/testing.md#ignoring-tests

I like the "ignoring tests based on options." I think it makes much more sense for tests that will be ignored longer than the time of writing the tests. I do think there are still use cases for .ignore() and .only()

.only()

Isolating test while writing/fixing it. I agree with @dsherret 's comment https://github.com/denoland/deno/issues/5197#issuecomment-626264310

~.skip()~ .ignore()

Writing tests for features before writing the implementation of those features. This would require ignoring all tests while each feature isn't implement. Then removing the ignores as you complete them.

TLD;
ignoring / only-ing via options is nice for long term ignores and only-s, but .ignore() and .only() are nice while developing tests. I am also not opposed to .only and .ignore being at the end as mentioned above.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

watilde picture watilde  路  3Comments

benjamingr picture benjamingr  路  3Comments

CruxCv picture CruxCv  路  3Comments

ry picture ry  路  3Comments

JosephAkayesi picture JosephAkayesi  路  3Comments