diff --git a/packages/ava/index.js b/packages/ava/index.js new file mode 100644 index 00000000..8a5a98c9 --- /dev/null +++ b/packages/ava/index.js @@ -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 + }, +} diff --git a/packages/ava/package.json b/packages/ava/package.json new file mode 100644 index 00000000..66e3e17f --- /dev/null +++ b/packages/ava/package.json @@ -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": "pinemz@gmail.com", + "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" + } +} diff --git a/packages/ava/readme.md b/packages/ava/readme.md new file mode 100644 index 00000000..cfdc1473 --- /dev/null +++ b/packages/ava/readme.md @@ -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 © [Pine Mizune](https://github.com/pine) diff --git a/packages/ava/test/fixture/fail.js b/packages/ava/test/fixture/fail.js new file mode 100644 index 00000000..d4494181 --- /dev/null +++ b/packages/ava/test/fixture/fail.js @@ -0,0 +1,5 @@ +import test from 'ava' + +test('fail', t => { + t.fail() +}) diff --git a/packages/ava/test/fixture/pass.js b/packages/ava/test/fixture/pass.js new file mode 100644 index 00000000..f4972fd4 --- /dev/null +++ b/packages/ava/test/fixture/pass.js @@ -0,0 +1,5 @@ +import test from 'ava' + +test('pass', t => { + t.pass() +}) diff --git a/packages/ava/test/index.js b/packages/ava/test/index.js new file mode 100644 index 00000000..95dd8e5d --- /dev/null +++ b/packages/ava/test/index.js @@ -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')) +})