npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

task-tape

v1.2.2

Published

Tape with gulp async task support

Downloads

84

Readme

task-tape

Tape with gulpish task support.

version status dependencies devDependencies

Usage

Global installation

npm install -g task-tape

Go to your project directory, which has tape installed already:

task-tape test/*.js

Or with babel (please install babel first):

task-tape --babel test/*.js

Local installation

npm install --save-dev task-tape tape

Require directly

var test = require('task-tape')

Hook require

require('task-tape')
var test = require('tape')

With gulp-tape

gulp.task('test', function test() {
  require('task-tape')
  var tape = require('gulp-tape')
  var reporter = require('tap-spec')
  return gulp.src('test/*.js')
    .pipe(tape({
      reporter: reporter(),
    }))
})

npm test

In package.json:

{
  "scripts": {
    "test": "task-tape test/*.js"
  }
}

To support babel:

{
  "scripts": {
    "test": "task-tape --babel test/*.js"
  }
}

Example

End the test

t.end

import test from 'tape'

test('sync', (t) => {
  t.ok(true)
  t.ok(true)
  t.end()
})

test('async', (t) => {
  process.nextTick(() => {
    t.ok(true)
    t.end()
  })
  t.ok(true)
})

t.plan

import test from 'tape'

test('async', (t) => {
  t.plan(2)
  process.nextTick(() => {
    t.ok(true)
  })
  t.ok(true)
})

Gulpish callback

import test from 'tape'
import concat from 'concat-stream'

// accept a callback
test('callback', (t, cb) => {
  process.nextTick(() => {
    t.ok(true)
    cb()
  })
})

// return a promise
test('promise', (t) => {
  return new Promise((rs) => {
    process.nextTick(() => {
      t.ok(true)
      rs()
    })
  })
})

// return a stream
test('stream', (t) => {
  let s = concat({ encoding: 'object' }, (rows) => {
    t.same(rows, [ { x: 1 }, { y: 2 }, { z: 3 } ])
  })
  s.write({ x: 1 })
  s.write({ y: 2 })
  process.nextTick(() => {
    s.end({ z: 3 })
  })
  return s
})

Gulpish callbacks in sequence

import test from 'tape'
import concat from 'concat-stream'
import gulp from 'gulp'
import fs from 'fs'
import del from 'del'

// Run tasks in sequence.
test('tasks in sequence', function(t) {
  // t.plan(7)

  let rows = []

  // clean
  t.task(() => {
    t.ok(true)
    return del('build')
  })

  // delay
  t.task((cb) => {
    t.ok(true)
    setTimeout(() => {
      cb()
    }, 100)
  })

  // collect rows
  t.task(() => {
    t.ok(true)
    let stream = thr.obj()

    stream.write({ index: 0 })

    process.nextTick(() => {
      stream.end({ index: 1 })
    })

    return stream.pipe(concat({ encoding: 'object' }, function (rs) {
      rows = rs.sort((a, b) => {
        return a.index < b.index ? 1 : -1
      })
    }))
  })

  // stringify rows
  t.task(() => {
    t.same(rows, [ { index: 1 }, { index: 0 } ])
    let ws = fs.createWriteStream('rows.json')

    process.nextTick(() => {
      ws.end(JSON.stringify(rows, null, 2))
    })

    return ws
  })

  // build
  t.task(() => {
    t.ok(true)
    return gulp.src('rows.json')
      .pipe(gulp.dest('build'))
  })

  // check
  t.task(() => {
    t.equal(
      fs.readFileSync('rows.json', 'utf8'),
      fs.readFileSync('build/rows.json', 'utf8')
    )
  })

  // clean
  t.task(() => {
    t.ok(true)
    return del('rows.json')
  })
})