1 var sinon = require('sinon')
3 var path = require('path')
5 var expect = require('chai').expect
6 var Linerstream = require('../')
8 describe('Split test', function() {
9 describe('given text with line breaks', function() {
10 it('should split on new lines', function(done) {
11 var fixturePath = path.join(__dirname, 'data/newlines-big.txt')
12 var inputStream = fs.createReadStream(fixturePath)
13 var splitter = new Linerstream()
14 expect(splitter).to.exist
15 var output = inputStream.pipe(splitter)
16 var validateLineSpy = sinon.spy(validateLine)
18 output.on('finish', finishHandler)
19 output.on('readable', readableHandler)
21 function validateLine(line) {
23 expect(line).to.be.a('string')
24 expect(line).to.not.be.empty
25 expect(line).to.not.match(/\n|\r/)
28 function readableHandler() {
40 function finishHandler() {
41 expect(validateLineSpy.callCount).to.be.above(1)