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 ava plugin #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
46 changes: 46 additions & 0 deletions packages/ava/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict'

const path = require('path')
const pkgConf = require('pkg-conf')

const Api = require('ava/api')
const Verbose = require('ava/lib/reporters/verbose')
const Logger = require('ava/lib/logger')
const babelConfigHelper = require('ava/lib/babel-config')

module.exports = {
name: 'ava',
every: false,
files: true,
*func(files, opts) {
const conf = yield pkgConf('ava')
const filepath = pkgConf.filepath(conf)
const projectDir = filepath === null ? process.cwd() : path.dirname(filepath)

const defaults = {
babelConfig: babelConfigHelper.validate(conf.babel),
projectDir,
}
opts = Object.assign({}, defaults, opts)

const api = new Api(opts)
const reporter = new Verbose()
reporter.api = api

const logger = new Logger(reporter)
logger.start()

api.on('test-run', runStatus => {
reporter.api = runStatus
runStatus.on('test', logger.test)
runStatus.on('error', logger.unhandledError)
runStatus.on('stdout', logger.stdout)
runStatus.on('stderr', logger.stderr)
})

const runStatus = yield api.run(files.map(path.format))

console.log(reporter.finish(runStatus))
if (runStatus.failCount > 0) throw runStatus.errors
},
}
37 changes: 37 additions & 0 deletions packages/ava/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@taskr/ava",
"version": "1.2.0",
"description": "A plugin for taskr that run ava tests",
"repository": "lukeed/taskr",
"license": "MIT",
"author": {
"name": "Pine Mizune",
"email": "[email protected]",
"url": "https://github.com/pine"
},
"engines": {
"node": ">=4.6"
},
"scripts": {
"test": "ava -v test/*.js"
},
"main": "index.js",
"files": [
"index.js"
],
"keywords": [
"taskr",
"taskr-plugin",
"ava"
],
"dependencies": {
"ava": ">=0.20.0 <0.21.0",
"pkg-conf": "^2.0.0"
},
"devDependencies": {
"taskr": "^1.1.0"
},
"publishConfig": {
"access": "public"
}
}
29 changes: 29 additions & 0 deletions packages/ava/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# @taskr/ava [![npm](https://img.shields.io/npm/v/@taskr/ava.svg)](https://npmjs.org/package/@taskr/ava)

> Remove one or multiple directories


## Install

```
$ npm install --save-dev @taskr/ava
```


## Usage

```js
exports.test = function * (task) {
yield task.source('test/*.js').ava()
}
```

## Support

Any issues or questions can be sent to the [Taskr monorepo](https://github.com/lukeed/taskr/issues/new).

Please be sure to specify that you are using `@taskr/ava`.

## License

MIT &copy; [Pine Mizune](https://github.com/pine)
5 changes: 5 additions & 0 deletions packages/ava/test/fixture/fail.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test from 'ava'

test('fail', t => {
t.fail()
})
5 changes: 5 additions & 0 deletions packages/ava/test/fixture/pass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import test from 'ava'

test('pass', t => {
t.pass()
})
34 changes: 34 additions & 0 deletions packages/ava/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {join} from 'path'

import test from 'ava'
import Taskr from 'taskr'

test('pass', t => {
const taskr = new Taskr({
plugins: [ require('../') ],
tasks: {
*foo(f) {
yield f.source([ join(__dirname, '/fixture/pass.js') ]).ava()
},
},
})

return taskr.start('foo')
.then(() => t.pass('ok'))
.catch(() => t.fail('should be the test that was succeeded'))
})

test('fail', t => {
const taskr = new Taskr({
plugins: [ require('../') ],
tasks: {
*foo(f) {
yield f.source([ join(__dirname, '/fixture/fail.js') ]).ava()
},
},
})

return taskr.start('foo')
.then(() => t.failed('should be the test that was failed'))
.catch(() => t.pass('ok'))
})