Skip to content

Commit c3539c1

Browse files
fluffywafflessindresorhus
authored andcommitted
JSPM and SystemJS recipe.
<!-- Read the [contributing guidelines](https://github.com/avajs/ava/blob/master/contributing.md). We are excited about pull requests, but please try to limit the scope, provide a general description of the changes, and remember, it's up to you to convince us to land it. If this fixes an open issue, link to it in the following way: `Fixes #321`. New features and bug fixes should come with tests. --> A recipe for using AVA with JSPM, per discussion on #131. It requires the import of an external library I wrote for the purpose of encapsulating the loader shim so it can be maintained and updated. Here's a link to that library: [ava-jspm-loader](https://github.com/skorlir/ava-jspm-loader). Closes #941
1 parent 6c0f093 commit c3539c1

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

docs/recipes/jspm-systemjs.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# JSPM and SystemJS for ES2015
2+
3+
It requires a special loader helper to correctly resolve `import`s of JSPM packages when using AVA.
4+
5+
## Setup
6+
7+
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.
8+
9+
### Babel
10+
11+
Configure your .babelrc 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.
12+
13+
```json
14+
{
15+
"presets": ["es2015", "stage-2"]
16+
}
17+
```
18+
19+
You can find more information about setting up Babel with AVA in the [babelrc recipe](babelrc.md).
20+
21+
### JSPM Loader Helper
22+
23+
You will need to install the [AVA JSPM loader](https://github.com/skorlir/ava-jspm-loader) as a dev dependency.
24+
25+
```
26+
$ npm install --save-dev ava-jspm-loader
27+
```
28+
29+
You will also need to update your AVA config in package.json to use the JSPM loader.
30+
31+
```json
32+
{
33+
"ava": {
34+
"require": [
35+
"babel-register",
36+
"ava-jspm-loader"
37+
]
38+
}
39+
}
40+
```
41+
42+
NOTE: If you use async/await in your source code (not in your test code), you will need to install `babel-polyfill` from npm and add it to your `require` array.
43+
44+
### Example test file
45+
46+
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'`.
47+
48+
```js
49+
import test from 'ava';
50+
import main from 'app/main'; // maps to your JSPM config for "app/main.js"
51+
import BigNumber from 'bignumber.js'; // in jspm_packages
52+
53+
function fn() {
54+
return Promise.resolve(new BigNumber('1234567890.123456789'));
55+
}
56+
57+
test('example test', async t => {
58+
t.is((await fn()).toString(), '1234567890.123456789');
59+
});
60+
```

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,7 @@ It's the [Andromeda galaxy](https://simple.wikipedia.org/wiki/Andromeda_galaxy).
10081008
- [TypeScript](docs/recipes/typescript.md)
10091009
- [Configuring Babel](docs/recipes/babelrc.md)
10101010
- [Testing React components](docs/recipes/react.md)
1011+
- [JSPM and SystemJS](docs/recipes/jspm-systemjs.md)
10111012

10121013
## Support
10131014

0 commit comments

Comments
 (0)