mirror of https://github.com/iptv-org/iptv
				
				
				
			Update tests
							parent
							
								
									98645d4166
								
							
						
					
					
						commit
						c1a815754e
					
				@ -1,45 +0,0 @@
 | 
			
		||||
import * as fs from 'fs-extra'
 | 
			
		||||
import * as path from 'path'
 | 
			
		||||
import { execSync } from 'child_process'
 | 
			
		||||
import * as _ from 'lodash'
 | 
			
		||||
 | 
			
		||||
beforeEach(() => {
 | 
			
		||||
  fs.emptyDirSync('tests/__data__/output')
 | 
			
		||||
  fs.mkdirSync('tests/__data__/output/database')
 | 
			
		||||
 | 
			
		||||
  const stdout = execSync(
 | 
			
		||||
    'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams npm run db:create',
 | 
			
		||||
    { encoding: 'utf8' }
 | 
			
		||||
  )
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
it('can create database', () => {
 | 
			
		||||
  let output = content('tests/__data__/output/database/streams.db')
 | 
			
		||||
  let expected = content('tests/__data__/expected/database/db_create.streams.db')
 | 
			
		||||
 | 
			
		||||
  output = output.map(i => {
 | 
			
		||||
    i._id = null
 | 
			
		||||
    return i
 | 
			
		||||
  })
 | 
			
		||||
  expected = expected.map(i => {
 | 
			
		||||
    i._id = null
 | 
			
		||||
    return i
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  expect(_.orderBy(output, 'name')).toMatchObject(
 | 
			
		||||
    expect.arrayContaining(_.orderBy(expected, 'name'))
 | 
			
		||||
  )
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
function content(filepath: string) {
 | 
			
		||||
  const data = fs.readFileSync(path.resolve(filepath), {
 | 
			
		||||
    encoding: 'utf8'
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  return data
 | 
			
		||||
    .split('\n')
 | 
			
		||||
    .filter(l => l)
 | 
			
		||||
    .map(l => {
 | 
			
		||||
      return JSON.parse(l)
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,30 @@
 | 
			
		||||
import { execSync } from 'child_process'
 | 
			
		||||
import * as fs from 'fs-extra'
 | 
			
		||||
import { glob } from 'glob'
 | 
			
		||||
 | 
			
		||||
beforeEach(() => {
 | 
			
		||||
  fs.emptyDirSync('tests/__data__/output')
 | 
			
		||||
  fs.copySync('tests/__data__/input/streams_format', 'tests/__data__/output/streams')
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
it('can format playlists', () => {
 | 
			
		||||
  const stdout = execSync('STREAMS_DIR=tests/__data__/output/streams npm run playlist:format', {
 | 
			
		||||
    encoding: 'utf8'
 | 
			
		||||
  })
 | 
			
		||||
 | 
			
		||||
  const files = glob
 | 
			
		||||
    .sync('tests/__data__/expected/streams_format/*.m3u')
 | 
			
		||||
    .map(f => f.replace('tests/__data__/expected/streams_format/', ''))
 | 
			
		||||
 | 
			
		||||
  files.forEach(filepath => {
 | 
			
		||||
    expect(content(`output/streams/${filepath}`), filepath).toBe(
 | 
			
		||||
      content(`expected/streams_format/${filepath}`)
 | 
			
		||||
    )
 | 
			
		||||
  })
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
function content(filepath: string) {
 | 
			
		||||
  return fs.readFileSync(`tests/__data__/${filepath}`, {
 | 
			
		||||
    encoding: 'utf8'
 | 
			
		||||
  })
 | 
			
		||||
}
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue