Skip to content

Commit

Permalink
feat: add listVisibleInputs method (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Van Camp authored and Julusian committed Nov 29, 2019
1 parent fa974a4 commit 23c9318
Show file tree
Hide file tree
Showing 45 changed files with 22,241 additions and 9 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ Whenever the connection to the ATEM fails and does not recover within 5 seconds
Whenever a packet from the ATEM is received that changes the state, this event will be fired.
The path parameter is a path into the state that represents the change, to allow for filtering of events. eg video.ME.0.programInput

- `receivedCommand(command)`
Whenever a packet from the ATEM is received that contains a command, this event will be fired.
This should not be relied on in most usage, as the commands can and will have breaking changes in patch releases. This event is needed for some use cases, so if this is used you should likely pin the version down to a specific patch release to ensure nothing breaks.

## Debug

Set `debug=true` config option in order to see raw packets. This is especially useful for library developers.
Expand Down
10 changes: 9 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@ module.exports = {
}
},
coverageDirectory: "./coverage/",
collectCoverage: true
collectCoverage: true,
collectCoverageFrom: [
"**/src/**",
"!**/src/@types/**",
"!**/__tests__/**",
"!**/__mocks__/**",
'!**/node_modules/**',
'!**/dist/**'
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"devDependencies": {
"@types/jest": "^24.0.11",
"@types/node": "^12.7.12",
"class-transformer": "^0.2.3",
"codecov": "^3.2.0",
"gh-pages": "^2.0.1",
"jest": "^24.8.0",
Expand Down
73 changes: 73 additions & 0 deletions src/__tests__/tally.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Commands } from '../index'
import { listVisibleInputs } from '../lib/tally'

import { readFileSync } from 'fs'
import { resolve } from 'path'
import { parseAtemState } from './util'

function readJson (fileName: string) {
const filePath = resolve(__dirname, fileName)
const fileData = readFileSync(filePath)
return JSON.parse(fileData as any)
}

function loadRawState (file: string) {
return parseAtemState(readJson(`./tally/${file}-state.json`))
}
function loadTally (file: string) {
const rawTally = readJson(`./tally/${file}-tally.json`) as Commands.TallyBySourceCommand['properties']

const program: number[] = []
const preview: number[] = []
for (const id in rawTally) {
const elm = rawTally[id]
if (elm && elm.program) {
program.push(Number(id))
}
if (elm && elm.preview) {
preview.push(Number(id))
}
}

return {
program: program.sort(),
preview: preview.sort()
}
}

function runTestMe1 (name: string, filename: string) {
const rawTally = loadTally(filename)
const rawState = loadRawState(filename)

test(`${name} - program`, () => {
const res = listVisibleInputs('program', rawState, 0).sort()
expect(res).toEqual(rawTally.program)
})
test(`${name} - preview`, () => {
const res = listVisibleInputs('preview', rawState, 0).sort()
expect(res).toEqual(rawTally.preview)
})
}

describe('tally', () => {
/**
* Test cases can be generated with the dump.js script.
* These tests compare listVisibleInputs against the atem TlSr command
*/
runTestMe1('dsk active', 'dsk-active')
runTestMe1('dsk in auto', 'dsk-in-auto')
runTestMe1('ssrc', 'ssrc')
runTestMe1('ssrc2', 'ssrc2')
runTestMe1('upstream keyers', 'upstream-keyers')
runTestMe1('mid wipe - no border', 'mid-wipe-no-border')
runTestMe1('mid wipe - with border', 'mid-wipe-with-border')
runTestMe1('mid dip', 'mid-dip')
runTestMe1('mid sting', 'mid-trans-sting')
runTestMe1('mid dve - no inputs', 'mid-trans-dve')
runTestMe1('mid dve - with fill', 'mid-trans-dve-with-fill')
runTestMe1('mid dve - with fill and key', 'mid-trans-dve-with-fill-and-key')
runTestMe1('preview transition', 'preview-trans')
runTestMe1('mid preview transition', 'mid-preview-trans')
runTestMe1('chain me2 pgm', 'chain-me2-pgm')
runTestMe1('chain me2 pvw', 'chain-me2-pvw')
})
Loading

0 comments on commit 23c9318

Please sign in to comment.