Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Apr 8, 2024
2 parents cc2a0a1 + 1a9874b commit 3919c0d
Show file tree
Hide file tree
Showing 55 changed files with 1,479 additions and 567 deletions.
4 changes: 2 additions & 2 deletions apps/appcontainer-node/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@appcontainer-node/app",
"version": "1.50.2",
"version": "1.50.5-alpha.0",
"description": "AppContainer-Node.js",
"private": true,
"scripts": {
Expand All @@ -11,7 +11,7 @@
"start": "node dist/index.js"
},
"dependencies": {
"@appcontainer-node/generic": "1.50.2"
"@appcontainer-node/generic": "1.50.5-alpha.0"
},
"prettier": "@sofie-automation/code-standard-preset/.prettierrc.json",
"engines": {
Expand Down
8 changes: 4 additions & 4 deletions apps/appcontainer-node/packages/generic/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "@appcontainer-node/generic",
"version": "1.50.2",
"version": "1.50.5-alpha.0",
"private": true,
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "yarn rimraf dist && yarn build:main",
"build:main": "tsc -p tsconfig.json",
"__test": "jest"
"test": "jest"
},
"peerDependencies": {
"@sofie-automation/shared-lib": "*"
},
"dependencies": {
"@sofie-package-manager/api": "1.50.2",
"@sofie-package-manager/worker": "1.50.2",
"@sofie-package-manager/api": "1.50.5-alpha.0",
"@sofie-package-manager/worker": "1.50.5-alpha.0",
"underscore": "^1.12.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import EventEmitter from 'events'

const packageManagerAPI: any = jest.createMockFromModule('@sofie-package-manager/api')
const realPackageManagerAPI = jest.requireActual('@sofie-package-manager/api')

type ClientType = 'N/A' | 'workerAgent' | 'expectationManager' | 'appContainer'

class MockClientConnection extends EventEmitter {
constructor() {
super()
}

public clientType: ClientType = 'N/A'
public clientId = ''
}

export class WebsocketServer extends EventEmitter {
constructor(public _port: number, public _logger: any, connectionClb: (client: MockClientConnection) => void) {
super()
WebsocketServer.connectionClb = connectionClb
}
static connectionClb: (connection: MockClientConnection) => void

static openConnections: MockClientConnection[] = []

static mockNewConnection(clientId: string, clientType: ClientType): MockClientConnection {
const newConnection = new MockClientConnection()
newConnection.clientId = clientId
newConnection.clientType = clientType
WebsocketServer.openConnections.push(newConnection)
WebsocketServer.connectionClb(newConnection)
return newConnection
}

terminate() {
WebsocketServer.openConnections.forEach((connection) => {
connection.emit('close')
})
this.emit('close')
}
}
packageManagerAPI.WebsocketServer = WebsocketServer

// these are various utilities, not really a part of the API
packageManagerAPI.initializeLogger = realPackageManagerAPI.initializeLogger
packageManagerAPI.setupLogger = realPackageManagerAPI.setupLogger
packageManagerAPI.protectString = realPackageManagerAPI.protectString
packageManagerAPI.unprotectString = realPackageManagerAPI.unprotectString
packageManagerAPI.literal = realPackageManagerAPI.literal
packageManagerAPI.mapEntries = realPackageManagerAPI.mapEntries
packageManagerAPI.findValue = realPackageManagerAPI.findValue
packageManagerAPI.DataStore = realPackageManagerAPI.DataStore
packageManagerAPI.stringifyError = realPackageManagerAPI.stringifyError
packageManagerAPI.waitTime = realPackageManagerAPI.waitTime

module.exports = packageManagerAPI
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import EventEmitter from 'events'

/* eslint-disable no-console */

const child_process: any = jest.createMockFromModule('child_process')

async function pExec(_commandString: string, _options: any): Promise<{ stdout: string; stderr: string }> {
const NOOP = { stdout: '', stderr: '' }
return NOOP
}
function exec(
commandString: string,
options?: any,
cb?: (error: any | null, result: { stdout: string; stderr: string } | null) => void
): void {
if (typeof options === 'function' && cb === undefined) {
cb = options
options = {}
}
pExec(commandString, options)
.then((result) => cb?.(null, result))
.catch((err) => cb?.(err, null))
}
child_process.exec = exec

const allProcesses: SpawnedProcess[] = []
let mockOnNewProcessClb: null | ((process: SpawnedProcess) => void) = null
function spawn(command: string, args: string[] = []) {
const spawned = new SpawnedProcess(command, args)
mockOnNewProcessClb?.(spawned)
allProcesses.push(spawned)

spawned.on('exit', () => {
const index = allProcesses.indexOf(spawned)
allProcesses.splice(index, 1)
})
return spawned
}
child_process.spawn = spawn

function mockOnNewProcess(clb: (process: SpawnedProcess) => void) {
mockOnNewProcessClb = clb
}
child_process.mockOnNewProcess = mockOnNewProcess

function mockListAllProcesses(): SpawnedProcess[] {
return allProcesses
}
child_process.mockListAllProcesses = mockListAllProcesses

function mockClearAllProcesses(): void {
allProcesses.length = 0
}
child_process.mockClearAllProcesses = mockClearAllProcesses

class SpawnedProcess extends EventEmitter {
public stdout = new EventEmitter()
public stderr = new EventEmitter()
public pid: number

constructor(public command: string, public args: string[]) {
super()
this.pid = Date.now()
}

kill() {
this.emit('exit')
this.stdout.emit('end')
this.stderr.emit('end')
return true
}
}

module.exports = child_process
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import {
AppContainerWorkerAgent,
AdapterServerOptions,
LogLevel,
Expectation,
ReturnTypeDoYouSupportExpectation,
PackageContainerExpectation,
AppContainerId,
WorkerAgentId,
} from '@sofie-package-manager/api'

export class WorkerAgentAPI implements AppContainerWorkerAgent.WorkerAgent {
constructor(
public id: AppContainerId,
methods: AppContainerWorkerAgent.AppContainer,
_options: AdapterServerOptions<AppContainerWorkerAgent.WorkerAgent>
) {
WorkerAgentAPI.mockAppContainer[methods.id] = methods
}

public static mockAppContainer: Record<WorkerAgentId, AppContainerWorkerAgent.AppContainer> = {}

public static mockReset(): void {
WorkerAgentAPI.mockAppContainer = {}
}

type = ''

async setLogLevel(_logLevel: LogLevel): Promise<void> {
return
}
async _debugKill(): Promise<void> {
return
}
async doYouSupportExpectation(_exp: Expectation.Any): Promise<ReturnTypeDoYouSupportExpectation> {
return {
support: true,
}
}
async doYouSupportPackageContainer(
_packageContainer: PackageContainerExpectation
): Promise<ReturnTypeDoYouSupportExpectation> {
return {
support: true,
}
}
async setSpinDownTime(_spinDownTime: number): Promise<void> {
return
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { AppContainerId, LoggerInstance, WorkForceAppContainer } from '@sofie-package-manager/api'
import { EventEmitter } from 'events'

export class WorkforceAPI extends EventEmitter implements WorkForceAppContainer.WorkForce {
constructor(public id: AppContainerId, _loger: LoggerInstance) {
super()
}

connected = false
public static mockAvailableApps: AppDesc[] = []
public static mockMethods: Record<string, (...args: any[]) => Promise<void>> = {}

registerAvailableApps = async (availableApps: AppDesc[]): Promise<void> => {
WorkforceAPI.mockAvailableApps = availableApps
return
}
init = async (_connectionOptions: any, methods: any) => {
WorkforceAPI.mockMethods = methods
this.connected = true
setImmediate(() => {
this.emit('connected')
})
}

terminate = () => {
this.emit('disconnected')
}
}

type AppDesc = { appType: `@@protectedString/AppType/${string}` }
Loading

0 comments on commit 3919c0d

Please sign in to comment.