1 var expect = require('chai').expect
2 , unique = require('..')
3 , Stream = require('stream')
4 , after = require('after')
5 , setImmediate = global.setImmediate || process.nextTick;
7 describe('unique stream', function() {
9 function makeStream(type) {
14 var next = after(n, function () {
15 setImmediate(function () {
20 for (var i = 0; i < n; i++) {
28 setImmediate(function () {
37 it('should be able to uniqueify objects based on JSON data', function(done) {
38 var aggregator = unique();
46 .on('data', function () {
49 .on('end', function () {
50 expect(n).to.equal(10);
55 it('should be able to uniqueify objects based on a property', function(done) {
56 var aggregator = unique('number');
64 .on('data', function () {
67 .on('end', function () {
68 expect(n).to.equal(10);
73 it('should be able to uniqueify objects based on a function', function(done) {
74 var aggregator = unique(function (data) {
85 .on('data', function () {
88 .on('end', function () {
89 expect(n).to.equal(10);
94 it('should be able to handle uniqueness when not piped', function(done) {
95 var stream = unique();
97 stream.on('data', function (data) {
98 expect(data).to.equal('hello');
101 stream.on('end', function() {
102 expect(count).to.equal(1);
105 stream.write('hello');
106 stream.write('hello');