<commit_before>import m3u8stream from '../dist/index';
import path from 'path';
import fs from 'fs';
import assert from 'assert';
import { PassThrough } from 'stream';
import nock from 'nock';
import { spy } from 'sinon';


const concat = (stream: PassThrough, callback: (err: Error, body: string) => void) => {
  let body = '';
  stream.setEncoding('utf8');
  stream.on('data', (chunk: string) => { body += chunk; });
  stream.on('error', callback);
  stream.on('end', () => { callback(null, body); });
};

describe('m3u8stream', () => {
  let setTimeout = global.setTimeout;
  before(() => { global.setTimeout = (fn, ms, ...args) => setTimeout(fn, 0, ...args); });
  after(() => { global.setTimeout = setTimeout; });

  describe('Simple media playlist', () => {
    it('Concatenates segments into stream', (done) => {
      let scope = nock('http://media.example.com')
        .get('/playlist.m3u8')
        .replyWithFile(200, path.resolve(__dirname, 'playlists/simple.m3u8'))
        .get('/first.ts').reply(200, 'one')
        .get('/second.ts').reply(200, 'two')
        .get('/third.ts').reply(200, 'three');
      let stream = m3u8stream('http://media.example.com/playlist.m3u8');
      concat(stream, (err, body) => {
        assert.ifError(err);
        scope.done();
        assert.equal(body, 'onetwothree');
        done();
      });
    });<commit_msg>test: add `nock.disableNetConnect()` in case<commit_after>import m3u8stream from '../dist/index';
import path from 'path';
import fs from 'fs';
import assert from 'assert';
import { PassThrough } from 'stream';
import nock from 'nock';
import { spy } from 'sinon';


nock.disableNetConnect();
const concat = (stream: PassThrough, callback: (err: Error, body: string) => void) => {
  let body = '';
  stream.setEncoding('utf8');
  stream.on('data', (chunk: string) => { body += chunk; });
  stream.on('error', callback);
  stream.on('end', () => { callback(null, body); });
};

describe('m3u8stream', () => {
  let setTimeout = global.setTimeout;
  before(() => { global.setTimeout = (fn, ms, ...args) => setTimeout(fn, 0, ...args); });
  after(() => { global.setTimeout = setTimeout; });

  describe('Simple media playlist', () => {
    it('Concatenates segments into stream', (done) => {
      let scope = nock('http://media.example.com')
        .get('/playlist.m3u8')
        .replyWithFile(200, path.resolve(__dirname, 'playlists/simple.m3u8'))
        .get('/first.ts').reply(200, 'one')
        .get('/second.ts').reply(200, 'two')
        .get('/third.ts').reply(200, 'three');
      let stream = m3u8stream('http://media.example.com/playlist.m3u8');
      concat(stream, (err, body) => {
        assert.ifError(err);
        scope.done();
        assert.equal(body, 'onetwothree');
        done();
      });
    });
{'fraction_non_alphanumeric': 0.20795984223736105, 'fraction_numerical': 0.01864467551093582, 'mean_word_length': 3.373040752351097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3780720', 'n_tokens_mistral': 938, 'n_tokens_neox': 910, 'n_words': 201}