PHP 7.4.33
Preview: line-stream.test.js Size: 2.50 KB
/var/www/sitesecurity.bitkit.dk/httpdocs/node_modules/m3u8-parser/test/line-stream.test.js
import {LineStream} from '../src';
import QUnit from 'qunit';

QUnit.module('LineStream', {
  beforeEach() {
    this.lineStream = new LineStream();
  }
});
QUnit.test('empty inputs produce no tokens', function(assert) {
  let data = false;

  this.lineStream.on('data', function() {
    data = true;
  });
  this.lineStream.push('');
  assert.ok(!data, 'no tokens were produced');
});
QUnit.test('splits on newlines', function(assert) {
  const lines = [];

  this.lineStream.on('data', function(line) {
    lines.push(line);
  });
  this.lineStream.push('#EXTM3U\nmovie.ts\n');

  assert.strictEqual(2, lines.length, 'two lines are ready');
  assert.strictEqual('#EXTM3U', lines.shift(), 'the first line is the first token');
  assert.strictEqual('movie.ts', lines.shift(), 'the second line is the second token');
});
QUnit.test('empty lines become empty strings', function(assert) {
  const lines = [];

  this.lineStream.on('data', function(line) {
    lines.push(line);
  });
  this.lineStream.push('\n\n');

  assert.strictEqual(2, lines.length, 'two lines are ready');
  assert.strictEqual('', lines.shift(), 'the first line is empty');
  assert.strictEqual('', lines.shift(), 'the second line is empty');
});
QUnit.test('handles lines broken across appends', function(assert) {
  const lines = [];

  this.lineStream.on('data', function(line) {
    lines.push(line);
  });
  this.lineStream.push('#EXTM');
  assert.strictEqual(0, lines.length, 'no lines are ready');

  this.lineStream.push('3U\nmovie.ts\n');
  assert.strictEqual(2, lines.length, 'two lines are ready');
  assert.strictEqual('#EXTM3U', lines.shift(), 'the first line is the first token');
  assert.strictEqual('movie.ts', lines.shift(), 'the second line is the second token');
});
QUnit.test('stops sending events after deregistering', function(assert) {
  const temporaryLines = [];
  const temporary = function(line) {
    temporaryLines.push(line);
  };
  const permanentLines = [];
  const permanent = function(line) {
    permanentLines.push(line);
  };

  this.lineStream.on('data', temporary);
  this.lineStream.on('data', permanent);
  this.lineStream.push('line one\n');
  assert.strictEqual(
    temporaryLines.length,
    permanentLines.length,
    'both callbacks receive the event'
  );

  assert.ok(this.lineStream.off('data', temporary), 'a listener was removed');
  this.lineStream.push('line two\n');
  assert.strictEqual(1, temporaryLines.length, 'no new events are received');
  assert.strictEqual(2, permanentLines.length, 'new events are still received');
});

Directory Contents

Dirs: 1 × Files: 3
Name Size Perms Modified Actions
fixtures DIR
- drwxr-xr-x 2026-04-28 09:11:39
Edit Download
2.50 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
34.40 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
45.21 KB lrw-r--r-- 2026-04-28 09:11:40
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).