Translations: Français
It requires a special loader helper to correctly resolve import
s of JSPM packages when using AVA. The purpose of the loader is to allow you to run your tests without having to pre-build your JSPM project.
This recipe has only been tested with JSPM v0.17.0-beta.22, but it should work with any version of JSPM v0.17 and may work with v0.16.
Set up your Babel options to work with AVA if you have not already. NOTE: You can keep additional configuration in your JSPM config files to override these settings during bundling and building.
$ npm install --save-dev @babel/preset-env
{
"presets": ["@babel/preset-env"]
}
You can find more information about setting up Babel with AVA in the Babel recipe.
You will need to install the AVA JSPM loader as a dev dependency. You will also need to install @babel/register
.
$ npm install --save-dev ava-jspm-loader @babel/register
You will also need to update your AVA config in the package.json
or ava.config.js
to use the JSPM loader.
package.json
:
{
"ava": {
"require": [
"@babel/register",
"ava-jspm-loader"
]
}
}
NOTE: If you use async/await in your source code (not in your test code), you will need to install @babel/polyfill
and add it to your require
array.
Note that you will need to use System.import
paths for all of your project files. So, if you named your project app
and you want to import your main.js
into a test file, you will need to import main from 'app/main'
.
import test from 'ava';
import main from 'app/main'; // Maps to your JSPM config for "app/main.js"
import BigNumber from 'bignumber.js'; // In jspm_packages
function fn() {
return Promise.resolve(new BigNumber('1234567890.123456789'));
}
test('example test', async t => {
t.is((await fn()).toString(), '1234567890.123456789');
});