ava icon indicating copy to clipboard operation
ava copied to clipboard

Implement .because() modifier for irregular tests

Open novemberborn opened this issue 1 year ago β€’ 14 comments

Based on discussion with @tommy-mitchell in https://github.com/avajs/ava/discussions/3224:

test.failing('does foo', t => {
  // ..
}).because('waiting on some/repo#123')

Should output:

βœ” [expected fail] does foo
  - waiting on some/repo#123

This requires changes to https://github.com/avajs/ava/blob/main/lib/create-chain.js so that a chainable object is returned for test.failing(), test.skip() etc. Here we then need to add a because function. The reason should make its way to the reporter where it can be printed beneath the test title.

This should be reflected in the type definitions and documentation. Once we've made some progress on this, work needs to be done with https://github.com/avajs/eslint-plugin-ava to support this new modifier.

It should be a test failure if because() is called with anything but a non-empty string.

novemberborn avatar Jul 30 '23 12:07 novemberborn

As commented in #3224, I also think .because() should come last.

sindresorhus avatar Jul 30 '23 13:07 sindresorhus

As commented in #3224, I also think .because() should come last.

That'd be easy to miss with a large test implementation / function body.

It's also a new thing to implement, test() doesn't return anything at the moment, and to make trailers work we'd have to change that, todo, failing, skip, and only. Adding a test.because() function which continues the chain is easier.

novemberborn avatar Jul 30 '23 19:07 novemberborn

This could have an ESLint rule as well, requiring a .because() description

tommy-mitchell avatar Jul 30 '23 20:07 tommy-mitchell

test() doesn't return anything at the moment, and to make trailers work we'd have to change that, todo, failing, skip, and only

Both #2979 and #2980 propose trailing modifiers on test(), so all three would benefit from it.

tommy-mitchell avatar Jul 31 '23 23:07 tommy-mitchell

That's fair β€”Β it's worth exploring but it's a chunk of work. Will amend the issue description.

novemberborn avatar Aug 15 '23 15:08 novemberborn

@novemberborn If no one has started working on the implementation, I'd like to take a crack at this.

adiSuper94 avatar Sep 18 '23 15:09 adiSuper94

Turned out to more complex than I anticipated. But I am still working on this.

adiSuper94 avatar Sep 29 '23 01:09 adiSuper94

@novemberborn I have made some test and trying to test it. But looks like when I run npm run test it calls the old version of create-chain.js instead of the new version that I have made edits to. Is this an issue you have ever faced ??

adiSuper94 avatar Sep 30 '23 17:09 adiSuper94

npm test calls npx test-ava which uses a different copy of AVA to test AVA with. But these tests are meant to be integration style, so you'd set up a fixture which uses the new syntax and then you observe the behavior.

novemberborn avatar Oct 12 '23 12:10 novemberborn

I haven't worked on this for a while now. And I am facing troubles setting up the the test, so that the tests use the my changes. If some else has more experience doing I'd like some help, or they can take up the this issue entirely.

adiSuper94 avatar Dec 22 '23 14:12 adiSuper94

@adiSuper94 , I can take up this issue if you want. In addition, what troubles were you having setting up the tests?

arescrimson avatar Jan 06 '24 01:01 arescrimson