Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zoubin/task-tape
Tape with gulpish task support
https://github.com/zoubin/task-tape
Last synced: 8 days ago
JSON representation
Tape with gulpish task support
- Host: GitHub
- URL: https://github.com/zoubin/task-tape
- Owner: zoubin
- License: mit
- Created: 2015-10-05T12:38:58.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-24T03:22:56.000Z (almost 9 years ago)
- Last Synced: 2024-04-09T16:29:07.525Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
# task-tape
[Tape](https://github.com/substack/tape) with [gulpish task support](https://github.com/gulpjs/gulp/blob/master/docs/API.md#async-task-support).[![version](https://img.shields.io/npm/v/task-tape.svg)](https://www.npmjs.org/package/task-tape)
[![status](https://travis-ci.org/zoubin/task-tape.svg?branch=master)](https://travis-ci.org/zoubin/task-tape)
[![dependencies](https://david-dm.org/zoubin/task-tape.svg)](https://david-dm.org/zoubin/task-tape)
[![devDependencies](https://david-dm.org/zoubin/task-tape/dev-status.svg)](https://david-dm.org/zoubin/task-tape#info=devDependencies)## Usage
### Global installation
```bash
npm install -g task-tape```
Go to your project directory, which has tape installed already:
```bash
task-tape test/*.js```
Or with babel (please install babel first):
```bash
task-tape --babel test/*.js```
### Local installation
```bash
npm install --save-dev task-tape tape```
### Require directly
```javascript
var test = require('task-tape')```
### Hook require
```javascript
require('task-tape')
var test = require('tape')```
### With [gulp-tape](https://www.npmjs.com/package/gulp-tape)
```javascript
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`:
```json
{
"scripts": {
"test": "task-tape test/*.js"
}
}```
To support babel:
```json
{
"scripts": {
"test": "task-tape --babel test/*.js"
}
}```
## Example
### End the test
#### `t.end`
```javascript
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`
```javascript
import test from 'tape'test('async', (t) => {
t.plan(2)
process.nextTick(() => {
t.ok(true)
})
t.ok(true)
})```
### Gulpish callback
```javascript
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
```javascript
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')
})
})```