From c9352a82e4be4b40f17c1f7e135bf1b66a05eb6a Mon Sep 17 00:00:00 2001 From: Dakuan Date: Wed, 20 Aug 2014 19:53:21 +0100 Subject: [PATCH] use stream path --- index.js | 3 ++- package.json | 51 ++++++++++++++++++++++++++------------------------- test.js | 22 +++++++++++++++++++--- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/index.js b/index.js index 46b5408..9a36eac 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,10 @@ var jest = require('jest-cli'), gutil = require('gulp-util'), through = require('through2'); -module.exports = function (options) { +module.exports = function (options) { options = options || {}; return through.obj(function (file, enc, cb) { + options.rootDir = options.rootDir || file.path; try { jest.runCLI({ config: options diff --git a/package.json b/package.json index 2a29b1f..4c32f77 100644 --- a/package.json +++ b/package.json @@ -4,44 +4,45 @@ "description": "gulp-jest =========", "main": "index.js", "scripts": { - "test": "mocha test.js -t 10000" + "test": "mocha test.js -t 10000" }, "repository": { - "type": "git", - "url": "git://github.com/Dakuan/gulp-jest.git" + "type": "git", + "url": "git://github.com/Dakuan/gulp-jest.git" }, "author": { - "name": "Dominic Barker", - "email": "dom.barker808@gmail.com", - "url": "http://www.dombarker.co.uk" + "name": "Dominic Barker", + "email": "dom.barker808@gmail.com", + "url": "http://www.dombarker.co.uk" }, "license": "MIT", "bugs": { - "url": "https://github.com/Dakuan/gulp-jest/issues" + "url": "https://github.com/Dakuan/gulp-jest/issues" }, "homepage": "https://github.com/Dakuan/gulp-jest", "dependencies": { - "jest-cli": "^0.1.18", - "gulp-util": "^3.0.0", - "through2": "^0.5.1", - "react-tools": "^0.11.1" + "jest-cli": "^0.1.18", + "gulp-util": "^3.0.0", + "through2": "^0.5.1", + "react-tools": "^0.11.1" }, "devDependencies": { - "assert": "^1.1.1", - "mocha": "^1.21.3" + "assert": "^1.1.1", + "mocha": "^1.21.3", + "gulp": "^3.8.7" }, "keywords": [ - "gulpplugin", - "jest", - "test", - "testing", - "unit", - "framework", - "runner", - "tdd", - "bdd", - "qunit", - "spec", - "tap" + "gulpplugin", + "jest", + "test", + "testing", + "unit", + "framework", + "runner", + "tdd", + "bdd", + "qunit", + "spec", + "tap" ] } diff --git a/test.js b/test.js index 995baf3..1e4494f 100644 --- a/test.js +++ b/test.js @@ -1,13 +1,14 @@ 'use strict'; var assert = require('assert'); +var gulp = require('gulp') var gutil = require('gulp-util'); var jest = require('./index'); var through2 = require('through2'); var out = process.stdout.write.bind(process.stdout); -it('should run unit test and pass', function (cb) { +it('should take a rootDir as an option', function (cb) { var stream = jest({ - rootDir: __dirname + rootDir: '__tests__' }); process.stdout.write = function (str) { @@ -20,9 +21,24 @@ it('should run unit test and pass', function (cb) { }; stream.write(new gutil.File({ - path: '__tests__/fixture.js', + path: '__tests__', contents: new Buffer('') })); stream.end(); }); + + +it('should use the scream path as the rootDir', function (cb) { + var stream = gulp.src('__tests__') + .pipe(jest()); + + process.stdout.write = function (str) { + out(str); + if (/test passed/.test(str)) { + assert(true); + process.stdout.write = out; + cb(); + } + }; +});