diff --git a/.ci/.azure-pipelines-steps.yml b/.ci/.azure-pipelines-steps.yml deleted file mode 100644 index 894c21e..0000000 --- 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 2d717af..0000000 --- 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/.editorconfig b/.editorconfig index e000b0c..e7b73a7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,4 +1,4 @@ -# http://editorconfig.org +# https://editorconfig.org root = true [*] diff --git a/.eslintignore b/.eslintignore index 33ed5c0..722de04 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,3 @@ +coverage/ test/fixtures/out test/fixtures/tmp diff --git a/.github/support.yml b/.github/support.yml deleted file mode 100644 index 3ee3d22..0000000 --- a/.github/support.yml +++ /dev/null @@ -1,2 +0,0 @@ -# Configuration for support-requests - https://github.com/dessant/support-requests -_extends: gulp diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml new file mode 100644 index 0000000..3b07263 --- /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 0000000..87cd13c --- /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/.gitignore b/.gitignore index 58a757a..aa0c563 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,7 @@ coverage # nyc test coverage .nyc_output -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) .grunt # Bower dependency directory (https://bower.io/) diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..c96ebe0 --- /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 eda5b00..0000000 --- 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 0b2955a..4e03626 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Blaine Bublitz, Eric Schoffstall and other contributors +Copyright (c) 2014, 2016-2020, 2022 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 8855ddd..4b79fca 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@

- +

