Skip to content

Commit

Permalink
Close #23 PR: Add ES2015 support to CLI. Fixes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepolischuk authored and sindresorhus committed Sep 6, 2015
1 parent a5ad276 commit 4e2dce3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ var fs = require('fs');
var path = require('path');
var globby = require('globby');
var meow = require('meow');
var resolveFrom = require('resolve-from');
var updateNotifier = require('update-notifier');

try {
require(resolveFrom('.', 'babel-core/register') || resolveFrom('.', 'babel/register'));
} catch (err) {
require('babel-core/register');
}

var cli = meow({
help: [
'Usage',
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"node": ">=0.10.0"
},
"scripts": {
"test": "xo && node test/test.js | tap-dot"
"test": "xo !es2015.js && xo es2015.js --esnext && node test/test.js | tap-dot"
},
"files": [
"index.js",
Expand All @@ -47,6 +47,7 @@
"dependencies": {
"async-each-series": "^1.0.0",
"ava-init": "^0.1.0",
"babel-core": "^5.8.23",
"chalk": "^1.0.0",
"claim": "^1.3.0",
"each-async": "^1.0.0",
Expand All @@ -56,6 +57,7 @@
"meow": "^3.3.0",
"plur": "^2.0.0",
"pretty-ms": "^2.0.0",
"resolve-from": "^1.0.0",
"set-immediate-shim": "^1.0.1",
"squeak": "^1.2.0",
"update-notifier": "^0.5.0"
Expand Down
34 changes: 34 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,40 @@ test(function (t) {
```


### ES2015 support

You can write your tests in ES2015:

```js
test(t => {
t.pass();
t.end();
});
```

And run it in any node version.

```sh
$ ava
```

Also you can use your local `babel` or `babel-core` instead of built-in.

For example, package.json:

```json
{
"devDependencies": {
"ava": "^0.1.0",
"babel": "^5.8.0"
},
"scripts": {
"test": "ava"
}
}
```


## API

### test([name], body)
Expand Down
12 changes: 12 additions & 0 deletions test/es2015.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import test from 'tape';
import ava from '../lib/test';

test('run test', t => {
ava('foo', a => {
a.true(false);
a.end();
}).run(err => {
t.true(err);
t.end();
});
});
12 changes: 12 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
var test = require('tape');
var Promise = require('pinkie-promise');
var execFile = require('child_process').execFile;
var ava = require('../lib/test');
var Runner = require('../lib/runner');

Expand Down Expand Up @@ -361,3 +362,14 @@ test('record test duration', function (t) {
t.end();
});
});

test('ES2015 support', function (t) {
t.plan(2);

execFile('../cli.js', ['es2015.js'], {
cwd: __dirname
}, function (err, stdout) {
t.assert(!err, err);
t.assert(stdout.trim().length);
});
});

2 comments on commit 4e2dce3

@sindresorhus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebmck
Copy link

@sebmck sebmck commented on 4e2dce3 Sep 6, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌 ✨

Please sign in to comment.