avajs / ava-codemods

Codemods for AVA
https://ava.li
MIT License
68 stars 16 forks source link

Conversion for Mocha #3

Closed jamestalmage closed 5 years ago

jamestalmage commented 8 years ago

From https://github.com/sindresorhus/ava/issues/644

@spudly has a start here: https://astexplorer.net/#/Uwl4f415pa

For completeness, here's a list of everything that I think would be needed for a complete mocha codemod:

  • [x] transform it() to test()
  • [x] add t parameter to a ArrowFunctionExpression passed to test()
  • [ ] don't de-sync async functions (the codemod above will mess those up currently)
  • [ ] add t parameter to a FunctionExpression passed to test()
  • [x] transform beforeEach() to test.beforeEach()
  • [x] transform afterEach() to test.afterEach()
  • [x] transform after() to test.after()
  • [x] transform before() to test.before()
  • [ ] remove describe() blocks, prepending their text to each test block's description
  • [ ] intelligently handle nested describe blocks if possible. how do we handle nested describe blocks with their own lifecycle hooks?
  • [ ] if the test body FunctionExpression or ArrowFunctionExpression is async, it should use test.serial instead of test

Also, it would be nice to have a separate codemod to transform chai assertions to ava assertions.

@spudly - https://github.com/sindresorhus/ava/issues/644#issuecomment-204361166

  • [ ] Transform tests containing a callback ( it('foo', function (done) { ... }) ) to test.cb(t => ... t.end();

@jfmengels - https://github.com/sindresorhus/ava/issues/644#issuecomment-204593881

jamestalmage commented 8 years ago

Ideas for handling lifecycle functions and groups: