- Traverse the AST, using babel-traverse, and look for functions that would require a test.
- Create a model that stores information on each function that will be tested. This information would include the function name, parameters, any calls to other functions and if it returns a value.
- Use the model to genreate a new AST that would be the unit test. I’ll be using babel-generator.
I only wanted to genreate most of the boilerplate code that is needed for a unit test. Things like importing or requiring modules, setting up any mocks, and creating describe/test blocks for any functions.
The test won’t include any expectations. Stuff like this expect(true).toBe(true). I’ll leave that for the developer. It can get challenging to understand the purpose of a function by analyizing the AST. I also didn’t want this tool to remove the developer from writing a unit test.