# undertaker -[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Azure Pipelines Build Status][azure-pipelines-image]][azure-pipelines-url] [![Travis Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-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] + +Task registry that allows composition through series/parallel methods. ## Usage @@ -292,29 +294,23 @@ taker.task('default', taker.series('clean', 'build', 'serve', function(cb) { MIT -[downloads-image]: https://img.shields.io/npm/dm/undertaker.svg + +[downloads-image]: https://img.shields.io/npm/dm/undertaker.svg?style=flat-square [npm-url]: https://www.npmjs.com/package/undertaker -[npm-image]: https://img.shields.io/npm/v/undertaker.svg - -[azure-pipelines-url]: https://dev.azure.com/gulpjs/gulp/_build/latest?definitionId=$PROJECT_ID&branchName=master -[azure-pipelines-image]: https://dev.azure.com/gulpjs/gulp/_apis/build/status/undertaker?branchName=master +[npm-image]: https://img.shields.io/npm/v/undertaker.svg?style=flat-square -[travis-url]: https://travis-ci.org/gulpjs/undertaker -[travis-image]: https://img.shields.io/travis/gulpjs/undertaker.svg?label=travis-ci - -[appveyor-url]: https://ci.appveyor.com/project/gulpjs/undertaker -[appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/undertaker.svg?label=appveyor +[ci-url]: https://github.com/gulpjs/undertaker/actions?query=workflow:dev +[ci-image]: https://img.shields.io/github/workflow/status/gulpjs/undertaker/dev?style=flat-square [coveralls-url]: https://coveralls.io/r/gulpjs/undertaker -[coveralls-image]: https://img.shields.io/coveralls/gulpjs/undertaker/master.svg - -[gitter-url]: https://gitter.im/gulpjs/gulp -[gitter-image]: https://badges.gitter.im/gulpjs/gulp.svg +[coveralls-image]: https://img.shields.io/coveralls/gulpjs/undertaker/master.svg?style=flat-square + -[custom-registries]: #custom-registries + [async-resolution]: https://github.com/phated/async-done#completion-and-error-resolution -[archy]: https://www.npmjs.org/package/archy [undertaker-registry]: https://github.com/gulpjs/undertaker-registry +[custom-registries]: #custom-registries +[archy]: https://www.npmjs.org/package/archy [undertaker-forward-reference]: https://github.com/gulpjs/undertaker-forward-reference [undertaker-task-metadata]: https://github.com/gulpjs/undertaker-task-metadata [undertaker-common-tasks]: https://github.com/gulpjs/undertaker-common-tasks @@ -322,3 +318,4 @@ MIT [gulp-hub]: https://github.com/frankwallis/gulp-hub/tree/registry-init [gulp-pipeline]: https://github.com/alienfast/gulp-pipeline [rails-registry]: https://github.com/alienfast/gulp-pipeline/blob/master/src/registry/railsRegistry.js + diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 47b3ca2..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,32 +0,0 @@ -# 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" - - nodejs_version: "10" - - nodejs_version: "12" - -platform: - - x86 - - x64 - -install: - # https://www.appveyor.com/docs/lang/nodejs-iojs/#installing-any-version-of-nodejs-or-iojs - - ps: Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version) $env:PLATFORM - - npm install - -test_script: - - node --version - - npm --version - - cmd: npm test - -build: off - -# build version format -version: "{build}" diff --git a/lib/helpers/buildTree.js b/lib/helpers/buildTree.js index dbc3aaf..001bac9 100644 --- a/lib/helpers/buildTree.js +++ b/lib/helpers/buildTree.js @@ -1,11 +1,9 @@ 'use strict'; -var map = require('collection-map'); - var metadata = require('./metadata'); function buildTree(tasks) { - return map(tasks, function(task) { + return Object.values(tasks).map(function(task) { var meta = metadata.get(task); if (meta) { return meta.tree; diff --git a/lib/helpers/metadata.js b/lib/helpers/metadata.js index 1e3dc9e..b27378e 100644 --- a/lib/helpers/metadata.js +++ b/lib/helpers/metadata.js @@ -1,7 +1,5 @@ 'use strict'; -// WeakMap for storing metadata -var WM = require('es6-weak-map'); -var metadata = new WM(); +var metadata = new WeakMap(); module.exports = metadata; diff --git a/lib/helpers/normalizeArgs.js b/lib/helpers/normalizeArgs.js index 3f9e339..49f63e0 100644 --- a/lib/helpers/normalizeArgs.js +++ b/lib/helpers/normalizeArgs.js @@ -2,8 +2,6 @@ var assert = require('assert'); -var map = require('arr-map'); -var flatten = require('arr-flatten'); var levenshtein = require('fast-levenshtein'); function normalizeArgs(registry, args) { @@ -24,10 +22,10 @@ function normalizeArgs(registry, args) { return fn; } - var flattenArgs = flatten(args); + var flattenArgs = Array.prototype.concat.apply([], args); assert(flattenArgs.length, 'One or more tasks should be combined using series or parallel'); - return map(flattenArgs, getFunction); + return flattenArgs.map(getFunction); } function similarTasks(registry, queryTask) { @@ -38,7 +36,7 @@ function similarTasks(registry, queryTask) { var tasks = registry.tasks(); var similarTasks = []; for (var task in tasks) { - if (tasks.hasOwnProperty(task)) { + if (Object.prototype.hasOwnProperty.call(tasks, task)) { var distance = levenshtein.get(task, queryTask); var allowedDistance = Math.floor(0.4 * task.length) + 1; if (distance < allowedDistance) { diff --git a/lib/registry.js b/lib/registry.js index d441232..49264fb 100644 --- a/lib/registry.js +++ b/lib/registry.js @@ -1,12 +1,12 @@ 'use strict'; -var reduce = require('object.reduce'); - var validateRegistry = require('./helpers/validateRegistry'); -function setTasks(inst, task, name) { - inst.set(name, task); - return inst; +function setTasks(registry, nameAndTask) { + var name = nameAndTask[0]; + var task = nameAndTask[1]; + registry.set(name, task); + return registry; } function registry(newRegistry) { @@ -18,7 +18,7 @@ function registry(newRegistry) { var tasks = this._registry.tasks(); - this._registry = reduce(tasks, setTasks, newRegistry); + this._registry = Object.entries(tasks).reduce(setTasks, newRegistry); this._registry.init(this); } diff --git a/lib/tree.js b/lib/tree.js index ed06364..171a17e 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -1,17 +1,12 @@ 'use strict'; -var defaults = require('object.defaults'); -var map = require('collection-map'); - var metadata = require('./helpers/metadata'); function tree(opts) { - opts = defaults(opts || {}, { - deep: false, - }); + opts = Object.assign({ deep: false }, opts); var tasks = this._registry.tasks(); - var nodes = map(tasks, function(task) { + var nodes = Object.values(tasks).map(function(task) { var meta = metadata.get(task); if (opts.deep) { diff --git a/package.json b/package.json index 94a13af..c2d89d0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "repository": "gulpjs/undertaker", "license": "MIT", "engines": { - "node": ">= 0.10" + "node": ">=10.13.0" }, "main": "index.js", "files": [ @@ -21,37 +21,37 @@ "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": { - "arr-flatten": "^1.0.1", - "arr-map": "^2.0.0", - "bach": "^1.0.0", - "collection-map": "^1.0.0", - "es6-weak-map": "^2.0.1", - "last-run": "^1.1.0", - "object.defaults": "^1.0.0", - "object.reduce": "^1.0.0", - "undertaker-registry": "^1.0.0", - "fast-levenshtein": "^1.0.0" + "bach": "^2.0.1", + "fast-levenshtein": "^3.0.0", + "last-run": "^2.0.0", + "undertaker-registry": "^2.0.0" }, "devDependencies": { - "async-once": "^1.0.0", - "coveralls": "github:phated/node-coveralls#2.x", - "del": "^2.0.2", - "eslint": "^2.13.1", - "eslint-config-gulp": "^3.0.1", - "expect": "^1.20.2", - "gulp-jshint": "^1.8.4", - "mocha": "^3.0.0", - "nyc": "^10.3.2", - "once": "^1.3.1", - "through2": "^2.0.0", - "undertaker-common-tasks": "^1.0.0", - "undertaker-task-metadata": "^1.0.0", - "vinyl-fs": "^2.2.0" + "async-once": "^2.0.0", + "del": "^6.1.1", + "eslint": "^7.32.0", + "eslint-config-gulp": "^5.0.1", + "eslint-plugin-node": "^11.1.0", + "expect": "^27.5.1", + "mocha": "^8.4.0", + "nyc": "^15.1.0", + "once": "^1.4.0", + "through2": "^4.0.2", + "undertaker-common-tasks": "^2.0.0", + "undertaker-task-metadata": "^2.0.0", + "vinyl-fs": "^4.0.0" + }, + "nyc": { + "reporter": [ + "lcov", + "text-summary" + ] + }, + "prettier": { + "singleQuote": true }, "keywords": [ "registry", diff --git a/test/.eslintrc b/test/.eslintrc deleted file mode 100644 index 06b940f..0000000 --- a/test/.eslintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "extends": "gulp/test" -} diff --git a/test/integration.js b/test/integration.js index 004651a..0a62135 100644 --- a/test/integration.js +++ b/test/integration.js @@ -6,7 +6,6 @@ var os = require('os'); var fs = require('fs'); var path = require('path'); var vinyl = require('vinyl-fs'); -var jshint = require('gulp-jshint'); var spawn = require('child_process').spawn; var once = require('once'); var aOnce = require('async-once'); @@ -55,10 +54,10 @@ describe('integrations', function() { taker.parallel('test')(done); }); - it('should lints all piped files', function(done) { + it('should handle a Transform stream return', function(done) { taker.task('test', function() { return vinyl.src('./fixtures/test.js', { cwd: __dirname }) - .pipe(jshint()); + .pipe(through.obj()); }); taker.parallel('test')(done); diff --git a/test/last-run.js b/test/last-run.js index 830f407..290a48c 100644 --- a/test/last-run.js +++ b/test/last-run.js @@ -54,10 +54,10 @@ describe('lastRun', function() { it('should record tasks time execution', function(done) { taker.parallel('test1')(function(err) { - expect(taker.lastRun('test1')).toExist(); - expect(taker.lastRun('test1')).toBeLessThanOrEqualTo(Date.now()); - expect(taker.lastRun(test2)).toNotExist(); - expect(taker.lastRun(function() {})).toNotExist(); + expect(taker.lastRun('test1')).toBeTruthy(); + expect(taker.lastRun('test1')).toBeLessThanOrEqual(Date.now()); + expect(taker.lastRun(test2)).toBeFalsy(); + expect(taker.lastRun(function() {})).toBeFalsy(); expect(taker.lastRun.bind(taker, 'notexists')).toThrow(Error); done(err); }); @@ -65,10 +65,10 @@ describe('lastRun', function() { it('should record all tasks time execution', function(done) { taker.parallel('test1', test2)(function(err) { - expect(taker.lastRun('test1')).toExist(); - expect(taker.lastRun('test1')).toBeLessThanOrEqualTo(Date.now()); - expect(taker.lastRun(test2)).toExist(); - expect(taker.lastRun(test2)).toBeLessThanOrEqualTo(Date.now()); + expect(taker.lastRun('test1')).toBeTruthy(); + expect(taker.lastRun('test1')).toBeLessThanOrEqual(Date.now()); + expect(taker.lastRun(test2)).toBeTruthy(); + expect(taker.lastRun(test2)).toBeLessThanOrEqual(Date.now()); done(err); }); }); @@ -103,8 +103,8 @@ describe('lastRun', function() { // To keep the test from catching the emitted errors }); taker.series('error')(function(err) { - expect(err).toExist(); - expect(taker.lastRun('error')).toNotExist(); + expect(err).toBeTruthy(); + expect(taker.lastRun('error')).toBeFalsy(); done(); }); }); diff --git a/test/parallel.js b/test/parallel.js index 628794a..f78bbc4 100644 --- a/test/parallel.js +++ b/test/parallel.js @@ -120,7 +120,7 @@ describe('parallel', function() { // To keep the test from catching the emitted errors }); taker.parallel('test1', 'error', 'test3')(function(err, results) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); expect(results).toEqual([1, undefined, undefined]); done(); }); @@ -141,7 +141,7 @@ describe('parallel', function() { }); taker._settle = true; taker.parallel(taker.parallel('test1', 'error'), 'test3')(function(err, results) { - expect(err[0][0]).toBeAn(Error); + expect(err[0][0]).toBeInstanceOf(Error); expect(results).toEqual([3]); done(); }); diff --git a/test/registry.js b/test/registry.js index a3a1c21..0dbeec8 100644 --- a/test/registry.js +++ b/test/registry.js @@ -30,6 +30,9 @@ SetNoReturnRegistry.prototype.tasks = noop; function InvalidRegistry() {} +function InvalidProtoRegistry() {} +InvalidProtoRegistry.prototype = InvalidRegistry; + describe('registry', function() { describe('method', function() { @@ -65,8 +68,8 @@ describe('registry', function() { var customRegistry = new DefaultRegistry(); taker.registry(customRegistry); - expect(taker.task('clean')).toBeA('function'); - expect(taker.task('serve')).toBeA('function'); + expect(typeof taker.task('clean')).toEqual('function'); + expect(typeof taker.task('serve')).toEqual('function'); done(); }); @@ -74,8 +77,8 @@ describe('registry', function() { var taker = new Undertaker(); taker.registry(new CommonRegistry()); - expect(taker.task('clean')).toBeA('function'); - expect(taker.task('serve')).toBeA('function'); + expect(typeof taker.task('clean')).toEqual('function'); + expect(typeof taker.task('serve')).toEqual('function'); taker.registry(new MetadataRegistry()); taker.task('context', function(cb) { @@ -86,9 +89,9 @@ describe('registry', function() { taker.registry(new DefaultRegistry()); - expect(taker.task('clean')).toBeA('function'); - expect(taker.task('serve')).toBeA('function'); - expect(taker.task('context')).toBeA('function'); + expect(typeof taker.task('clean')).toEqual('function'); + expect(typeof taker.task('serve')).toEqual('function'); + expect(typeof taker.task('context')).toEqual('function'); taker.series('context')(); }); @@ -111,8 +114,8 @@ describe('registry', function() { DefaultRegistry.prototype.init = function(inst) { expect(inst).toEqual(taker); - expect(inst.task('clean')).toBeA('function'); - expect(inst.task('serve')).toBeA('function'); + expect(typeof inst.task('clean')).toEqual('function'); + expect(typeof inst.task('serve')).toEqual('function'); }; taker.registry(new DefaultRegistry()); @@ -125,24 +128,32 @@ describe('registry', function() { describe('constructor', function() { it('should take a custom registry on instantiation', function(done) { var taker = new Undertaker(new CustomRegistry()); - expect(taker.registry()).toBeA(CustomRegistry); - expect(taker.registry()).toNotBeA(DefaultRegistry); + expect(taker.registry()).toBeInstanceOf(CustomRegistry); + expect(taker.registry()).not.toBeInstanceOf(DefaultRegistry); done(); }); it('should default to undertaker-registry if not constructed with custom registry', function(done) { var taker = new Undertaker(); - expect(taker.registry()).toBeA(DefaultRegistry); - expect(taker.registry()).toNotBeA(CustomRegistry); + expect(taker.registry()).toBeInstanceOf(DefaultRegistry); + expect(taker.registry()).not.toBeInstanceOf(CustomRegistry); done(); }); it('should take a registry that pre-defines tasks', function(done) { var taker = new Undertaker(new CommonRegistry()); - expect(taker.registry()).toBeA(CommonRegistry); - expect(taker.registry()).toBeA(DefaultRegistry); - expect(taker.task('clean')).toBeA('function'); - expect(taker.task('serve')).toBeA('function'); + expect(taker.registry()).toBeInstanceOf(CommonRegistry); + expect(taker.registry()).toBeInstanceOf(DefaultRegistry); + expect(typeof taker.task('clean')).toEqual('function'); + expect(typeof taker.task('serve')).toEqual('function'); + done(); + }); + + it('should throw upon invalid registry', function(done) { + var taker = new Undertaker(new CommonRegistry()); + expect(function() { + taker.registry(new InvalidProtoRegistry()); + }).toThrow('Custom registry must have `get` function'); done(); }); @@ -194,6 +205,28 @@ describe('registry', function() { taker.series('test')(); }); + it('should fail if task name is of an inherited property', function(done) { + var tasks = {}; + tasks.__proto__ = { notOwnProp: 1 } + + function MyRegistry() {} + MyRegistry.prototype.init = noop; + MyRegistry.prototype.get = noop; + MyRegistry.prototype.set = noop; + MyRegistry.prototype.tasks = function() { return tasks; }; + + var registry = new MyRegistry(); + var taker = new Undertaker(registry); + + function fail() { + taker.series('notOwnProp'); + } + + expect(fail).toThrow(/Task never defined: notOwnProp/); + + done(); + }); + it('should fail and offer tasks which are close in name', function(done) { var taker = new Undertaker(new CommonRegistry()); var customRegistry = new DefaultRegistry(); diff --git a/test/series.js b/test/series.js index d9b85fe..fce503f 100644 --- a/test/series.js +++ b/test/series.js @@ -120,7 +120,7 @@ describe('series', function() { // To keep the test from catching the emitted errors }); taker.series('test1', 'error', 'test3')(function(err, results) { - expect(err).toBeAn(Error); + expect(err).toBeInstanceOf(Error); expect(results).toEqual([1, undefined, undefined]); done(); }); @@ -141,7 +141,7 @@ describe('series', function() { }); taker._settle = true; taker.series(taker.series('test1', 'error'), 'test3')(function(err, results) { - expect(err[0][0]).toBeAn(Error); + expect(err[0][0]).toBeInstanceOf(Error); expect(results).toEqual([3]); done(); }); diff --git a/test/task.js b/test/task.js index 5350d70..51f19b5 100644 --- a/test/task.js +++ b/test/task.js @@ -67,14 +67,14 @@ describe('task', function() { it('should get the wrapped task, not original function', function(done) { var registry = taker.registry(); taker.task('test1', noop); - expect(taker.task('test1').unwrap).toBeA('function'); + expect(typeof taker.task('test1').unwrap).toEqual('function'); expect(taker.task('test1')).toEqual(registry.get('test1')); done(); }); it('provides an `unwrap` method to get the original function', function(done) { taker.task('test1', noop); - expect(taker.task('test1').unwrap).toBeA('function'); + expect(typeof taker.task('test1').unwrap).toEqual('function'); expect(taker.task('test1').unwrap()).toEqual(noop); done(); });