Comments (16)
@MarkTiedemann Seems reasonable to me. Go for it.
from deno_std.
What do y'all think about AVA's API?
Personally I love it and it already has great TS types, so should be very easy for Deno to adopt.
from deno_std.
Sorry, I meant the API definition (or a small subset of it), not necessarily the implementation. Would be awesome if AVA's implementation could be ported, but I agree that sounds hard. Among other things, AVA relies on Node's child_process
. It might be possible to replace that with Web Workers, but there could be other issues.
If, however, Deno were to adopt the API of a popular framework like AVA, it would make it easier to port the implementation in the future as better tooling comes along to do that, and as libraries begin to use more runtime agnostic patterns. At the very least it would make Deno more familiar and approachable.
The similarities don't have to go super deep, IMO, as long as test definitions and assertions are the same.
from deno_std.
@sholladay Hm - looks quite minimal and similar to ours. I'm not opposed to that API.
@piscisaureus thoughts? https://github.com/avajs/ava/blob/master/docs/01-writing-tests.md
from deno_std.
Personally, I really hate overloads that change the ariaty of the arguments. Omitting "optional" parameters is different. Adding complexity to a straight forward API without real value doesn't seem warranted IMO.
from deno_std.
Well, yeah, that would change the arity of the function. Before, however, the arity was kind of "hidden" in the object properties. In both cases, two things (the name and a function) need to be passed to the test function.
I still think an options object with two specifically named properties is more complex than two parameters... But it might also be that it's just more familiar to me since quite a lot of JS testing frameworks (for example, mocha
and ava
) have chosen this approach.
from deno_std.
See also denoland/deno#20
from deno_std.
I think It is good idea.
I still think an options object with two specifically named properties is more complex than two parameters...
I agree. I rarely saw test runner written in that style, name
and fn
look redundant.
It is natural to define test()
with 2 argument: description, body for most JS developers. It's usual style in Jasmine, mocha, RSpec..
As @kitsonk said, I know defining typed function with different number of arguments is quite complicated. But It can be by TypeScript. I understand this may not be the best, but believe a great and flexible feature of TS(JS).
Patches will be like this:
export type TestDescription = {
(description: string, body: TestFunction)
(body: TestFunction)
}
export const test: TestDescription = function test (descOrBody: string|TestFunction, body?: TestFunction): void {
let name: string;
let fn: TestFunction;
if (typeof descOrBody === "string") {
name = descOrBody;
fn = body;
} else {
name = descOrBody.name;
fn = descOrBody;
}
if (!name) {
throw new Error("Test function may not be anonymous");
}
if (filter(name)) {
tests.push({ fn, name });
} else {
filtered++;
}
}
Obviously, more discussions will be neededπ§
from deno_std.
I think the correct overloaded typings are:
declare function test(fn: () => void): void;
declare function test(name: string, fn: () => void): void;
Which could be used as follows:
test(function example() { /* test code */ })
test('example', () => { /* test code */ })
Unfortunately, I don't think it's possible to distinguish named and anonymous functions in TypeScript... so that's gotta be a runtime fn.name
check.
from deno_std.
The implementation of the overloading might not look all too pretty.
export function test(fnOrName: (() => void) | string, undefOrFn?: () => void) {
if (typeof fnOrName === "function") {
if (fnOrName.name === "") {
throw new Error(`'fn' must be a named function`);
} else if (undefOrFn !== undefined) {
throw new Error(`second parameter must be 'undefined'`);
} else {
let fn = fnOrName;
let name = fnOrName.name;
// Yay!
}
} else if (typeof fnOrName === "string") {
if (typeof undefOrFn !== "function") {
throw new Error(
`'fn' must be typeof 'function', but found '${typeof fnOrNone}'`
);
} else {
let fn = undefOrFn;
let name = fnOrName;
// Yay!
}
} else {
throw new Error(
`first parameter must be typeof 'function' or 'string', but found '${typeof fnOrName}'`
);
}
}
But using the API is more intuitive, IMHO.
from deno_std.
@ry Would you accept a PR that implements this breaking change? If so, I'd start working on it.
from deno_std.
I dislike overloading this much further...
I think it's going to be much more useful to add setup and teardown, an example might be something like this: hayd@987ef51
from deno_std.
@MarkTiedemann Any progress? I want see it π§.
@hayd @kitsonk If you don't like definition overload, let us consider defining test
function with exactly 2 arguments? We have overload for a while, and deprecate early style of test in the future.
from deno_std.
@MarkTiedemann Any progress? I want see it π§.
Not yet, unfortunately. I was working on deno_install
in the past week.
My next week is gonna be busy, too, so if you want to work on it, feel free!
I think it's going to be much more useful to add setup and teardown
I guess that's a matter of taste.
I personally don't like it when test frameworks offer a special way to do setup and teardown (which you have to learn or look up in the docs).
I prefer a plain old function call for setup and a try-finally-block with a function call for teardown. For example:
test(function exampleTest() {
mySetupCode()
try {
myTestCode()
} finally {
myTeardownCode()
}
})
In this case, you don't have to know the test framework. This works everywhere JS works. It's plain and simple.
Also, not many test cases actually require custom setup or teardown code, whereas all test cases require a name. So if I had to choose between those features, as you seem to imply, I'd go with the less verbose naming feature rather than the setup and teardown feature.
from deno_std.
See also #128.
from deno_std.
If someone ported AVA to deno_std and it worked perfectly, I would be happy to have it. But likely that won't happen - because it looks big and complex.
I'm a fan of the current testing module because of how minimal it is. I realize it has some problems at the moment (#152, #162, #122), but I intend to clean it up soon. I think it's worthwhile to have a very minimal std testing module.
from deno_std.
Related Issues (20)
- Log: debug level logs not showing HOT 3
- suggestion: more readable function chaining for `collections` (pipe, chain, data-last)
- The OS Signals Async iterator example is broken because `std/signal` was removed HOT 1
- deprecation(log): deprecate `LogRecord` class and use plain object instead HOT 3
- question(log): remove `setup()` and `destroy()` from `BaseHandler`? HOT 8
- question(log): public methods in classes HOT 1
- proposal(front_matter): fix file names and exports HOT 5
- is it possible to cache all std lib? HOT 2
- suggestion: optional `reason` param for assert::unreachable
- proposal(std): standardise JSDoc tag usage HOT 4
- Log FileHandler chokes at messages > 4096 HOT 4
- Publish older versions of std to jsr
- suggestion(semver): remove redundant `increment()` arguments
- feature request: grapheme-cluster-aware string operations HOT 2
- bug(http): missing docs and `setCookie()` allows `Max-age` to be 0 HOT 5
- bug: `unable to analyze dynamic import` in `@std/testing/snapshot` HOT 2
- Failed to publish @std/expect to local jsr HOT 3
- suggestion: enable `no-sync-fn-in-async-fn` linting rule HOT 1
- suggestion: enable `single-var-declarator` linting rule
- flaky test failure on macOS with the error message `error: second time provided was later than self` 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.