├── .editorconfig ├── .gitattributes ├── .gitignore ├── .npmrc ├── .travis.yml ├── fixture.js ├── fixture2.js ├── fixture3.js ├── gulpfile.js ├── index.js ├── license ├── package.json ├── readme.md └── test.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 eol=lf 2 | -------------------------------------------------------------------------------- /.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 | - '12' 4 | - '10' 5 | - '8' 6 | -------------------------------------------------------------------------------- /fixture.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | 3 | test('foo', t => { 4 | t.pass(); 5 | }); 6 | -------------------------------------------------------------------------------- /fixture2.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | 3 | test('bar', t => { 4 | t.pass(); 5 | }); 6 | -------------------------------------------------------------------------------- /fixture3.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | 3 | test('bar', t => { 4 | t.fail(); 5 | }); 6 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const gulp = require('gulp'); 3 | const ava = require('.'); 4 | 5 | exports.default = () => ( 6 | gulp.src('fixture.js') 7 | .pipe(ava({ 8 | verbose: true, 9 | nyc: true 10 | })) 11 | ); 12 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const PluginError = require('plugin-error'); 3 | const through = require('through2'); 4 | const dargs = require('dargs'); 5 | const resolveCwd = require('resolve-cwd'); 6 | const execa = require('execa'); 7 | 8 | const BINARY = require.resolve('ava/cli.js'); 9 | 10 | module.exports = options => { 11 | options = { 12 | silent: false, 13 | ...options 14 | }; 15 | 16 | const files = []; 17 | 18 | return through.obj((file, encoding, callback) => { 19 | if (file.isNull()) { 20 | callback(null, file); 21 | return; 22 | } 23 | 24 | if (file.isStream()) { 25 | callback(new PluginError('gulp-ava', 'Streaming not supported')); 26 | return; 27 | } 28 | 29 | files.push(file.path); 30 | 31 | callback(null, file); 32 | }, async callback => { 33 | const args = [BINARY].concat(files, '--color', dargs(options, {excludes: ['nyc']})); 34 | 35 | if (options.nyc) { 36 | const nycBin = resolveCwd('nyc/bin/nyc.js'); 37 | 38 | if (!nycBin) { 39 | callback(new PluginError('gulp-ava', 'Couldn\'t find the `nyc` binary')); 40 | return; 41 | } 42 | 43 | args.unshift(nycBin); 44 | } 45 | 46 | const subprocess = execa(process.execPath, args, {buffer: false}); 47 | 48 | if (!options.silent) { 49 | subprocess.stdout.pipe(process.stdout); 50 | subprocess.stderr.pipe(process.stderr); 51 | } 52 | 53 | try { 54 | await subprocess; 55 | callback(); 56 | } catch (_) { 57 | callback(new PluginError('gulp-ava', 'One or more tests failed')); 58 | } 59 | }); 60 | }; 61 | -------------------------------------------------------------------------------- /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": "gulp-ava", 3 | "version": "3.0.0", 4 | "description": "Run AVA tests", 5 | "license": "MIT", 6 | "repository": "avajs/gulp-ava", 7 | "author": { 8 | "name": "Sindre Sorhus", 9 | "email": "sindresorhus@gmail.com", 10 | "url": "sindresorhus.com" 11 | }, 12 | "engines": { 13 | "node": ">=8" 14 | }, 15 | "scripts": { 16 | "test": "xo && ava" 17 | }, 18 | "files": [ 19 | "index.js" 20 | ], 21 | "keywords": [ 22 | "gulpplugin", 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": "^2.4.0", 37 | "dargs": "^7.0.0", 38 | "execa": "^3.0.0", 39 | "fancy-log": "^1.3.3", 40 | "plugin-error": "^1.0.1", 41 | "resolve-cwd": "^3.0.0", 42 | "through2": "^3.0.0" 43 | }, 44 | "devDependencies": { 45 | "gulp": "^4.0.0", 46 | "hooker": "^0.2.3", 47 | "nyc": "^14.1.1", 48 | "vinyl-file": "^3.0.0", 49 | "xo": "^0.25.3" 50 | }, 51 | "peerDependencies": { 52 | "gulp": ">=4" 53 | }, 54 | "peerDependenciesMeta": { 55 | "gulp": { 56 | "optional": true 57 | } 58 | }, 59 | "xo": { 60 | "rules": { 61 | "ava/no-ignored-test-files": "off" 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # gulp-ava [![Build Status](https://travis-ci.org/avajs/gulp-ava.svg?branch=master)](https://travis-ci.org/avajs/gulp-ava) 2 | 3 | > Run [AVA](https://ava.li) tests 4 | 5 | 6 | ## Install 7 | 8 | ``` 9 | $ npm install --save-dev gulp-ava 10 | ``` 11 | 12 | 13 | ## Usage 14 | 15 | ```js 16 | const gulp = require('gulp'); 17 | const ava = require('gulp-ava'); 18 | 19 | exports.default = () => ( 20 | gulp.src('test.js') 21 | // `gulp-ava` needs file paths, so you can't have any plugins before it 22 | .pipe(ava({verbose: true})) 23 | ); 24 | ``` 25 | 26 | 27 | ## API 28 | 29 | ### ava(options?) 30 | 31 | This plugin adheres to AVA [options](https://github.com/avajs/ava#configuration) in package.json. You can also specify options in the plugin, as seen above, but prefer the package.json approach whenever possible. 32 | 33 | `gulp-ava` specific options: 34 | 35 | #### silent 36 | 37 | Type: `boolean`
38 | Default: `false` 39 | 40 | Only print output on failure. 41 | 42 | #### nyc 43 | 44 | Type: `boolean`
45 | Default: `false` 46 | 47 | 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. 48 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import vinylFile from 'vinyl-file'; 3 | import hooker from 'hooker'; 4 | import log from 'fancy-log'; 5 | import ava from '.'; 6 | 7 | test.cb('main', t => { 8 | const stream = ava(); 9 | 10 | hooker.hook(process.stdout, 'write', (...args) => { 11 | if (/2.*passed/.test(args.join(' '))) { 12 | hooker.unhook(log); 13 | t.pass(); 14 | t.end(); 15 | } 16 | }); 17 | 18 | stream.on('error', error => { 19 | t.ifError(error); 20 | t.end(); 21 | }); 22 | 23 | stream.write(vinylFile.readSync('fixture.js')); 24 | stream.write(vinylFile.readSync('fixture2.js')); 25 | stream.end(); 26 | }); 27 | --------------------------------------------------------------------------------