through2 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.npmignore CHANGED
@@ -1 +1,3 @@
1
- node_modules
1
+ test
2
+ .jshintrc
3
+ .travis.yml
package/README.md CHANGED
@@ -1,40 +1,23 @@
1
1
  # through2
2
2
 
3
- <!--
4
-
5
- soon ...
6
-
7
- [![Build Status](https://secure.travis-ci.org/rvagg/through2.png)](http://travis-ci.org/rvagg/through2)
8
-
9
- [![Build Status](https://saucelabs.com/browser-matrix/through2-sauce.svg)](https://travis-ci.org/rvagg/through2)
10
-
11
- -->
12
-
13
- [![NPM](https://nodei.co/npm/through2.png?compact=true)](https://nodei.co/npm/through2/)
14
-
15
- <!--
16
- not happy with these, we need to peg to readable-stream@1.0.x so it'll always report out-of-date
17
-
18
- [![david-dm](https://david-dm.org/rvagg/through2.png)](https://david-dm.org/rvagg/through2/)
19
- [![david-dm](https://david-dm.org/rvagg/through2/dev-status.png)](https://david-dm.org/rvagg/through2#info=devDependencies/)
20
- -->
3
+ [![NPM](https://nodei.co/npm/through2.png?downloads&downloadRank)](https://nodei.co/npm/through2/)
21
4
 
22
5
  **A tiny wrapper around Node streams.Transform (Streams2) to avoid explicit subclassing noise**
23
6
 
24
7
  Inspired by [Dominic Tarr](https://github.com/dominictarr)'s [through](https://github.com/dominictarr/through) in that it's so much easier to make a stream out of a function than it is to set up the prototype chain properly: `through(function (chunk) { ... })`.
25
8
 
9
+ Note: As 2.x.x this module starts using **Streams3** instead of Stream2. To continue using a Streams2 version use `npm install through2@0` to fetch the latest version of 0.x.x. More information about Streams2 vs Streams3 and recommendations see the article **[Why I don't use Node's core 'stream' module](http://r.va.gg/2014/06/why-i-dont-use-nodes-core-stream-module.html)**.
10
+
26
11
  ```js
27
12
  fs.createReadStream('ex.txt')
28
13
  .pipe(through2(function (chunk, enc, callback) {
29
-
30
14
  for (var i = 0; i < chunk.length; i++)
31
15
  if (chunk[i] == 97)
32
16
  chunk[i] = 122 // swap 'a' for 'z'
33
17
 
34
18
  this.push(chunk)
35
-
36
- callback()
37
19
 
20
+ callback()
38
21
  }))
39
22
  .pipe(fs.createWriteStream('out.txt'))
40
23
  ```
@@ -47,17 +30,14 @@ var all = []
47
30
  fs.createReadStream('data.csv')
48
31
  .pipe(csv2())
49
32
  .pipe(through2.obj(function (chunk, enc, callback) {
50
-
51
33
  var data = {
52
34
  name : chunk[0]
53
35
  , address : chunk[3]
54
36
  , phone : chunk[10]
55
37
  }
56
-
57
38
  this.push(data)
58
-
59
- callback()
60
39
 
40
+ callback()
61
41
  }))
62
42
  .on('data', function (data) {
63
43
  all.push(data)
@@ -83,12 +63,12 @@ The `options` argument is first, unlike standard convention, because if I'm pass
83
63
 
84
64
  ```js
85
65
  fs.createReadStream('/tmp/important.dat')
86
- .pipe(through2({ objectMode: true, allowHalfOpen: false }, function (chunk, enc, cb) {
87
-
88
- this.push(new Buffer('wut?'))
89
- cb()
90
-
91
- })
66
+ .pipe(through2({ objectMode: true, allowHalfOpen: false },
67
+ function (chunk, enc, cb) {
68
+ cb(null, 'wut?') // note we can use the second argument on the callback
69
+ // to provide data as an alternative to this.push('wut?')
70
+ }
71
+ )
92
72
  .pipe(fs.createWriteStream('/tmp/wut.txt'))
93
73
  ```
94
74
 
@@ -98,19 +78,33 @@ The `transformFunction` must have the following signature: `function (chunk, enc
98
78
 
99
79
  To queue a new chunk, call `this.push(chunk)`&mdash;this can be called as many times as required before the `callback()` if you have multiple pieces to send on.
100
80
 
101
- If you **do not provide a `transformFunction`** then you will get a simple simple pass-through stream.
81
+ Alternatively, you may use `callback(err, chunk)` as shorthand for emitting a single chunk or an error.
82
+
83
+ If you **do not provide a `transformFunction`** then you will get a simple pass-through stream.
102
84
 
103
85
  ### flushFunction
104
86
 
105
87
  The optional `flushFunction` is provided as the last argument (2nd or 3rd, depending on whether you've supplied options) is called just prior to the stream ending. Can be used to finish up any processing that may be in progress.
106
88
 
89
+ ```js
90
+ fs.createReadStream('/tmp/important.dat')
91
+ .pipe(through2(
92
+ function (chunk, enc, cb) { cb(null, chunk) }, // transform is a noop
93
+ function (cb) { // flush function
94
+ this.push('tacking on an extra buffer to the end');
95
+ cb();
96
+ }
97
+ ))
98
+ .pipe(fs.createWriteStream('/tmp/wut.txt'));
99
+ ```
100
+
107
101
  <b><code>through2.ctor([ options, ] transformFunction[, flushFunction ])</code></b>
108
102
 
109
103
  Instead of returning a `stream.Transform` instance, `through2.ctor()` returns a **constructor** for a custom Transform. This is useful when you want to use the same transform logic in multiple instances.
110
104
 
111
105
  ```js
112
106
  var FToC = through2.ctor({objectMode: true}, function (record, encoding, callback) {
113
- if (record.temp != null && record.unit = "F") {
107
+ if (record.temp != null && record.unit == "F") {
114
108
  record.temp = ( ( record.temp - 32 ) * 5 ) / 9
115
109
  record.unit = "C"
116
110
  }
@@ -126,6 +120,14 @@ var converter = FToC()
126
120
  var converter = FToC({objectMode: true})
127
121
  ```
128
122
 
123
+ ## See Also
124
+
125
+ - [through2-map](https://github.com/brycebaril/through2-map) - Array.prototype.map analog for streams.
126
+ - [through2-filter](https://github.com/brycebaril/through2-filter) - Array.prototype.filter analog for streams.
127
+ - [through2-reduce](https://github.com/brycebaril/through2-reduce) - Array.prototype.reduce analog for streams.
128
+ - [through2-spy](https://github.com/brycebaril/through2-spy) - Wrapper for simple stream.PassThrough spies.
129
+ - the [mississippi stream utility collection](https://github.com/maxogden/mississippi) includes `through2` as well as many more useful stream modules similar to this one
130
+
129
131
  ## License
130
132
 
131
- **through2** is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
133
+ **through2** is Copyright (c) 2013 Rod Vagg [@rvagg](https://twitter.com/rvagg) and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "through2",
3
- "version": "1.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise",
5
5
  "main": "through2.js",
6
6
  "scripts": {
7
- "test": "node test/test.js",
7
+ "test": "node test/test.js | faucet",
8
8
  "test-local": "brtapsauce-local test/basic-test.js"
9
9
  },
10
10
  "repository": {
@@ -20,16 +20,13 @@
20
20
  "author": "Rod Vagg <r@va.gg> (https://github.com/rvagg)",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "readable-stream": "~1.1.10",
24
- "xtend": "~2.1.1"
23
+ "readable-stream": "~2.0.0",
24
+ "xtend": "~4.0.0"
25
25
  },
26
26
  "devDependencies": {
27
- "tape": "~2.3.0",
28
- "bl": "~0.6.0",
29
- "stream-spigot": "~3.0.1",
30
- "brtapsauce": "~0.2.2"
31
- },
32
- "publishConfig": {
33
- "tag": "1.0"
27
+ "bl": "~0.9.4",
28
+ "faucet": "0.0.1",
29
+ "stream-spigot": "~3.0.5",
30
+ "tape": "~4.0.0"
34
31
  }
35
32
  }
package/through2.js CHANGED
@@ -2,6 +2,24 @@ var Transform = require('readable-stream/transform')
2
2
  , inherits = require('util').inherits
3
3
  , xtend = require('xtend')
4
4
 
5
+ function DestroyableTransform(opts) {
6
+ Transform.call(this, opts)
7
+ this._destroyed = false
8
+ }
9
+
10
+ inherits(DestroyableTransform, Transform)
11
+
12
+ DestroyableTransform.prototype.destroy = function(err) {
13
+ if (this._destroyed) return
14
+ this._destroyed = true
15
+
16
+ var self = this
17
+ process.nextTick(function() {
18
+ if (err)
19
+ self.emit('error', err)
20
+ self.emit('close')
21
+ })
22
+ }
5
23
 
6
24
  // a noop _transform function
7
25
  function noop (chunk, enc, callback) {
@@ -32,7 +50,7 @@ function through2 (construct) {
32
50
 
33
51
  // main export, just make me a transform stream!
34
52
  module.exports = through2(function (options, transform, flush) {
35
- var t2 = new Transform(options)
53
+ var t2 = new DestroyableTransform(options)
36
54
 
37
55
  t2._transform = transform
38
56
 
@@ -52,10 +70,10 @@ module.exports.ctor = through2(function (options, transform, flush) {
52
70
 
53
71
  this.options = xtend(options, override)
54
72
 
55
- Transform.call(this, this.options)
73
+ DestroyableTransform.call(this, this.options)
56
74
  }
57
75
 
58
- inherits(Through2, Transform)
76
+ inherits(Through2, DestroyableTransform)
59
77
 
60
78
  Through2.prototype._transform = transform
61
79
 
@@ -67,7 +85,7 @@ module.exports.ctor = through2(function (options, transform, flush) {
67
85
 
68
86
 
69
87
  module.exports.obj = through2(function (options, transform, flush) {
70
- var t2 = new Transform(xtend({ objectMode: true }, options))
88
+ var t2 = new DestroyableTransform(xtend({ objectMode: true, highWaterMark: 16 }, options))
71
89
 
72
90
  t2._transform = transform
73
91
 
package/.jshintrc DELETED
@@ -1,59 +0,0 @@
1
- {
2
- "predef": [ ]
3
- , "bitwise": false
4
- , "camelcase": false
5
- , "curly": false
6
- , "eqeqeq": false
7
- , "forin": false
8
- , "immed": false
9
- , "latedef": false
10
- , "noarg": true
11
- , "noempty": true
12
- , "nonew": true
13
- , "plusplus": false
14
- , "quotmark": true
15
- , "regexp": false
16
- , "undef": true
17
- , "unused": true
18
- , "strict": false
19
- , "trailing": true
20
- , "maxlen": 120
21
- , "asi": true
22
- , "boss": true
23
- , "debug": true
24
- , "eqnull": true
25
- , "esnext": true
26
- , "evil": true
27
- , "expr": true
28
- , "funcscope": false
29
- , "globalstrict": false
30
- , "iterator": false
31
- , "lastsemic": true
32
- , "laxbreak": true
33
- , "laxcomma": true
34
- , "loopfunc": true
35
- , "multistr": false
36
- , "onecase": false
37
- , "proto": false
38
- , "regexdash": false
39
- , "scripturl": true
40
- , "smarttabs": false
41
- , "shadow": false
42
- , "sub": true
43
- , "supernew": false
44
- , "validthis": true
45
- , "browser": true
46
- , "couch": false
47
- , "devel": false
48
- , "dojo": false
49
- , "mootools": false
50
- , "node": true
51
- , "nonstandard": true
52
- , "prototypejs": false
53
- , "rhino": false
54
- , "worker": true
55
- , "wsh": false
56
- , "nomen": false
57
- , "onevar": false
58
- , "passfail": false
59
- }
package/.travis.yml DELETED
@@ -1,17 +0,0 @@
1
- language: node_js
2
- node_js:
3
- - '0.8'
4
- - '0.10'
5
- - '0.11'
6
- branches:
7
- only:
8
- - master
9
- notifications:
10
- email:
11
- - rod@vagg.org
12
- script: npm test
13
- env:
14
- global:
15
- - SAUCE_USER=through2-sauce
16
- - secure: A8KyygIlklZOcTwTGhZHpkOu7Cn4tI1QQasg75CTSjudczGzkuh1pG2RDIkWqGcrWv9o5CjI6fFYYx0JvQu8o5PO+ZAtV1Z0AlnM965vE8kAx0XEC7giAV323bibfnHwyQu74vIhbOfdes7E4/cYerV2kAjK0T375D4DYEpDuvw=
17
-
@@ -1,334 +0,0 @@
1
- const test = require('tape')
2
- , through2 = require('../')
3
- , crypto = require('crypto')
4
- , bl = require('bl')
5
- , spigot = require('stream-spigot')
6
-
7
- test('plain through', function (t) {
8
- var th2 = through2(function (chunk, enc, callback) {
9
- if (!this._i)
10
- this._i = 97 // 'a'
11
- else
12
- this._i++
13
- var b = new Buffer(chunk.length)
14
- for (var i = 0; i < chunk.length; i++)
15
- b[i] = this._i
16
- this.push(b)
17
- callback()
18
- })
19
-
20
- th2.pipe(bl(function (err, b) {
21
- var s = b.toString('ascii')
22
- t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
23
- t.end()
24
- }))
25
-
26
- th2.write(crypto.randomBytes(10))
27
- th2.write(crypto.randomBytes(5))
28
- th2.write(crypto.randomBytes(10))
29
- th2.end()
30
- })
31
-
32
- test('pipeable through', function (t) {
33
- var th2 = through2(function (chunk, enc, callback) {
34
- if (!this._i)
35
- this._i = 97 // 'a'
36
- else
37
- this._i++
38
- var b = new Buffer(chunk.length)
39
- for (var i = 0; i < chunk.length; i++)
40
- b[i] = this._i
41
- this.push(b)
42
- callback()
43
- })
44
-
45
- th2.pipe(bl(function (err, b) {
46
- var s = b.toString('ascii')
47
- // bl() acts like a proper streams2 stream and passes as much as it's
48
- // asked for, so we really only get one write with such a small amount
49
- // of data
50
- t.equal(s, 'aaaaaaaaaaaaaaaaaaaaaaaaa', 'got transformed string')
51
- t.end()
52
- }))
53
-
54
- var bufs = bl()
55
- bufs.append(crypto.randomBytes(10))
56
- bufs.append(crypto.randomBytes(5))
57
- bufs.append(crypto.randomBytes(10))
58
- bufs.pipe(th2)
59
- })
60
-
61
- test('object through', function (t) {
62
- t.plan(3)
63
-
64
- var th2 = through2({ objectMode: true}, function (chunk, enc, callback) {
65
- this.push({ out: chunk.in + 1 })
66
- callback()
67
- })
68
-
69
- var e = 0
70
- th2.on('data', function (o) {
71
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
72
- e++
73
- })
74
-
75
- th2.write({ in: 101 })
76
- th2.write({ in: 202 })
77
- th2.write({ in: -100 })
78
- th2.end()
79
- })
80
-
81
- test('object through with through2.obj', function (t) {
82
- t.plan(3)
83
-
84
- var th2 = through2.obj(function (chunk, enc, callback) {
85
- this.push({ out: chunk.in + 1 })
86
- callback()
87
- })
88
-
89
- var e = 0
90
- th2.on('data', function (o) {
91
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
92
- e++
93
- })
94
-
95
- th2.write({ in: 101 })
96
- th2.write({ in: 202 })
97
- th2.write({ in: -100 })
98
- th2.end()
99
- })
100
-
101
- test('flushing through', function (t) {
102
- var th2 = through2(function (chunk, enc, callback) {
103
- if (!this._i)
104
- this._i = 97 // 'a'
105
- else
106
- this._i++
107
- var b = new Buffer(chunk.length)
108
- for (var i = 0; i < chunk.length; i++)
109
- b[i] = this._i
110
- this.push(b)
111
- callback()
112
- }, function (callback) {
113
- this.push(new Buffer([ 101, 110, 100 ]))
114
- callback()
115
- })
116
-
117
- th2.pipe(bl(function (err, b) {
118
- var s = b.toString('ascii')
119
- t.equal(s, 'aaaaaaaaaabbbbbccccccccccend', 'got transformed string')
120
- t.end()
121
- }))
122
-
123
- th2.write(crypto.randomBytes(10))
124
- th2.write(crypto.randomBytes(5))
125
- th2.write(crypto.randomBytes(10))
126
- th2.end()
127
- })
128
-
129
- test('plain through ctor', function (t) {
130
- var Th2 = through2.ctor(function (chunk, enc, callback) {
131
- if (!this._i)
132
- this._i = 97 // 'a'
133
- else
134
- this._i++
135
- var b = new Buffer(chunk.length)
136
- for (var i = 0; i < chunk.length; i++)
137
- b[i] = this._i
138
- this.push(b)
139
- callback()
140
- })
141
-
142
- var th2 = new Th2()
143
-
144
- th2.pipe(bl(function (err, b) {
145
- var s = b.toString('ascii')
146
- t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
147
- t.end()
148
- }))
149
-
150
- th2.write(crypto.randomBytes(10))
151
- th2.write(crypto.randomBytes(5))
152
- th2.write(crypto.randomBytes(10))
153
- th2.end()
154
- })
155
-
156
- test('reuse through ctor', function (t) {
157
- t.plan(4)
158
-
159
- var Th2 = through2.ctor(function (chunk, enc, callback) {
160
- if (!this._i) {
161
- t.ok(1, 'did not contain previous instance data (this._i)')
162
- this._i = 97 // 'a'
163
- } else
164
- this._i++
165
- var b = new Buffer(chunk.length)
166
- for (var i = 0; i < chunk.length; i++)
167
- b[i] = this._i
168
- this.push(b)
169
- callback()
170
- })
171
-
172
- var th2 = Th2()
173
-
174
- th2.pipe(bl(function (err, b) {
175
- var s = b.toString('ascii')
176
- t.equal('aaaaaaaaaabbbbbcccccccccc', s, 'got transformed string')
177
-
178
- var newInstance = Th2()
179
- newInstance.pipe(bl(function (err, b) {
180
- var s = b.toString('ascii')
181
- t.equal('aaaaaaabbbbccccccc', s, 'got transformed string')
182
- }))
183
-
184
- newInstance.write(crypto.randomBytes(7))
185
- newInstance.write(crypto.randomBytes(4))
186
- newInstance.write(crypto.randomBytes(7))
187
- newInstance.end()
188
- }))
189
-
190
- th2.write(crypto.randomBytes(10))
191
- th2.write(crypto.randomBytes(5))
192
- th2.write(crypto.randomBytes(10))
193
- th2.end()
194
- })
195
-
196
- test('object through ctor', function (t) {
197
- t.plan(3)
198
-
199
- var Th2 = through2.ctor({ objectMode: true}, function (chunk, enc, callback) {
200
- this.push({ out: chunk.in + 1 })
201
- callback()
202
- })
203
-
204
- var th2 = new Th2()
205
-
206
- var e = 0
207
- th2.on('data', function (o) {
208
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
209
- e++
210
- })
211
-
212
- th2.write({ in: 101 })
213
- th2.write({ in: 202 })
214
- th2.write({ in: -100 })
215
- th2.end()
216
- })
217
-
218
- test('pipeable object through ctor', function (t) {
219
- t.plan(4)
220
-
221
- var Th2 = through2.ctor({ objectMode: true}, function (record, enc, callback) {
222
- if (record.temp != null && record.unit == 'F') {
223
- record.temp = ( ( record.temp - 32 ) * 5 ) / 9
224
- record.unit = 'C'
225
- }
226
- this.push(record)
227
- callback()
228
- })
229
-
230
- var th2 = Th2()
231
-
232
- var expect = [-19, -40, 100, 22]
233
- th2.on('data', function (o) {
234
- t.deepEqual(o, { temp: expect.shift(), unit: 'C' }, 'got transformed object')
235
- })
236
-
237
- spigot({objectMode: true}, [
238
- {temp: -2.2, unit: 'F'},
239
- {temp: -40, unit: 'F'},
240
- {temp: 212, unit: 'F'},
241
- {temp: 22, unit: 'C'}
242
- ]).pipe(th2)
243
- })
244
-
245
- test('object through ctor override', function (t) {
246
- t.plan(3)
247
-
248
- var Th2 = through2.ctor(function (chunk, enc, callback) {
249
- this.push({ out: chunk.in + 1 })
250
- callback()
251
- })
252
-
253
- var th2 = Th2({objectMode: true})
254
-
255
- var e = 0
256
- th2.on('data', function (o) {
257
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
258
- e++
259
- })
260
-
261
- th2.write({ in: 101 })
262
- th2.write({ in: 202 })
263
- th2.write({ in: -100 })
264
- th2.end()
265
- })
266
-
267
- test('object settings available in transform', function (t) {
268
- t.plan(6)
269
-
270
- var Th2 = through2.ctor({objectMode: true, peek: true}, function (chunk, enc, callback) {
271
- t.ok(this.options.peek, "reading options from inside _transform")
272
- this.push({ out: chunk.in + 1 })
273
- callback()
274
- })
275
-
276
- var th2 = Th2()
277
-
278
- var e = 0
279
- th2.on('data', function (o) {
280
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
281
- e++
282
- })
283
-
284
- th2.write({ in: 101 })
285
- th2.write({ in: 202 })
286
- th2.write({ in: -100 })
287
- th2.end()
288
- })
289
-
290
- test('object settings available in transform override', function (t) {
291
- t.plan(6)
292
-
293
- var Th2 = through2.ctor(function (chunk, enc, callback) {
294
- t.ok(this.options.peek, "reading options from inside _transform")
295
- this.push({ out: chunk.in + 1 })
296
- callback()
297
- })
298
-
299
- var th2 = Th2({objectMode: true, peek: true})
300
-
301
- var e = 0
302
- th2.on('data', function (o) {
303
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
304
- e++
305
- })
306
-
307
- th2.write({ in: 101 })
308
- th2.write({ in: 202 })
309
- th2.write({ in: -100 })
310
- th2.end()
311
- })
312
-
313
- test('object override extends options', function (t) {
314
- t.plan(6)
315
-
316
- var Th2 = through2.ctor({objectMode: true}, function (chunk, enc, callback) {
317
- t.ok(this.options.peek, "reading options from inside _transform")
318
- this.push({ out: chunk.in + 1 })
319
- callback()
320
- })
321
-
322
- var th2 = Th2({peek: true})
323
-
324
- var e = 0
325
- th2.on('data', function (o) {
326
- t.deepEqual(o, { out: e === 0 ? 102 : e == 1 ? 203 : -99 }, 'got transformed object')
327
- e++
328
- })
329
-
330
- th2.write({ in: 101 })
331
- th2.write({ in: 202 })
332
- th2.write({ in: -100 })
333
- th2.end()
334
- })
package/test/bench.js DELETED
@@ -1,42 +0,0 @@
1
- /*
2
- on rvagg@fletcher:
3
- @0.2.3: Ran 36719 iterations in 10000 ms
4
- */
5
-
6
- const through2 = require('../')
7
- , bl = require('bl')
8
- , crypto = require('crypto')
9
- , assert = require('assert')
10
-
11
- function run (callback) {
12
- var bufs = Array.apply(null, Array(10)).map(function () { return crypto.randomBytes(32) })
13
- , stream = through2(function (chunk, env, callback) {
14
- callback(null, chunk.toString('hex'))
15
- })
16
-
17
- stream.pipe(bl(function (err, data) {
18
- assert(!err)
19
- assert.equal(data.toString(), Buffer.concat(bufs).toString('hex'))
20
- callback()
21
- }))
22
-
23
- bufs.forEach(function (b) {
24
- stream.write(b)
25
- })
26
- stream.end()
27
- }
28
-
29
- var count = 0
30
- , start = Date.now()
31
-
32
- ;(function exec () {
33
- count++
34
- run(function () {
35
- if (Date.now() - start < 1000 * 10) {
36
- return setImmediate(exec)
37
- }
38
- console.log('Ran', count, 'iterations in', Date.now() - start, 'ms')
39
- })
40
- }())
41
-
42
- console.log('Running for ~10s')
package/test/sauce.js DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const user = process.env.SAUCE_USER
4
- , key = process.env.SAUCE_KEY
5
- , path = require('path')
6
- , brtapsauce = require('brtapsauce')
7
- , testFile = path.join(__dirname, 'basic-test.js')
8
-
9
- , capabilities = [
10
- { browserName: 'chrome' , platform: 'Windows XP', version: '' }
11
- , { browserName: 'firefox' , platform: 'Windows 8' , version: '' }
12
- , { browserName: 'firefox' , platform: 'Windows XP', version: '4' }
13
- , { browserName: 'internet explorer' , platform: 'Windows 8' , version: '10' }
14
- , { browserName: 'internet explorer' , platform: 'Windows 7' , version: '9' }
15
- , { browserName: 'internet explorer' , platform: 'Windows 7' , version: '8' }
16
- , { browserName: 'internet explorer' , platform: 'Windows XP', version: '7' }
17
- , { browserName: 'internet explorer' , platform: 'Windows XP', version: '6' }
18
- , { browserName: 'safari' , platform: 'Windows 7' , version: '5' }
19
- , { browserName: 'safari' , platform: 'OS X 10.8' , version: '6' }
20
- , { browserName: 'opera' , platform: 'Windows 7' , version: '' }
21
- , { browserName: 'opera' , platform: 'Windows 7' , version: '11' }
22
- , { browserName: 'ipad' , platform: 'OS X 10.8' , version: '6' }
23
- , { browserName: 'android' , platform: 'Linux' , version: '4.0', 'device-type': 'tablet' }
24
- ]
25
-
26
- if (!user)
27
- throw new Error('Must set a SAUCE_USER env var')
28
- if (!key)
29
- throw new Error('Must set a SAUCE_KEY env var')
30
-
31
- brtapsauce({
32
- name : 'Traversty'
33
- , user : user
34
- , key : key
35
- , brsrc : testFile
36
- , capabilities : capabilities
37
- , options : { timeout: 60 * 6 }
38
- })
package/test/test.js DELETED
@@ -1,9 +0,0 @@
1
- require('./basic-test')
2
-
3
- if (!process.env.SAUCE_KEY || !process.env.SAUCE_USER)
4
- return console.log('SAUCE_KEY and/or SAUCE_USER not set, not running sauce tests')
5
-
6
- if (!/v0\.10/.test(process.version))
7
- return console.log('Not Node v0.10.x, not running sauce tests')
8
-
9
- require('./sauce.js')