import { assert } from 'chai' ; import { parseStream } from '../lib' ; import { IHttpClient , HttpClient } from './http-client' ; import { IFileInfo } from 'strtok3' ; interface IHttpClientTest { readonly name : string ; client : IHttpClient ; } const clients = [ { name : 'http' , client : new HttpClient ( ) } ] ; describe ( 'HTTP streaming' , function ( ) { this . timeout ( 15 * 1000 ) ; this . retries ( 3 ) ; describe ( 'Stream HTTP using different clients' , ( ) => { clients . forEach ( test => { describe ( `HTTP client: ${ test . name }` , ( ) => { [ true , false ] . forEach ( hasContentLength => { it ( `Should be able to parse M4A ${ hasContentLength ? 'with' : 'without' } content-length specified` , async ( ) => { const url = 'http://builds.tokyo.s3.amazonaws.com/sample.m4a' ; const response = await test . client . get ( url ) ; const fileInfo = { mimeType : response . headers [ 'content-type' ] } ; if ( hasContentLength ) { fileInfo . size = parseInt ( response . headers [ 'content-length' ] , 10 ) ; } const tags = await parseStream ( response . stream , fileInfo ) ; if ( response . stream . destroy ) { response . stream . destroy ( ) ; } assert . strictEqual ( tags . format . container , 'M4A/mp42/isom' ) ; assert . strictEqual ( tags . format . codec , 'MPEG-4/AAC' ) ; assert . strictEqual ( tags . format . lossless , false ) ; assert . strictEqual ( tags . common . title , 'Super Mario Galaxy "Into The Galaxy"' ) ; assert . strictEqual ( tags . common . artist , 'club nintendo CD "SUPER MARIO GALAXY"より' ) ; assert . strictEqual ( tags . common . album , 'SUPER MARIO GALAXY ORIGINAL SOUNDTRACK' ) ; } ) ; } ) ; } ) ; } ) ; } ) ; } ) ;