-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Experimental test interface #2435
Conversation
6715962
to
16823db
Compare
81a46ac
to
4b9e1dc
Compare
4b9e1dc
to
f90010b
Compare
With this commit, test.cb() has been removed. See #2387
This is without macros in anticipation of the next change.
f90010b
to
b0aef86
Compare
Hi @novemberborn, currently to get accurate type checking for import test, { TestInterface } from 'ava';
function wrapTest(test: TestInterface): asserts test is TestInterface<MyContextType> {
test.beforeEach(t => {
t.context = getMyContext();
});
}
wrapTest(test);
test('foo', /* ... */); And it works very well. Just in case it can help you have some ideas :) |
@papb that's a nice trick! Would you like to add it to our TypeScript recipe? |
Hi @novemberborn, sorry for taking long to reply, I would but I don't have the time, if you like it please feel free to add it, no need to credit or anything :) |
I've added this to the AVA 4 milestone… I don't expect to land everything but would like to get at least the breaking changes in. |
Other than the "forkable" stuff, this is now in #2785 instead. |
This kicks off some experimental changes to AVA's test interface. That is, the
const test = require('ava')
stuff. Eventually this will be come AVA 4, but initially it'll be available through importingava/experimental
. You'll also have to enable theexperimentalTestInterfaces
experiment.Summary of (planned) changes:
test
function. If you're transpiling ESM, you'll no longer be able toimport { serial } from 'ava'
. This never worked anyway with proper ESM.title
functions.t.try()
.title
function you'll need to usetest.macro({ exec (t) { … }, title () { return 'title' })
.Macro
type has changed.test.macro()
automatically uses thet.context
type fromtest
.I tend to write service integration tests using AVA, which involve stubbing several APIs, managing database access and launching child processes. Crafting
t.context
for these tests is rather complicated.I'm tinkering with a "forkable test interface". You'd start off calling
test.make()
. This gives you an entirely new test chain, saytest2
. You can define hooks and whatnot, and then calltest2.fork()
to create yet another test chain, which will use the hooks defined ontest2
before forking.You'll be able to pass some options to
make()
andfork()
to constructt.context
, along the lines of what you'd do usingtest.before()
andtest.beforeEach()
. But, for TypeScript users, the context type will be inferable.We could also use this to create a test chain that always executes serially, or limits concurrency, or runs in isolation from other test chains in the same test file, or executes conditionally.
More to come!