diff --git a/.editorconfig b/.editorconfig index 5d1263484..e000b0ce0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,13 +1,13 @@ -# editorconfig.org +# http://editorconfig.org root = true [*] indent_style = space indent_size = 2 -end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +end_of_line = lf [*.md] trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..fcadb2cf9 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf diff --git a/.gitignore b/.gitignore index cef23f007..6f636468b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,31 @@ -.DS_Store +# Logs +logs *.log -node_modules -build -*.node -components + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul coverage -*.orig -.idea -sandbox -test/out-fixtures/* -test/watch-*.txt -gulp.1 + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directory +# Commenting this out is preferred by some people, see +# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- +node_modules + +# Users Environment Variables +.lock-wscript + +# Garbage files +.DS_Store diff --git a/.jscsrc b/.jscsrc index d9e4b9a13..703b33fc3 100644 --- a/.jscsrc +++ b/.jscsrc @@ -1,3 +1,3 @@ { - "preset": "gulp", + "preset": "gulp" } diff --git a/.npmignore b/.npmignore deleted file mode 100644 index f93c39518..000000000 --- a/.npmignore +++ /dev/null @@ -1,12 +0,0 @@ -.DS_Store -*.log -node_modules -build -*.node -components -coverage -*.orig -.idea -sandbox -test/out-fixtures/* -test/watch-*.txt diff --git a/.travis.yml b/.travis.yml index 5756ce0ce..f621cabd3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,10 @@ sudo: false language: node_js node_js: - - "0.10" - - "0.12" - - "4" - - "6" - - "8" + - '8' + - '6' + - '4' + - '0.12' + - '0.10' after_script: - npm run coveralls -git: - depth: 10 diff --git a/LICENSE b/LICENSE index ee25a9095..6355a4b4a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,22 +1,21 @@ The MIT License (MIT) -Copyright (c) 2013-2016 Fractal +Copyright (c) 2013-2017 Blaine Bublitz , Eric Schoffstall and other contributors -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: +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: -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. -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. +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. diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..e2d9fb3ad --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,25 @@ +# http://www.appveyor.com/docs/appveyor-yml +# http://www.appveyor.com/docs/lang/nodejs-iojs + +environment: + matrix: + # node.js + - nodejs_version: "0.10" + - nodejs_version: "0.12" + - nodejs_version: "4" + - nodejs_version: "6" + - nodejs_version: "8" + +install: + - ps: Install-Product node $env:nodejs_version + - npm install + +test_script: + - node --version + - npm --version + - cmd: npm test + +build: off + +# build version format +version: "{build}" diff --git a/package.json b/package.json index 7ea402eca..31dab214c 100644 --- a/package.json +++ b/package.json @@ -1,27 +1,34 @@ { "name": "gulp", - "description": "The streaming build system", "version": "4.0.0-alpha.3", + "description": "The streaming build system.", "homepage": "http://gulpjs.com", - "repository": "gulpjs/gulp", - "author": "Fractal (http://wearefractal.com/)", - "keywords": [ - "build", - "stream", - "system", - "make", - "tool", - "asset", - "pipeline" + "author": "Gulp Team (http://gulpjs.com/)", + "contributors": [ + "Eric Schoffstall ", + "Blaine Bublitz " ], + "repository": "gulpjs/gulp", + "license": "MIT", + "engines": { + "node": ">= 0.10" + }, + "main": "index.js", "files": [ + "LICENSE", "index.js", "bin" ], "bin": { "gulp": "./bin/gulp.js" }, - "man": "gulp.1", + "scripts": { + "lint": "eslint . && jscs index.js bin/ test/", + "pretest": "npm run lint", + "test": "mocha --async-only", + "cover": "istanbul cover _mocha --report lcovonly", + "coveralls": "npm run cover && istanbul-coveralls" + }, "dependencies": { "glob-watcher": "^5.0.0", "gulp-cli": "^2.0.0", @@ -29,27 +36,27 @@ "vinyl-fs": "^3.0.0" }, "devDependencies": { - "coveralls": "^2.7.0", "eslint": "^1.7.3", "eslint-config-gulp": "^2.0.0", - "istanbul": "^0.3.0", + "expect": "^1.20.2", + "istanbul": "^0.4.3", + "istanbul-coveralls": "^1.0.3", "jscs": "^2.3.5", "jscs-preset-gulp": "^1.0.0", - "mkdirp": "^0.5.0", - "mocha": "^2.0.1", - "mocha-lcov-reporter": "^1.0.0", - "q": "^1.0.0", - "rimraf": "^2.2.5", - "should": "^5.0.1" - }, - "scripts": { - "lint": "eslint . && jscs *.js bin/ test/", - "pretest": "npm run lint", - "test": "mocha --reporter spec", - "coveralls": "istanbul cover _mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | coveralls && rm -rf ./coverage" + "mkdirp": "^0.5.1", + "mocha": "^3.0.0", + "rimraf": "^2.2.5" }, - "engines": { - "node": ">= 0.9" - }, - "license": "MIT" + "keywords": [ + "build", + "stream", + "system", + "make", + "tool", + "asset", + "pipeline", + "series", + "parallel", + "streaming" + ] } diff --git a/test/dest.js b/test/dest.js index c5f2729f6..3dbba4600 100644 --- a/test/dest.js +++ b/test/dest.js @@ -1,133 +1,127 @@ 'use strict'; var fs = require('fs'); +var path = require('path'); -var gulp = require('../'); -var should = require('should'); -var join = require('path').join; +var expect = require('expect'); var rimraf = require('rimraf'); -require('mocha'); +var gulp = require('../'); -var outpath = join(__dirname, './out-fixtures'); +var outpath = path.join(__dirname, './out-fixtures'); -describe('gulp output stream', function() { - describe('dest()', function() { - beforeEach(rimraf.bind(null, outpath)); - afterEach(rimraf.bind(null, outpath)); +describe('gulp.dest()', function() { + beforeEach(rimraf.bind(null, outpath)); + afterEach(rimraf.bind(null, outpath)); - it('should return a stream', function(done) { - var stream = gulp.dest(join(__dirname, './fixtures/')); - should.exist(stream); - should.exist(stream.on); - done(); - }); + it('should return a stream', function(done) { + var stream = gulp.dest(path.join(__dirname, './fixtures/')); + expect(stream).toExist(); + expect(stream.on).toExist(); + done(); + }); - it('should return a output stream that writes files', function(done) { - var instream = gulp.src(join(__dirname, './fixtures/**/*.txt')); - var outstream = gulp.dest(outpath); - instream.pipe(outstream); - - outstream.on('error', done); - outstream.on('data', function(file) { - // Data should be re-emitted right - should.exist(file); - should.exist(file.path); - should.exist(file.contents); - join(file.path, '').should.equal(join(outpath, './copy/example.txt')); - String(file.contents).should.equal('this is a test'); - }); - outstream.on('end', function() { - fs.readFile(join(outpath, 'copy', 'example.txt'), function(err, contents) { - should.not.exist(err); - should.exist(contents); - String(contents).should.equal('this is a test'); - done(); - }); + it('should return a output stream that writes files', function(done) { + var instream = gulp.src('./fixtures/**/*.txt', { cwd: __dirname }); + var outstream = gulp.dest(outpath); + instream.pipe(outstream); + + outstream.on('error', done); + outstream.on('data', function(file) { + // Data should be re-emitted right + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.contents).toExist(); + expect(file.path).toEqual(path.join(outpath, './copy/example.txt')); + expect(file.contents).toEqual('this is a test'); + }); + outstream.on('end', function() { + fs.readFile(path.join(outpath, 'copy', 'example.txt'), function(err, contents) { + expect(err).toNotExist(); + expect(contents).toExist(); + expect(contents).toEqual('this is a test'); + done(); }); }); + }); - it('should return a output stream that does not write non-read files', function(done) { - var instream = gulp.src(join(__dirname, './fixtures/**/*.txt'), { read: false }); - var outstream = gulp.dest(outpath); - instream.pipe(outstream); - - outstream.on('error', done); - outstream.on('data', function(file) { - // Data should be re-emitted right - should.exist(file); - should.exist(file.path); - should.not.exist(file.contents); - join(file.path, '').should.equal(join(outpath, './copy/example.txt')); - }); - outstream.on('end', function() { - fs.readFile(join(outpath, 'copy', 'example.txt'), function(err, contents) { - should.exist(err); - should.not.exist(contents); - done(); - }); + it('should return a output stream that does not write non-read files', function(done) { + var instream = gulp.src('./fixtures/**/*.txt', { read: false, cwd: __dirname }); + var outstream = gulp.dest(outpath); + instream.pipe(outstream); + + outstream.on('error', done); + outstream.on('data', function(file) { + // Data should be re-emitted right + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.contents).toNotExist(); + expect(file.path).toEqual(path.join(outpath, './copy/example.txt')); + }); + outstream.on('end', function() { + fs.readFile(path.join(outpath, 'copy', 'example.txt'), function(err, contents) { + expect(err).toExist(); + expect(contents).toNotExist(); + done(); }); }); + }); - it('should return a output stream that writes streaming files', function(done) { - var instream = gulp.src(join(__dirname, './fixtures/**/*.txt'), { buffer: false }); - var outstream = instream.pipe(gulp.dest(outpath)); - - outstream.on('error', done); - outstream.on('data', function(file) { - // Data should be re-emitted right - should.exist(file); - should.exist(file.path); - should.exist(file.contents); - join(file.path, '').should.equal(join(outpath, './copy/example.txt')); - }); - outstream.on('end', function() { - fs.readFile(join(outpath, 'copy', 'example.txt'), function(err, contents) { - should.not.exist(err); - should.exist(contents); - String(contents).should.equal('this is a test'); - done(); - }); + it('should return a output stream that writes streaming files', function(done) { + var instream = gulp.src('./fixtures/**/*.txt', { buffer: false, cwd: __dirname }); + var outstream = instream.pipe(gulp.dest(outpath)); + + outstream.on('error', done); + outstream.on('data', function(file) { + // Data should be re-emitted right + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.contents).toExist(); + expect(file.path).toEqual(path.join(outpath, './copy/example.txt')); + }); + outstream.on('end', function() { + fs.readFile(path.join(outpath, 'copy', 'example.txt'), function(err, contents) { + expect(err).toNotExist(); + expect(contents).toExist(); + expect(contents).toEqual('this is a test'); + done(); }); }); + }); - it('should return a output stream that writes streaming files into new directories', function(done) { - testWriteDir({}, done); - }); + it('should return a output stream that writes streaming files into new directories', function(done) { + testWriteDir({ cwd: __dirname }, done); + }); - it('should return a output stream that writes streaming files into new directories (buffer: false)', function(done) { - testWriteDir({ buffer: false }, done); - }); + it('should return a output stream that writes streaming files into new directories (buffer: false)', function(done) { + testWriteDir({ buffer: false, cwd: __dirname }, done); + }); - it('should return a output stream that writes streaming files into new directories (read: false)', function(done) { - testWriteDir({ read: false }, done); - }); + it('should return a output stream that writes streaming files into new directories (read: false)', function(done) { + testWriteDir({ read: false, cwd: __dirname }, done); + }); - it('should return a output stream that writes streaming files into new directories (read: false, buffer: false)', function(done) { - testWriteDir({ buffer: false, read: false }, done); - }); + it('should return a output stream that writes streaming files into new directories (read: false, buffer: false)', function(done) { + testWriteDir({ buffer: false, read: false, cwd: __dirname }, done); + }); - function testWriteDir(srcOptions, done) { - var instream = gulp.src(join(__dirname, './fixtures/stuff'), srcOptions); - var outstream = instream.pipe(gulp.dest(outpath)); + function testWriteDir(srcOptions, done) { + var instream = gulp.src('./fixtures/stuff', srcOptions); + var outstream = instream.pipe(gulp.dest(outpath)); - outstream.on('error', done); - outstream.on('data', function(file) { - // Data should be re-emitted right - should.exist(file); - should.exist(file.path); - join(file.path, '').should.equal(join(outpath, './stuff')); - }); - outstream.on('end', function() { - fs.exists(join(outpath, 'stuff'), function(exists) { - /* Stinks that ok is an expression instead of a function call */ - /* jshint expr: true */ - should(exists).be.ok; - /* jshint expr: false */ - done(); - }); + outstream.on('error', done); + outstream.on('data', function(file) { + // Data should be re-emitted right + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.path).toEqual(path.join(outpath, './stuff')); + }); + outstream.on('end', function() { + fs.exists(path.join(outpath, 'stuff'), function(exists) { + expect(exists).toExist(); + done(); }); - } + }); + } - }); }); diff --git a/test/src.js b/test/src.js index a85f237d6..4ec1df962 100644 --- a/test/src.js +++ b/test/src.js @@ -1,152 +1,150 @@ 'use strict'; -var gulp = require('../'); -var should = require('should'); -var join = require('path').join; +var path = require('path'); -require('mocha'); +var expect = require('expect'); -describe('gulp input stream', function() { - describe('src()', function() { - it('should return a stream', function(done) { - var stream = gulp.src(join(__dirname, './fixtures/*.coffee')); - should.exist(stream); - should.exist(stream.on); - done(); +var gulp = require('../'); + +describe('gulp.src()', function() { + it('should return a stream', function(done) { + var stream = gulp.src('./fixtures/*.coffee', { cwd: __dirname }); + expect(stream).toExist(); + expect(stream.on).toExist(); + done(); + }); + it('should return a input stream from a flat glob', function(done) { + var stream = gulp.src('./fixtures/*.coffee', { cwd: __dirname }); + stream.on('error', done); + stream.on('data', function(file) { + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.contents).toExist(); + expect(file.path).toEqual(path.join(__dirname, './fixtures/test.coffee')); + expect(file.contents).toEqual('this is a test'); }); - it('should return a input stream from a flat glob', function(done) { - var stream = gulp.src(join(__dirname, './fixtures/*.coffee')); - stream.on('error', done); - stream.on('data', function(file) { - should.exist(file); - should.exist(file.path); - should.exist(file.contents); - join(file.path, '').should.equal(join(__dirname, './fixtures/test.coffee')); - String(file.contents).should.equal('this is a test'); - }); - stream.on('end', function() { - done(); - }); + stream.on('end', function() { + done(); }); + }); - it('should return a input stream for multiple globs', function(done) { - var globArray = [ - join(__dirname, './fixtures/stuff/run.dmc'), - join(__dirname, './fixtures/stuff/test.dmc'), - ]; - var stream = gulp.src(globArray); + it('should return a input stream for multiple globs', function(done) { + var globArray = [ + './fixtures/stuff/run.dmc', + './fixtures/stuff/test.dmc', + ]; + var stream = gulp.src(globArray, { cwd: __dirname }); - var files = []; - stream.on('error', done); - stream.on('data', function(file) { - should.exist(file); - should.exist(file.path); - files.push(file); - }); - stream.on('end', function() { - files.length.should.equal(2); - files[0].path.should.equal(globArray[0]); - files[1].path.should.equal(globArray[1]); - done(); - }); + var files = []; + stream.on('error', done); + stream.on('data', function(file) { + expect(file).toExist(); + expect(file.path).toExist(); + files.push(file); + }); + stream.on('end', function() { + expect(files.length).toEqual(2); + expect(files[0].path).toEqual(path.join(__dirname, globArray[0])); + expect(files[1].path).toEqual(path.join(__dirname, globArray[1])); + done(); }); + }); - it('should return a input stream for multiple globs, with negation', function(done) { - var expectedPath = join(__dirname, './fixtures/stuff/run.dmc'); - var globArray = [ - join(__dirname, './fixtures/stuff/*.dmc'), - '!' + join(__dirname, './fixtures/stuff/test.dmc'), - ]; - var stream = gulp.src(globArray); + it('should return a input stream for multiple globs, with negation', function(done) { + var expectedPath = path.join(__dirname, './fixtures/stuff/run.dmc'); + var globArray = [ + './fixtures/stuff/*.dmc', + '!fixtures/stuff/test.dmc', + ]; + var stream = gulp.src(globArray, { cwd: __dirname }); - var files = []; - stream.on('error', done); - stream.on('data', function(file) { - should.exist(file); - should.exist(file.path); - files.push(file); - }); - stream.on('end', function() { - files.length.should.equal(1); - files[0].path.should.equal(expectedPath); - done(); - }); + var files = []; + stream.on('error', done); + stream.on('data', function(file) { + expect(file).toExist(); + expect(file.path).toExist(); + files.push(file); }); + stream.on('end', function() { + expect(files.length).toEqual(1); + expect(files[0].path).toEqual(expectedPath); + done(); + }); + }); - it('should return a input stream with no contents when read is false', function(done) { - var stream = gulp.src(join(__dirname, './fixtures/*.coffee'), { read: false }); - stream.on('error', done); - stream.on('data', function(file) { - should.exist(file); - should.exist(file.path); - should.not.exist(file.contents); - join(file.path, '').should.equal(join(__dirname, './fixtures/test.coffee')); - }); - stream.on('end', function() { - done(); - }); + it('should return a input stream with no contents when read is false', function(done) { + var stream = gulp.src('./fixtures/*.coffee', { read: false, cwd: __dirname }); + stream.on('error', done); + stream.on('data', function(file) { + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.contents).toNotExist(); + expect(file.path).toEqual(path.join(__dirname, './fixtures/test.coffee')); }); - it('should return a input stream with contents as stream when buffer is false', function(done) { - var stream = gulp.src(join(__dirname, './fixtures/*.coffee'), { buffer: false }); - stream.on('error', done); - stream.on('data', function(file) { - should.exist(file); - should.exist(file.path); - should.exist(file.contents); - var buf = ''; - file.contents.on('data', function(d) { - buf += d; - }); - file.contents.on('end', function() { - buf.should.equal('this is a test'); - done(); - }); - join(file.path, '').should.equal(join(__dirname, './fixtures/test.coffee')); - }); + stream.on('end', function() { + done(); }); - it('should return a input stream from a deep glob', function(done) { - var stream = gulp.src(join(__dirname, './fixtures/**/*.jade')); - stream.on('error', done); - stream.on('data', function(file) { - should.exist(file); - should.exist(file.path); - should.exist(file.contents); - join(file.path, '').should.equal(join(__dirname, './fixtures/test/run.jade')); - String(file.contents).should.equal('test template'); + }); + it('should return a input stream with contents as stream when buffer is false', function(done) { + var stream = gulp.src('./fixtures/*.coffee', { buffer: false, cwd: __dirname }); + stream.on('error', done); + stream.on('data', function(file) { + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.contents).toExist(); + var buf = ''; + file.contents.on('data', function(d) { + buf += d; }); - stream.on('end', function() { + file.contents.on('end', function() { + expect(buf).toEqual('this is a test'); done(); }); + expect(file.path).toEqual(path.join(__dirname, './fixtures/test.coffee')); }); - it('should return a input stream from a deeper glob', function(done) { - var stream = gulp.src(join(__dirname, './fixtures/**/*.dmc')); - var a = 0; - stream.on('error', done); - stream.on('data', function() { - ++a; - }); - stream.on('end', function() { - a.should.equal(2); - done(); - }); + }); + it('should return a input stream from a deep glob', function(done) { + var stream = gulp.src('./fixtures/**/*.jade', { cwd: __dirname }); + stream.on('error', done); + stream.on('data', function(file) { + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.contents).toExist(); + expect(file.path).toEqual(path.join(__dirname, './fixtures/test/run.jade')); + expect(file.contents).toEqual('test template'); + }); + stream.on('end', function() { + done(); + }); + }); + it('should return a input stream from a deeper glob', function(done) { + var stream = gulp.src('./fixtures/**/*.dmc', { cwd: __dirname }); + var a = 0; + stream.on('error', done); + stream.on('data', function() { + ++a; }); + stream.on('end', function() { + expect(a).toEqual(2); + done(); + }); + }); - it('should return a file stream from a flat path', function(done) { - var a = 0; - var stream = gulp.src(join(__dirname, './fixtures/test.coffee')); - stream.on('error', done); - stream.on('data', function(file) { - ++a; - should.exist(file); - should.exist(file.path); - should.exist(file.contents); - join(file.path, '').should.equal(join(__dirname, './fixtures/test.coffee')); - String(file.contents).should.equal('this is a test'); - }); - stream.on('end', function() { - a.should.equal(1); - done(); - }); + it('should return a file stream from a flat path', function(done) { + var a = 0; + var stream = gulp.src(path.join(__dirname, './fixtures/test.coffee')); + stream.on('error', done); + stream.on('data', function(file) { + ++a; + expect(file).toExist(); + expect(file.path).toExist(); + expect(file.contents).toExist(); + expect(file.path).toEqual(path.join(__dirname, './fixtures/test.coffee')); + expect(file.contents).toEqual('this is a test'); + }); + stream.on('end', function() { + expect(a).toEqual(1); + done(); }); }); }); diff --git a/test/watch.js b/test/watch.js index d943944e9..0ac076d23 100644 --- a/test/watch.js +++ b/test/watch.js @@ -1,14 +1,15 @@ 'use strict'; +/* eslint-disable no-use-before-define */ + var fs = require('fs'); +var path = require('path'); -var gulp = require('../'); +var expect = require('expect'); var rimraf = require('rimraf'); var mkdirp = require('mkdirp'); -var path = require('path'); -var should = require('should'); -require('mocha'); +var gulp = require('../'); var outpath = path.join(__dirname, './out-fixtures'); @@ -19,187 +20,189 @@ function createTempFile(path) { } function updateTempFile(path) { - var gazeTimeout = 125; setTimeout(function() { fs.appendFileSync(path, ' changed'); - }, gazeTimeout); + }, 125); } -describe('gulp', function() { - describe('watch()', function() { - beforeEach(rimraf.bind(null, outpath)); - beforeEach(mkdirp.bind(null, outpath)); - afterEach(rimraf.bind(null, outpath)); - - it('should call the function when file changes: no options', function(done) { - var tempFile = path.join(outpath, 'watch-func.txt'); +describe('gulp.watch()', function() { + beforeEach(rimraf.bind(null, outpath)); + beforeEach(mkdirp.bind(null, outpath)); + afterEach(rimraf.bind(null, outpath)); - createTempFile(tempFile); + it('should call the function when file changes: no options', function(done) { + var tempFile = path.join(outpath, 'watch-func.txt'); - var watcher = gulp.watch(tempFile, function(cb) { - watcher.close(); - cb(); - done(); - }); + createTempFile(tempFile); - updateTempFile(tempFile); + var watcher = gulp.watch('watch-func.txt', { cwd: outpath }, function(cb) { + watcher.close(); + cb(); + done(); }); - it('should execute the gulp.parallel tasks', function(done) { - var tempFile = path.join(outpath, 'watch-func.txt'); - - createTempFile(tempFile); + updateTempFile(tempFile); + }); - gulp.task('test', function(cb) { - watcher.close(); - cb(); - done(); - }); + it('should execute the gulp.parallel tasks', function(done) { + var tempFile = path.join(outpath, 'watch-func.txt'); - var watcher = gulp.watch(tempFile, gulp.parallel('test')); + createTempFile(tempFile); - updateTempFile(tempFile); + gulp.task('test', function(cb) { + watcher.close(); + cb(); + done(); }); - it('should work with destructuring', function(done) { - var tempFile = path.join(outpath, 'watch-func.txt'); - var watch = gulp.watch; - var parallel = gulp.parallel; - var task = gulp.task; - createTempFile(tempFile); + var watcher = gulp.watch('watch-func.txt', { cwd: outpath }, gulp.parallel('test')); - task('test', function(cb) { - watcher.close(); - cb(); - done(); - }); - - var watcher = watch(tempFile, parallel('test')); + updateTempFile(tempFile); + }); - updateTempFile(tempFile); + it('should work with destructuring', function(done) { + var tempFile = path.join(outpath, 'watch-func.txt'); + var watch = gulp.watch; + var parallel = gulp.parallel; + var task = gulp.task; + createTempFile(tempFile); + + task('test', function(cb) { + watcher.close(); + cb(); + done(); }); - it('should not call the function when no file changes: no options', function(done) { - var tempFile = path.join(outpath, 'watch-func.txt'); - - createTempFile(tempFile); + var watcher = watch('watch-func.txt', { cwd: outpath }, parallel('test')); - var watcher = gulp.watch(tempFile, function() { - should.fail('Watcher erroneously called'); - }); - - setTimeout(function() { - watcher.close(); - done(); - }, 10); - }); - - it('should call the function when file changes: w/ options', function(done) { - var tempFile = path.join(outpath, 'watch-func-options.txt'); + updateTempFile(tempFile); + }); - createTempFile(tempFile); + it('should not call the function when no file changes: no options', function(done) { + var tempFile = path.join(outpath, 'watch-func.txt'); - var watcher = gulp.watch(tempFile, function(cb) { - watcher.close(); - cb(); - done(); - }); + createTempFile(tempFile); - updateTempFile(tempFile); + var watcher = gulp.watch('watch-func.txt', { cwd: outpath }, function() { + // TODO: proper fail here + expect('Watcher erroneously called'); }); - it('should not drop options when no callback specified', function(done) { - var tempFile = path.join(outpath, 'watch-func-nodrop-options.txt'); - // By passing a cwd option, ensure options are not lost to gaze - var relFile = '../watch-func-nodrop-options.txt'; - var cwd = outpath + '/subdir'; + setTimeout(function() { + watcher.close(); + done(); + }, 10); + }); - createTempFile(tempFile); + it('should call the function when file changes: w/ options', function(done) { + var tempFile = path.join(outpath, 'watch-func-options.txt'); - var watcher = gulp.watch(relFile, {cwd: cwd}) - .on('change', function(filepath) { - should.exist(filepath); - path.resolve(cwd, filepath).should.equal(path.resolve(tempFile)); - watcher.close(); - done(); - }); + createTempFile(tempFile); - updateTempFile(tempFile); + var watcher = gulp.watch('watch-func-options.txt', { cwd: outpath }, function(cb) { + watcher.close(); + cb(); + done(); }); - it('should work without options or callback', function() { - gulp.watch('x'); - }); + updateTempFile(tempFile); + }); - it('should run many tasks: w/ options', function(done) { - var tempFile = path.join(outpath, 'watch-task-options.txt'); - var a = 0; + it('should not drop options when no callback specified', function(done) { + var tempFile = path.join(outpath, 'watch-func-nodrop-options.txt'); + // By passing a cwd option, ensure options are not lost to gaze + var relFile = '../watch-func-nodrop-options.txt'; + var cwd = path.join(outpath, '/subdir'); - createTempFile(tempFile); + createTempFile(tempFile); - gulp.task('task1', function(cb) { - a++; - cb(); - }); - gulp.task('task2', function(cb) { - a += 10; - a.should.equal(11); + var watcher = gulp.watch(relFile, { cwd: cwd }) + .on('change', function(filepath) { + expect(filepath).toExist(); + expect(path.resolve(cwd, filepath)).toEqual(path.resolve(tempFile)); watcher.close(); - cb(); done(); }); - var watcher = gulp.watch(tempFile, gulp.series('task1', 'task2')); + updateTempFile(tempFile); + }); - updateTempFile(tempFile); - }); + it('should work without options or callback', function(done) { + // TODO: check we return watcher? + gulp.watch('x'); + done(); + }); - it('should run many tasks: no options', function(done) { - var tempFile = path.join(outpath, 'watch-many-tasks-no-options.txt'); - var a = 0; + it('should run many tasks: w/ options', function(done) { + var tempFile = path.join(outpath, 'watch-task-options.txt'); + var a = 0; - createTempFile(tempFile); + createTempFile(tempFile); - gulp.task('task1', function(cb) { - a++; - cb(); - }); - gulp.task('task2', function(cb) { - a += 10; - a.should.equal(11); - watcher.close(); - cb(); - done(); - }); + gulp.task('task1', function(cb) { + a++; + cb(); + }); + gulp.task('task2', function(cb) { + a += 10; + expect(a).toEqual(11); + watcher.close(); + cb(); + done(); + }); - var watcher = gulp.watch(tempFile, gulp.series('task1', 'task2')); + var watcher = gulp.watch('watch-task-options.txt', { cwd: outpath }, gulp.series('task1', 'task2')); - updateTempFile(tempFile); - }); + updateTempFile(tempFile); + }); - it('should throw an error: passed parameter (string) is not a function', function(done) { - var tempFile = path.join(outpath, 'empty.txt'); + it('should run many tasks: no options', function(done) { + var tempFile = path.join(outpath, 'watch-many-tasks-no-options.txt'); + var a = 0; - createTempFile(tempFile); - try { - gulp.watch(tempFile, 'task1'); - } catch (err) { - err.message.should.equal('watching ' + tempFile + ': watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)'); - done(); - } + createTempFile(tempFile); + + gulp.task('task1', function(cb) { + a++; + cb(); + }); + gulp.task('task2', function(cb) { + a += 10; + expect(a).toEqual(11); + watcher.close(); + cb(); + done(); }); - it('should throw an error: passed parameter (array) is not a function', function(done) { - var tempFile = path.join(outpath, 'empty.txt'); + var watcher = gulp.watch('./test/out-fixtures/watch-many-tasks-no-options.txt', gulp.series('task1', 'task2')); - createTempFile(tempFile); - try { - gulp.watch(tempFile, ['task1']); - } catch (err) { - err.message.should.equal('watching ' + tempFile + ': watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)'); - done(); - } - }); + updateTempFile(tempFile); + }); + it('should throw an error: passed parameter (string) is not a function', function(done) { + var filename = 'empty.txt'; + var tempFile = path.join(outpath, filename); + + createTempFile(tempFile); + try { + gulp.watch(filename, { cwd: outpath }, 'task1'); + } catch (err) { + expect(err.message).toEqual('watching ' + filename + ': watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)'); + done(); + } }); + + it('should throw an error: passed parameter (array) is not a function', function(done) { + var filename = 'empty.txt'; + var tempFile = path.join(outpath, filename); + + createTempFile(tempFile); + try { + gulp.watch(filename, { cwd: outpath }, ['task1']); + } catch (err) { + expect(err.message).toEqual('watching ' + filename + ': watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)'); + done(); + } + }); + });