diff --git a/.ci/.azure-pipelines-steps.yml b/.ci/.azure-pipelines-steps.yml deleted file mode 100644 index 894c21eee..000000000 --- a/.ci/.azure-pipelines-steps.yml +++ /dev/null @@ -1,38 +0,0 @@ -steps: -- script: npm i -g npm@$(npm_version) - displayName: Use legacy npm version $(npm_version) - condition: ne(variables['npm_version'], '') - -- task: NodeTool@0 - inputs: - versionSpec: '$(node_version)' - displayName: Use Node $(node_version) - -- script: npm install - displayName: npm install - -- script: npm test - displayName: Run tests - -- script: npm run coveralls - displayName: Run coveralls - env: - # Pretend to be AppVeyor for now - APPVEYOR: true - APPVEYOR_BUILD_NUMBER: $(Build.BuildNumber) - APPVEYOR_BUILD_ID: $(Agent.OS)_$(node_version) - APPVEYOR_REPO_COMMIT: $(Build.SourceVersion) - APPVEYOR_REPO_BRANCH: $(Build.SourceBranchName) - # Overwrite the AppVeyor Service Name - COVERALLS_SERVICE_NAME: Azure Pipelines - COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) - COVERALLS_PARALLEL: true - CI_PULL_REQUEST: $(System.PullRequest.PullRequestNumber) - -- script: npm run azure-pipelines - displayName: Write tests to xml - -- task: PublishTestResults@2 - inputs: - testResultsFiles: '**/test.xunit' - condition: succeededOrFailed() diff --git a/.ci/.azure-pipelines.yml b/.ci/.azure-pipelines.yml deleted file mode 100644 index 2d717af1b..000000000 --- a/.ci/.azure-pipelines.yml +++ /dev/null @@ -1,90 +0,0 @@ -trigger: -- master -- releases/* - -jobs: - - job: Test_Linux - displayName: Run Tests on Linux - pool: - vmImage: "Ubuntu 16.04" - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - Node_v6: - node_version: 6 - Node_v4: - node_version: 4 - Node_v0_12: - node_version: 0.12 - Node_v0_10: - node_version: 0.10 - steps: - - template: .azure-pipelines-steps.yml - - - job: Test_Windows - displayName: Run Tests on Windows - pool: - vmImage: vs2017-win2016 - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - Node_v6: - node_version: 6 - Node_v4: - node_version: 4 - npm_version: 2 - Node_v0_12: - node_version: 0.12 - npm_version: 2 - Node_v0_10: - node_version: 0.10 - npm_version: 2 - steps: - - template: .azure-pipelines-steps.yml - - - job: Test_MacOS - displayName: Run Tests on MacOS - pool: - vmImage: macos-10.13 - strategy: - matrix: - Node_v12: - node_version: 12 - Node_v10: - node_version: 10 - Node_v8: - node_version: 8 - Node_v6: - node_version: 6 - Node_v4: - node_version: 4 - Node_v0_12: - node_version: 0.12 - Node_v0_10: - node_version: 0.10 - steps: - - template: .azure-pipelines-steps.yml - - - job: Notify_Coveralls - displayName: Notify Coveralls that the parallel report is done - pool: - vmImage: "Ubuntu 16.04" - dependsOn: - - Test_Linux - - Test_Windows - - Test_MacOS - steps: - - script: curl -k https://coveralls.io/webhook?repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$BUILD_NAME&payload[status]=done" - env: - COVERALLS_REPO_TOKEN: $(COVERALLS_REPO_TOKEN_SECRET) - BUILD_NAME: $(Build.BuildNumber) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 000000000..3b07263a5 --- /dev/null +++ b/.github/workflows/dev.yml @@ -0,0 +1,75 @@ +name: dev +on: + pull_request: + push: + branches: + - master + - main +env: + CI: true + +jobs: + prettier: + name: Format code + runs-on: ubuntu-latest + if: ${{ github.event_name == 'push' }} + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Prettier + uses: gulpjs/prettier_action@v3.0 + with: + commit_message: 'chore: Run prettier' + prettier_options: '--write .' + + test: + name: Tests for Node ${{ matrix.node }} on ${{ matrix.os }} + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + node: [10, 12, 14, 16] + os: [ubuntu-latest, windows-latest, macos-latest] + + steps: + - name: Clone repository + uses: actions/checkout@v2 + + - name: Set Node.js version + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + + - run: node --version + - run: npm --version + + - name: Install npm dependencies + run: npm install + + - name: Run lint + run: npm run lint + + - name: Run tests + run: npm test + + - name: Coveralls + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + flag-name: ${{matrix.os}}-node-${{ matrix.node }} + parallel: true + + coveralls: + needs: test + name: Finish up + + runs-on: ubuntu-latest + steps: + - name: Coveralls Finished + uses: coverallsapp/github-action@v1.1.2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..87cd13c01 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,16 @@ +name: release +on: + push: + branches: + - master + - main + +jobs: + release-please: + runs-on: ubuntu-latest + steps: + - uses: GoogleCloudPlatform/release-please-action@v2 + with: + token: ${{ secrets.GITHUB_TOKEN }} + release-type: node + package-name: release-please-action diff --git a/.npmrc b/.npmrc new file mode 100644 index 000000000..43c97e719 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 000000000..c96ebe0c9 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +coverage/ +.nyc_output/ +CHANGELOG.md diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index eda5b0009..000000000 --- a/.travis.yml +++ /dev/null @@ -1,12 +0,0 @@ -sudo: false -language: node_js -node_js: - - '12' - - '10' - - '8' - - '6' - - '4' - - '0.12' - - '0.10' -after_script: - - npm run coveralls diff --git a/LICENSE b/LICENSE index 6a29df97f..7980c1d40 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013-2018 Blaine Bublitz , Eric Schoffstall and other contributors +Copyright (c) 2013-2024 Blaine Bublitz and Eric Schoffstall Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 162f1bee5..b8b66b504 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@

