Allow the following to disable a test:
Deno.test({
skip: true, // <--
name: "foobar",
fn() {
// ...
}
});
Then uncomment all disabled tests in cli/js and std and skip them like this. That way the APIs used in disabled tests will forcibly be kept up to date (most of the time). Seen in https://github.com/denoland/deno/issues/4092.
cc @bartlomieju
i like this.
test.skip(name, fn) for shorthand style, please! This is how it works in AVA.
@sholladay This is not compatible with current syntax. The proposal don't disrupt current api. See test documentation.
I could open a separate issue, I suppose. It's directly related, though.
People who don't use the object-based syntax (like me) don't want to have to start using it just to skip a test. It needs to support the shorthand form.
If we want to apply this to the shorthand (which we currently have two of unfortunately), we can give it an options object containing the missing fields from TestDefinition:
export function test(t: TestDefinition): void;
export function test(fn: TestFunction, options?: Omit<TestDefinition, "name" | "fn">): void;
// ...
Why not use the API of an existing popular testing library like AVA? Not only does that make things more familiar to users, but AVA already has high quality TypeScript type definitions that can be reused, which makes Deno development and maintenance easier. It's also a superior API in my opinion.
test.skip(name, fn);
I'm ok with test.skip(name, fn)
The only problem with that, is that it makes it harder to do a conditional skip. For example, you might want to skip on a particular OS for a time period:
Deno.test({
skip: Deno.build.os === "win",
name: "skip on windows",
fn() { /* ... */ }
}
It is also easier to comment out or remove...
I mean, you could use a simple ternary to do the same thing with function shorthand. I already destructure const { test } = Deno anyway, so it doesn't even add any lines for me, unlike the object form.
const testNix = Deno.build.os === 'win' ? Deno.test.skip : Deno.test;
testNix('skip on windows', () => { /* ... */ });
There are other possibilities here, too. With AVA, one can write a test macro to conditionally pass/fail any tests that use it.
They are also planning to implement t.cancel() to cancel a test during execution, which would look like this...
Deno.test('skip on windows', (t) => {
if (Deno.build.os === 'win') {
t.cancel();
}
});
I said harder, not impossible.
Most helpful comment
The only problem with that, is that it makes it harder to do a conditional skip. For example, you might want to skip on a particular OS for a time period:
It is also easier to comment out or remove...