Testings are failing in Unexpected import token (probably due to non babel compiling issue)
initials.js
const initials = (string: string) =>
string.split(' ').map(word => word[0]).join('').slice(0, 2);
export default initials;
initials.test.js
import test from 'ava';
import initials from './initials';
test(t => t.expect(initials('Renato Ribeiro')).toBe('RR'));
Here's a print (Sorry, I have a problem with my term that I can't copy text :cry:)

package.json
{
"...": "...",
"ava": {
"babel": "inherit"
}
}
.babelrc
{
"presets": [
"next/babel"
],
"plugins": [
"transform-export-extensions"
]
}
Note: also tested with "require": ["babel-register"] in ava configuration
Repo: https://github.com/renatorib/next-jsonplaceholder
Initials test commit: https://github.com/renatorib/next-jsonplaceholder/commit/f5602a1f77163ca9a0fdac4f9bd76ccf10955fcd
$ ava --version
0.18.2
$ node --version
v7.5.0
(probably due to non babel compiling issue)
Yes.
You've disabled AVA's default transpilation of test files. It's now up to you to make sure your code runs in Node.js. You'll have to make sure to transpile the module syntax in your own Babel config.
@novemberborn
You've disabled AVA's default transpilation of test files.
Where?
My custom babel config (next/babel) support import/export and latest es versions.
And when I remove this config:
"ava": {
"babel": "inherit"
}
This error persists.
Why closed issue, since this not resolved?
And when I remove this config:
"ava": {
"babel": "inherit"
}
This error persists.
I actually get this error, which seems to be some Flow syntax that isn't removed:
โฏ npm t
> Placeholder@ test /private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T/tmp.zWXKadVBb1/next-jsonplaceholder
> ava
/private/var/folders/_6/p8qxp_3n62zg9081tvb0lcc80000gn/T/tmp.zWXKadVBb1/next-jsonplaceholder/utils/initials.js:3
const initials = (string: string) =>
^
SyntaxError: Unexpected token :
In any case, it means AVA transpiled the ESM syntax correctly.
My custom babel config (next/babel) support import/export and latest es versions.
But does it transpile to CJS?
Why closed issue, since this not resolved?
This issue tracker is for AVA itself. Happy to do the occasional support here, and happy to keep discussing, but this is a problem with your Babel setup, not AVA.
Put those to package.json:
{
"ava": {
"require": ["babel-register"]
},
"babel": {
"presets": ["@ava/stage-4"]
}
}
Source: transpiling-sources@AVA
@avajs, I would suggest making init more clever so those issues are gone.
To be "No extra setup needed." :)
I would like to add that it is very un-intuitive that you must add
"ava": {
"require": ["babel-register"]
}
In order to get ava working with ESNext source files and the documentation here is very misleading:
By default our Babel pipeline is applied to test and helper files ending in .js. If your project uses Babel then we'll automatically compile files using your project's Babel configuration.
Since you must add the snippet from above, which is given at the bottom of the doc.
@mdvorscak that paragraph does attempt to specify "test and helper files", but I agree it's not entirely clear. Perhaps "files" in the second sentence should be "these files", and we should add a paragraph linking to source compilation section?
I agree, I created a PR to attempt to clarify this behavior.
Most helpful comment
Put those to package.json:
Source: transpiling-sources@AVA
@avajs, I would suggest making init more clever so those issues are gone.
To be "No extra setup needed." :)