Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ES2015 support to CLI #23

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

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

cwd: path.resolve(__dirname, '..')

}, function (err, stdout) {
t.assert(!err, err);
t.assert(stdout.trim().length);
});
});