The streaming build system

-[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![OpenCollective Backers][backer-badge]][backer-url] [![OpenCollective Sponsors][sponsor-badge]][sponsor-url] [![Gitter chat][gitter-image]][gitter-url] - +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coveralls Status][coveralls-image]][coveralls-url] ## What is gulp? @@ -15,25 +14,6 @@ - **Strong Ecosystem** - Use npm modules to do anything you want + over 3000 curated plugins for streaming file transformations. - **Simple** - By providing only a minimal API surface, gulp is easy to learn and simple to use. -## What's new in 4.0?! - -* The task system was rewritten from the ground-up, allowing task composition using `series()` and `parallel()` methods. -* The watcher was updated, now using chokidar (no more need for gulp-watch!), with feature parity to our task system. -* First-class support was added for incremental builds using `lastRun()`. -* A `symlink()` method was exposed to create symlinks instead of copying files. -* Built-in support for sourcemaps was added - the gulp-sourcemaps plugin is no longer necessary! -* Task registration of exported functions - using node or ES exports - is now recommended. -* Custom registries were designed, allowing for shared tasks or augmented functionality. -* Stream implementations were improved, allowing for better conditional and phased builds. - - -## gulp for enterprise - -Available as part of the Tidelift Subscription - -The maintainers of gulp and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-gulp?utm_source=npm-gulp&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - - ## Installation Follow our [Quick Start guide][quick-start]. @@ -246,48 +226,21 @@ for a second time. Anyone can help make this project better - check out our [Contributing guide](/CONTRIBUTING.md)! -## Backers - -Support us with a monthly donation and help us continue our activities. - -[![Backers][backers-image]][support-url] - -## Sponsors - -Become a sponsor to get your logo on our README on Github. - -[![Sponsors][sponsors-image]][support-url] + +[quick-start]: https://gulpjs.com/docs/en/getting-started/quick-start +[getting-started-guide]: https://gulpjs.com/docs/en/getting-started/quick-start +[api-docs]: https://gulpjs.com/docs/en/api/concepts +[esm-module]: https://github.com/standard-things/esm + -[downloads-image]: https://img.shields.io/npm/dm/gulp.svg + +[downloads-image]: https://img.shields.io/npm/dm/gulp.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/gulp -[npm-image]: https://img.shields.io/npm/v/gulp.svg - -[azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=1&branchName=master -[azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/gulp?branchName=master +[npm-image]: https://img.shields.io/npm/v/gulp.svg?style=flat-square -[travis-url]: https://travis-ci.org/gulpjs/gulp -[travis-image]: https://img.shields.io/travis/gulpjs/gulp.svg?label=travis-ci - -[appveyor-url]: https://ci.appveyor.com/project/gulpjs/gulp -[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/gulp.svg?label=appveyor +[ci-url]: https://github.com/gulpjs/gulp/actions?query=workflow:dev +[ci-image]: https://img.shields.io/github/actions/workflow/status/gulpjs/gulp/dev.yml?branch=master&style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/gulp -[coveralls-image]: https://img.shields.io/coveralls/gulpjs/gulp/master.svg - -[gitter-url]: https://gitter.im/gulpjs/gulp -[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg - -[backer-url]: #backers -[backer-badge]: https://opencollective.com/gulpjs/backers/badge.svg?color=blue -[sponsor-url]: #sponsors -[sponsor-badge]: https://opencollective.com/gulpjs/sponsors/badge.svg?color=blue - -[support-url]: https://opencollective.com/gulpjs#support - -[backers-image]: https://opencollective.com/gulpjs/backers.svg -[sponsors-image]: https://opencollective.com/gulpjs/sponsors.svg - -[quick-start]: https://gulpjs.com/docs/en/getting-started/quick-start -[getting-started-guide]: https://gulpjs.com/docs/en/getting-started/quick-start -[api-docs]: https://gulpjs.com/docs/en/api/concepts -[esm-module]: https://github.com/standard-things/esm +[coveralls-image]: https://img.shields.io/coveralls/gulpjs/gulp/master.svg?style=flat-square + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index d8845d71e..000000000 --- a/appveyor.yml +++ /dev/null @@ -1,26 +0,0 @@ -# https://www.appveyor.com/docs/appveyor-yml -# https://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" - - nodejs_version: "10" - -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 256684af3..b335a1340 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ "repository": "gulpjs/gulp", "license": "MIT", "engines": { - "node": ">= 0.10" + "node": ">=10.13.0" }, "main": "index.js", "files": [ @@ -25,25 +25,32 @@ "scripts": { "lint": "eslint .", "pretest": "npm run lint", - "test": "nyc mocha --async-only", - "azure-pipelines": "nyc mocha --async-only --reporter xunit -O output=test.xunit", - "coveralls": "nyc report --reporter=text-lcov | coveralls" + "test": "nyc mocha --async-only" }, "dependencies": { - "glob-watcher": "^5.0.3", - "gulp-cli": "^2.2.0", - "undertaker": "^1.2.1", - "vinyl-fs": "^3.0.0" + "glob-watcher": "^6.0.0", + "gulp-cli": "^3.0.0", + "undertaker": "^2.0.0", + "vinyl-fs": "^4.0.0" }, "devDependencies": { - "coveralls": "github:phated/node-coveralls#2.x", - "eslint": "^2.13.1", - "eslint-config-gulp": "^3.0.1", - "expect": "^1.20.2", - "mkdirp": "^0.5.1", - "mocha": "^3.0.0", - "nyc": "^10.3.2", - "rimraf": "^2.6.3" + "eslint": "^7.0.0", + "eslint-config-gulp": "^5.0.0", + "eslint-plugin-node": "^11.1.0", + "expect": "^27.0.0", + "mkdirp": "^3.0.1", + "mocha": "^8.0.0", + "nyc": "^15.0.0", + "rimraf": "^3.0.0" + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] + }, + "prettier": { + "singleQuote": true }, "keywords": [ "build", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 06b940f7d..000000000 --- a/test/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "gulp/test" -} diff --git a/test/.gitkeep b/test/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/test/dest.js b/test/dest.js index 3dbba4600..16c58d213 100644 --- a/test/dest.js +++ b/test/dest.js @@ -16,8 +16,8 @@ describe('gulp.dest()', function() { it('should return a stream', function(done) { var stream = gulp.dest(path.join(__dirname, './fixtures/')); - expect(stream).toExist(); - expect(stream.on).toExist(); + expect(stream).toBeDefined(); + expect(stream.on).toBeDefined(); done(); }); @@ -26,20 +26,22 @@ describe('gulp.dest()', function() { var outstream = gulp.dest(outpath); instream.pipe(outstream); + var expectedContents = Buffer.from('this is a test'); + 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).toBeDefined(); + expect(file.path).toBeDefined(); + expect(file.contents).toBeDefined(); expect(file.path).toEqual(path.join(outpath, './copy/example.txt')); - expect(file.contents).toEqual('this is a test'); + expect(file.contents).toEqual(expectedContents); }); 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'); + expect(err).toBeNull(); + expect(contents).toBeDefined(); + expect(contents).toEqual(expectedContents); done(); }); }); @@ -53,15 +55,15 @@ describe('gulp.dest()', function() { 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).toBeDefined(); + expect(file.path).toBeDefined(); + expect(file.contents).toBeNull(); 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(); + expect(err).toBeDefined(); + expect(contents).toBeUndefined(); done(); }); }); @@ -74,16 +76,16 @@ describe('gulp.dest()', function() { 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).toBeDefined(); + expect(file.path).toBeDefined(); + expect(file.contents).toBeDefined(); 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'); + expect(err).toBeNull(); + expect(contents).toBeDefined(); + expect(contents).toEqual(Buffer.from('this is a test')); done(); }); }); @@ -112,13 +114,13 @@ describe('gulp.dest()', function() { outstream.on('error', done); outstream.on('data', function(file) { // Data should be re-emitted right - expect(file).toExist(); - expect(file.path).toExist(); + expect(file).toBeDefined(); + expect(file.path).toBeDefined(); expect(file.path).toEqual(path.join(outpath, './stuff')); }); outstream.on('end', function() { fs.exists(path.join(outpath, 'stuff'), function(exists) { - expect(exists).toExist(); + expect(exists).toBeDefined(); done(); }); }); diff --git a/test/fixtures/gulpfiles/cjs/gulpfile.cjs b/test/fixtures/gulpfiles/cjs/gulpfile.cjs new file mode 100644 index 000000000..b7e1a2d35 --- /dev/null +++ b/test/fixtures/gulpfiles/cjs/gulpfile.cjs @@ -0,0 +1,3 @@ +exports.default = function (done) { + done() +} diff --git a/test/index.test.js b/test/index.test.js index 8921084d8..0e8b65fb0 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,5 +1,8 @@ 'use strict'; +var cp = require('child_process'); +var path = require('path'); + var expect = require('expect'); var gulp = require('../'); @@ -8,52 +11,65 @@ describe('gulp', function() { describe('hasOwnProperty', function() { it('src', function(done) { - expect(gulp.hasOwnProperty('src')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'src')).toEqual(true); done(); }); it('dest', function(done) { - expect(gulp.hasOwnProperty('dest')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'dest')).toEqual(true); done(); }); it('symlink', function(done) { - expect(gulp.hasOwnProperty('symlink')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'symlink')).toEqual(true); done(); }); it('watch', function(done) { - expect(gulp.hasOwnProperty('watch')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'watch')).toEqual(true); done(); }); it('task', function(done) { - expect(gulp.hasOwnProperty('task')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'task')).toEqual(true); done(); }); it('series', function(done) { - expect(gulp.hasOwnProperty('series')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'series')).toEqual(true); done(); }); it('parallel', function(done) { - expect(gulp.hasOwnProperty('parallel')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'parallel')).toEqual(true); done(); }); it('tree', function(done) { - expect(gulp.hasOwnProperty('tree')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'tree')).toEqual(true); done(); }); it('lastRun', function(done) { - expect(gulp.hasOwnProperty('lastRun')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'lastRun')).toEqual(true); done(); }); it('registry', function(done) { - expect(gulp.hasOwnProperty('registry')).toEqual(true); + expect(Object.prototype.hasOwnProperty.call(gulp, 'registry')).toEqual(true); + done(); + }); + }); + + it('can run against gulpfile.cjs', function (done) { + this.timeout(5000); + + var cli = path.join(__dirname, '../bin/gulp.js'); + var opts = { cwd: path.join(__dirname, 'fixtures/gulpfiles/cjs' ) }; + cp.exec('node ' + cli, opts, function (err, stdout, stderr) { + expect(err).toBeNull(); + expect(stdout).toMatch('gulpfile.cjs'); + expect(stderr).toEqual(''); done(); }); }); diff --git a/test/src.js b/test/src.js index 4ec1df962..82501e73e 100644 --- a/test/src.js +++ b/test/src.js @@ -9,19 +9,20 @@ 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(); + expect(stream).toBeDefined(); + expect(stream.on).toBeDefined(); 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).toBeDefined(); + expect(file.path).toBeDefined(); + expect(file.contents).toBeDefined(); expect(file.path).toEqual(path.join(__dirname, './fixtures/test.coffee')); - expect(file.contents).toEqual('this is a test'); + expect(file.contents).toEqual(Buffer.from('this is a test')); }); stream.on('end', function() { done(); @@ -38,8 +39,8 @@ describe('gulp.src()', function() { var files = []; stream.on('error', done); stream.on('data', function(file) { - expect(file).toExist(); - expect(file.path).toExist(); + expect(file).toBeDefined(); + expect(file.path).toBeDefined(); files.push(file); }); stream.on('end', function() { @@ -61,8 +62,8 @@ describe('gulp.src()', function() { var files = []; stream.on('error', done); stream.on('data', function(file) { - expect(file).toExist(); - expect(file.path).toExist(); + expect(file).toBeDefined(); + expect(file.path).toBeDefined(); files.push(file); }); stream.on('end', function() { @@ -76,22 +77,23 @@ describe('gulp.src()', function() { 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).toBeDefined(); + expect(file.path).toBeDefined(); + expect(file.contents).toBeNull(); expect(file.path).toEqual(path.join(__dirname, './fixtures/test.coffee')); }); stream.on('end', function() { done(); }); }); + 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(); + expect(file).toBeDefined(); + expect(file.path).toBeDefined(); + expect(file.contents).toBeDefined(); var buf = ''; file.contents.on('data', function(d) { buf += d; @@ -103,20 +105,22 @@ describe('gulp.src()', function() { expect(file.path).toEqual(path.join(__dirname, './fixtures/test.coffee')); }); }); + 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).toBeDefined(); + expect(file.path).toBeDefined(); + expect(file.contents).toBeDefined(); expect(file.path).toEqual(path.join(__dirname, './fixtures/test/run.jade')); - expect(file.contents).toEqual('test template'); + expect(file.contents).toEqual(Buffer.from('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; @@ -136,11 +140,11 @@ describe('gulp.src()', function() { stream.on('error', done); stream.on('data', function(file) { ++a; - expect(file).toExist(); - expect(file.path).toExist(); - expect(file.contents).toExist(); + expect(file).toBeDefined(); + expect(file.path).toBeDefined(); + expect(file.contents).toBeDefined(); expect(file.path).toEqual(path.join(__dirname, './fixtures/test.coffee')); - expect(file.contents).toEqual('this is a test'); + expect(file.contents).toEqual(Buffer.from('this is a test')); }); stream.on('end', function() { expect(a).toEqual(1); diff --git a/test/watch.js b/test/watch.js index 0ac076d23..eab1ec011 100644 --- a/test/watch.js +++ b/test/watch.js @@ -7,7 +7,7 @@ var path = require('path'); var expect = require('expect'); var rimraf = require('rimraf'); -var mkdirp = require('mkdirp'); +var mkdirp = require('mkdirp').mkdirp; var gulp = require('../'); @@ -25,10 +25,22 @@ function updateTempFile(path) { }, 125); } +function removeTempFile(path) { + setTimeout(function() { + fs.unlinkSync(path); + }, 125); +} + describe('gulp.watch()', function() { - beforeEach(rimraf.bind(null, outpath)); - beforeEach(mkdirp.bind(null, outpath)); - afterEach(rimraf.bind(null, outpath)); + beforeEach(function (done) { + rimraf(outpath, done); + }); + beforeEach(function () { + return mkdirp(outpath); + }); + afterEach(function (done) { + rimraf(outpath, done); + }); it('should call the function when file changes: no options', function(done) { var tempFile = path.join(outpath, 'watch-func.txt'); @@ -83,15 +95,18 @@ describe('gulp.watch()', function() { createTempFile(tempFile); - var watcher = gulp.watch('watch-func.txt', { cwd: outpath }, function() { - // TODO: proper fail here - expect('Watcher erroneously called'); - }); - setTimeout(function() { - watcher.close(); - done(); - }, 10); + // Chokidar seems to pick up the file we just created, so we wait briefly before setup + // I wonder if node hasn't fully flushed the file or something... + var watcher = gulp.watch('watch-func.txt', { cwd: outpath }, function() { + done(new Error('should not each here!')); + }); + + setTimeout(function () { + watcher.close(); + done(); + }, 1000); + }, 250); }); it('should call the function when file changes: w/ options', function(done) { @@ -108,6 +123,40 @@ describe('gulp.watch()', function() { updateTempFile(tempFile); }); + it('should call the function when file changes at a path with japanese characters', function(done) { + var japaneseDir = path.join(outpath, 'フォルダ'); + + fs.mkdirSync(japaneseDir); + + var tempFile = path.join(japaneseDir, 'foobar.txt'); + + createTempFile(tempFile); + + var watcher = gulp.watch('フォルダ/*', { cwd: outpath }, function(cb) { + watcher.close(); + cb(); + done(); + }); + + updateTempFile(tempFile); + }); + + it('should not call the function when ignored file changes', function(done) { + var tempFile = path.join(outpath, 'ignored.txt'); + + createTempFile(tempFile); + + var watcher = gulp.watch(['*', '!ignored.txt'], { cwd: outpath }, function() { + done(new Error('should not each here!')); + }); + + removeTempFile(tempFile); + setTimeout(function () { + watcher.close(); + done(); + }, 1000); + }); + 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 @@ -118,7 +167,7 @@ describe('gulp.watch()', function() { var watcher = gulp.watch(relFile, { cwd: cwd }) .on('change', function(filepath) { - expect(filepath).toExist(); + expect(filepath).toBeDefined(); expect(path.resolve(cwd, filepath)).toEqual(path.resolve(tempFile)); watcher.close(); done(); @@ -128,8 +177,8 @@ describe('gulp.watch()', function() { }); it('should work without options or callback', function(done) { - // TODO: check we return watcher? - gulp.watch('x'); + var watcher = gulp.watch('x'); + watcher.close(); done(); });