# stream-assert-gulp

> simplify assertion library for gulp streams

Latest version **0.4.9** (published 2014-12-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install stream-assert-gulp
pnpm add stream-assert-gulp
yarn add stream-assert-gulp
bun add stream-assert-gulp
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.9 |
| Published | 2014-12-29 |
| First published | 2014-09-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | bornkiller |
| Maintainers | bornkiller |
| Keywords | assert, stream, gulp |

## Links

- npm: https://www.npmjs.com/package/stream-assert-gulp
- Repository: https://github.com/bornkiller/stream-assert-gulp
- Homepage: https://github.com/bornkiller/stream-assert-gulp.git
- Issues: https://github.com/bornkiller/stream-assert-gulp.git/issues
- npm.io page: https://npm.io/package/stream-assert-gulp

## Dependencies (1)

- [through-gulp](https://npm.io/package/through-gulp.md) ~0.3.5

## Alternatives

- [byte-size](https://npm.io/package/byte-size.md) — 2.1M weekly downloads
- [speed-limiter](https://npm.io/package/speed-limiter.md) — 16.0K weekly downloads
- [@powersync/node](https://npm.io/package/@powersync/node.md) — 10.9K weekly downloads
- [@ledgerhq/coin-cardano](https://npm.io/package/@ledgerhq/coin-cardano.md) — 1.0K weekly downloads
- [@jayesol/jayeson.lib.streamfinder](https://npm.io/package/@jayesol/jayeson.lib.streamfinder.md) — 1.0K weekly downloads

## Recent versions

- 0.4.9 (latest) — 2014-12-29
- 0.4.7 — 2014-12-24
- 0.4.3 — 2014-09-21
- 0.4.0 — 2014-09-17
- 0.3.0 — 2014-09-15
- 0.2.0 — 2014-09-14
- 0.1.6 — 2014-09-14

## README

# stream-assert-gulp
![Build Status](https://img.shields.io/travis/bornkiller/stream-assert-gulp/master.svg?style=flat)
![Coverage Report](http://img.shields.io/coveralls/bornkiller/stream-assert-gulp.svg?style=flat)
![Package Dependency](https://david-dm.org/bornkiller/stream-assert-gulp.svg?style=flat)
![Package DevDependency](https://david-dm.org/bornkiller/stream-assert-gulp/dev-status.svg?style=flat)

Assert gulp streams, make gulp plugin test easier, based on `through-gulp`, inspired by
`stream-assert` (https://github.com/floatdrop/stream-assert.git).

## Install
```js
npm install stream-assert-gulp --save-dev
```

## Usage
```js
var gulp = require('gulp');
var assert = require('stream-assert-gulp');
var should = require('should');

it('should pass data to next when undeclared', function (done) {
  gulp.src('./test/fixtures/template.js')
    // assert the file
    .pipe(assert.first(function(file) {
      (file.isBuffer()).should.be.true;
      (file.isStream()).should.be.false;
    }))
    // indicate the assert result
    .on('end', done);
});
```

## API

Build for asserting gulp stream. Constructed stream will emit `end` after stream assert, without any argument for success, with assertion error as first argument for fail.

### Assertion
Assertion is a function with each file as the first argument, just assert the file. For example:
```js
assertion = function(file) {
  (file.isBuffer()).should.be.true;
  (file.isStream()).should.be.false;
})
```

#### nth(n, assertion)

Calls `assertion` function on nth-child element in stream.

#### first(assertion)

Calls `assertion` function on first-child element in stream.

#### second(assertion)

Calls `assertion` function on first-child element in stream.

#### last(assertion)

Calls `assertion` function on last-child element in stream.

#### length(len)

Asserting, that length of stream is equal `len` at the end of the stream.

#### all(assertion)

Calls `assertion` function on every-child element in stream. Only if all the elements

match the assertion then pass success.

#### any(assertion)

Calls `assertion` function on every-child element in stream. Only if any of the elements

match the assertion, then pass success.

## Assert chain
As promised, now it does support chain assert after v0.2.x. Pay attention when you need
chain assert, assert below just work right, when all the assertion passed, the `done`
callback has no argument. when any assertion failed, it will jump to the end, and `done`
callback has error(this assertion throw) as first argument.

Till now, `length`, `nth`, `first`, `last` support chained assertion, also, `all` and `any`
works for chained assertion since v0.4.0.

```js
gulp.src(['./test/fixtures/template.js', './test/fixtures/destiny.js'])
  .pipe(assert.length(1))
  .pipe(assert.first(function(file) {
    (file.contents.toString()).should.equal("define('destiny',[],function(){});");
  }))
  .pipe(assert.nth(2, function(file) {
    (file.contents.toString()).should.equal("define('template',[],function(){});");
  }))
  .pipe(assert.any(function(file) {
    (file.isBuffer()).should.be.true;
  }))
  .pipe(assert.all(function(file) {
    (file.isStream()).should.be.false;
  }))
  .on('end', done);
```

## Contact

*Email: hjj491229492@hotmail.com*

## License

MIT (c) 2014

---
_Source: https://npm.io/package/stream-assert-gulp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
