├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── fixture.js ├── gruntfile.js ├── license ├── package.json ├── readme.md └── tasks └── ava.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.js text eol=lf 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | .nyc_output 4 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '8' 4 | - '6' 5 | - '4' 6 | -------------------------------------------------------------------------------- /fixture.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | 3 | test('foo', t => { 4 | t.pass(); 5 | }); 6 | -------------------------------------------------------------------------------- /gruntfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = grunt => { 3 | grunt.initConfig({ 4 | ava: { 5 | test: ['fixture.js'], 6 | test2: { 7 | options: { 8 | verbose: true, 9 | nyc: true 10 | }, 11 | files: { 12 | src: ['fixture.js'] 13 | } 14 | } 15 | }, 16 | shell: { 17 | ava: { 18 | command: 'grunt ava', 19 | options: { 20 | callback(_, stdout, stderr, cb) { 21 | cb(/1.*passed/.test(stdout)); 22 | } 23 | } 24 | } 25 | } 26 | }); 27 | 28 | grunt.loadTasks('tasks'); 29 | grunt.loadNpmTasks('grunt-shell'); 30 | grunt.registerTask('default', ['shell:ava']); 31 | }; 32 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grunt-ava", 3 | "version": "0.19.0", 4 | "description": "Run AVA tests", 5 | "license": "MIT", 6 | "repository": "avajs/grunt-ava", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=4" 14 | }, 15 | "scripts": { 16 | "test": "xo && grunt" 17 | }, 18 | "files": [ 19 | "tasks" 20 | ], 21 | "keywords": [ 22 | "gruntplugin", 23 | "ava", 24 | "test", 25 | "runner", 26 | "concurrent", 27 | "parallel", 28 | "fast", 29 | "tape", 30 | "tap", 31 | "mocha", 32 | "qunit", 33 | "jasmine" 34 | ], 35 | "dependencies": { 36 | "ava": "^0.23.0", 37 | "dargs": "^5.1.0", 38 | "resolve-cwd": "^2.0.0" 39 | }, 40 | "devDependencies": { 41 | "grunt": "^1.0.1", 42 | "grunt-cli": "^1.2.0", 43 | "grunt-shell": "^2.1.0", 44 | "nyc": "^11.0.3", 45 | "xo": "*" 46 | }, 47 | "peerDependencies": { 48 | "grunt": ">=0.4.0" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # grunt-ava [![Build Status](https://travis-ci.org/avajs/grunt-ava.svg?branch=master)](https://travis-ci.org/avajs/grunt-ava) 2 | 3 | > Run [AVA](https://ava.li) tests 4 | 5 | Please consider if you really need Grunt for this. Using a [npm run script](https://github.com/avajs/ava#initialize) would be better. 6 | 7 | 8 | ## Install 9 | 10 | ``` 11 | $ npm install --save-dev grunt-ava 12 | ``` 13 | 14 | 15 | ## Usage 16 | 17 | ```js 18 | require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks 19 | 20 | grunt.initConfig({ 21 | ava: { 22 | test: ['test.js'], 23 | nycTest: { 24 | options: { 25 | verbose: true, 26 | nyc: true 27 | }, 28 | files: { 29 | src: ['test.js'] 30 | } 31 | } 32 | } 33 | }); 34 | 35 | grunt.registerTask('default', ['ava']); 36 | ``` 37 | 38 | Adheres to AVA [options](https://github.com/avajs/ava#configuration) in package.json. You can also specify options in the plugin as seen above. 39 | 40 | You can specify `nyc: true` in the plugin to run AVA with [`nyc`](https://github.com/istanbuljs/nyc). You must have `nyc` as a devDependency. `nyc` [options](https://github.com/istanbuljs/nyc#configuring-nyc) can be defined in package.json. 41 | 42 | 43 | ## License 44 | 45 | MIT © [Sindre Sorhus](https://sindresorhus.com) 46 | -------------------------------------------------------------------------------- /tasks/ava.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const childProcess = require('child_process'); 3 | const dargs = require('dargs'); 4 | const resolveCwd = require('resolve-cwd'); 5 | 6 | const BIN = require.resolve('ava/cli.js'); 7 | const HUNDRED_MEGABYTES = 1000 * 1000 * 100; 8 | 9 | module.exports = grunt => { 10 | grunt.registerMultiTask('ava', 'Run AVA tests', function () { 11 | const cb = this.async(); 12 | const opts = this.options(); 13 | const args = [BIN].concat(this.filesSrc, '--color', dargs(opts, {excludes: ['nyc']})); 14 | 15 | if (opts.nyc) { 16 | const nycBin = resolveCwd('nyc/bin/nyc.js'); 17 | 18 | if (nycBin) { 19 | args.unshift(nycBin); 20 | } else { 21 | grunt.warn('Couldn\'t find the `nyc` binary'); 22 | cb(); 23 | return; 24 | } 25 | } 26 | 27 | childProcess.execFile(process.execPath, args, { 28 | maxBuffer: HUNDRED_MEGABYTES 29 | }, (err, stdout, stderr) => { 30 | if (err) { 31 | grunt.warn(stderr || stdout || err); 32 | cb(); 33 | return; 34 | } 35 | 36 | grunt.log.write(stderr + stdout); 37 | cb(); 38 | }); 39 | }); 40 | }; 41 | --------------------------------------------------------------------------------