Search code examples
node.jsecmascript-6babeljsava

AVA test setup: "Unexpected token export"


Problem

I'm trying to add AVA tests to a project and my tests are not parsing ES2015 modules correctly with my Babel setup. What is odd to me is the imports are working fine and if I run my npm run build and run the output from the REPL it works...so it seems that AVA is not transpiling export statements correctly or something is wrong with my config in my package.json? I've tried reading through the docs and looking at other examples without success.

Steps to reproduce

  1. Clone https://github.com/trevordmiller/utility-functions
  2. checkout the tests branch
  3. npm install
  4. npm test

Get an error (screenshot below) - ES2015 module export error on line 7 of getURLSlug:

AVA test error


Solution

  • Add "require": ["babel-register"] to the AVA configuration in your package.json