diff --git a/src/target/file.ts b/src/target/file.ts index a1b1df9..d305578 100644 --- a/src/target/file.ts +++ b/src/target/file.ts @@ -28,7 +28,6 @@ export class FileTarget extends Target { async send(message: Message) { std.log('file target sending', {message}) - await files.createFile(this.options.file) await files.appendFile(this.options.file, message.toString() + '\n') std.log('file target sent') } diff --git a/src/utils/files.ts b/src/utils/files.ts index 3e615a1..efdd961 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -67,7 +67,7 @@ export function loadYAML(file: string) { } export async function createFile(file: string) { - const handle = await fs.promises.open(path.resolve(file), 'w+') + const handle = await fs.promises.open(path.resolve(file), 'a+') await handle.close() } diff --git a/src/utils/hae.ts b/src/utils/hae.ts index 87d8427..84908b6 100644 --- a/src/utils/hae.ts +++ b/src/utils/hae.ts @@ -11,8 +11,8 @@ function exit(fn: (args: T) => Promise): (args: T) => Promise { return async (options: T) => { try { await fn(options) - } catch (e) { - std.log(e) + } catch (error) { + std.log({error}) process.exit(1) } } @@ -22,8 +22,8 @@ function log(fn: (args: T) => Promise): (args: T) => Promise { return async (args: T) => { try { await fn(args) - } catch (e) { - std.log(e) + } catch (error) { + std.log({error}) } } } @@ -31,8 +31,8 @@ function log(fn: (args: T) => Promise): (args: T) => Promise { async function _try(fn: () => Promise, reason?: string) { try { await fn() - } catch (e) { - std.log(reason, e) + } catch (error) { + std.log(reason, {error}) } } diff --git a/tests/bidirectional/bidirectional.test.ts b/tests/bidirectional/bidirectional.test.ts deleted file mode 100644 index 739a8b8..0000000 --- a/tests/bidirectional/bidirectional.test.ts +++ /dev/null @@ -1,91 +0,0 @@ -import actions from '#actions' -import Message, {CANMessage} from '#core/message' -import * as files from '#files' -import std from '#std' -import * as utils from '#utils' -import {expect} from 'chai' -import {afterEach} from 'mocha' -import * as can from 'socketcan' - -describe('bidirectional', () => { - const can2xA = 'can2xBixA' - const can2xB = 'can2xBixB' - - beforeEach(async () => { - try { - await actions.vcan.start({ - name: can2xA, - }) - await actions.vcan.start({ - name: can2xB, - }) - } catch (error) { - std.log('vcan not created', {error}) - } - }) - - it('bidirectional', async () => { - const request = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) - const response = Message.fromJSON({id: 42, data: [4, 5, 6], ext: false, rtr: false}) - const output = files.temporary() - - // Receives "message" and returns "answer" - const receiver = can.createRawChannel(can2xB) - receiver.addListener('onMessage', function (message: CANMessage) { - std.log('receiver received', {message}) - expect(Message.fromCAN(message).toString()).to.equal(request.toString()) - receiver.send(response.toCAN()) - }) - receiver.start() - - // Start can source with file target - const bridge = await actions.bridge.start({ - source: 'can', - sourceName: can2xA, - target: 'can', - targetName: can2xB, - }) - - // Send message using console source and can target - const logger = await actions.bridge.start({ - source: 'can', - sourceName: can2xA, - target: 'file', - targetFile: output, - }) - - // Send message using console source and can target - const sender = await actions.bridge.start({ - source: 'console', - sourceId: String(request.id), - sourceData: request.data.map(String), - sourceExt: request.ext, - sourceRtr: request.rtr, - target: 'can', - targetName: can2xA, - }) - - std.log('waiting for message being bridged') - await utils.sleep(250) - - expect(files.loadFile(output).trim().split('\n')).to.deep.equal([request.toString(), response.toString()]) - - await files.deleteFile(output) - await sender.stop() - await logger.stop() - await bridge.stop() - }) - - afterEach(async () => { - try { - await actions.vcan.stop({ - name: can2xA, - }) - await actions.vcan.stop({ - name: can2xB, - }) - } catch (error) { - std.log('vcan not stopped', {error}) - } - }) -}) diff --git a/tests/bridge/can.test.ts b/tests/bridge/can.test.ts new file mode 100644 index 0000000..3fa80e3 --- /dev/null +++ b/tests/bridge/can.test.ts @@ -0,0 +1,13 @@ +import {createBidirectionalBridgeTest, createBridgeTest} from './utils' + +describe('bridge', () => { + createBidirectionalBridgeTest( + 'can', + {source: 'can', sourceName: 'can2xBridge'}, + {target: 'can', targetName: 'can2xBridge'} + ) +}) + +describe('bridge', () => { + createBridgeTest('can', {source: 'can'}, {target: 'can'}) +}) diff --git a/tests/bridge/can/can-file.sh b/tests/bridge/can/can-file.sh deleted file mode 100644 index 8599263..0000000 --- a/tests/bridge/can/can-file.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env bash -set -e - -yarn cli vcan start -yarn cli bridge start --source can --target file --target-file out.txt \ No newline at end of file diff --git a/tests/bridge/can/can.test.ts b/tests/bridge/can/can.test.ts deleted file mode 100644 index 7acd2c3..0000000 --- a/tests/bridge/can/can.test.ts +++ /dev/null @@ -1,64 +0,0 @@ -import actions from '#actions' -import Message from '#core/message' -import * as files from '#files' -import std from '#std' -import * as utils from '#utils' -import {expect} from 'chai' -import {afterEach} from 'mocha' - -describe('can', () => { - const vcan = 'can2x' - - beforeEach(async () => { - try { - await actions.vcan.start({ - name: vcan, - }) - } catch (error) { - std.log('vcan not created', {error}) - } - }) - - it('source-target', async () => { - const message = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) - const output = files.temporary() - - // Start can source with file target - const source = await actions.bridge.start({ - source: 'can', - sourceName: vcan, - target: 'file', - targetFile: output, - }) - - // Send message using console source and can target - const target = await actions.bridge.start({ - source: 'console', - sourceId: String(message.id), - sourceData: message.data.map(String), - sourceExt: message.ext, - sourceRtr: message.rtr, - target: 'can', - targetName: vcan, - }) - - std.log('waiting for message being bridged') - await utils.sleep(25) - - expect(files.loadFile(output).trim()).to.equal(message.toString()) - - await files.deleteFile(output) - await target.stop() - await source.stop() - }) - - afterEach(async () => { - try { - await actions.vcan.stop({ - name: vcan, - }) - } catch (error) { - std.log('vcan not stopped', {error}) - } - }) -}) diff --git a/tests/bridge/can/console-can.sh b/tests/bridge/can/console-can.sh deleted file mode 100644 index bcd8c59..0000000 --- a/tests/bridge/can/console-can.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -yarn cli bridge start --source console --source-id 0x10 --source-data 0x5 5 --target can --target-name can2x \ No newline at end of file diff --git a/tests/bridge/console/send.sh b/tests/bridge/console/send.sh deleted file mode 100644 index a7ba52c..0000000 --- a/tests/bridge/console/send.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -yarn cli bridge start --source console --source-id 0x10 --source-data 0x5 5 --target console \ No newline at end of file diff --git a/tests/bridge/file/file.test.ts b/tests/bridge/file.test.ts similarity index 98% rename from tests/bridge/file/file.test.ts rename to tests/bridge/file.test.ts index 03b6d21..87bbf0b 100644 --- a/tests/bridge/file/file.test.ts +++ b/tests/bridge/file.test.ts @@ -5,7 +5,7 @@ import std from '#std' import * as utils from '#utils' import {expect} from 'chai' -describe('file', () => { +describe('bridge', () => { it('file2file', async () => { const message = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) diff --git a/tests/bridge/file/send.sh b/tests/bridge/file/send.sh deleted file mode 100644 index 411f340..0000000 --- a/tests/bridge/file/send.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -yarn cli bridge start --source console --source-id 0x10 --source-data 0x5 5 --target file --target-file out.txt \ No newline at end of file diff --git a/tests/bridge/http.test.ts b/tests/bridge/http.test.ts new file mode 100644 index 0000000..1147189 --- /dev/null +++ b/tests/bridge/http.test.ts @@ -0,0 +1,12 @@ +import {createBridgeTest} from './utils' + +describe('bridge', () => { + createBridgeTest( + 'http', + {source: 'http'}, + { + target: 'http', + targetEndpoint: 'http://localhost:3000', + } + ) +}) diff --git a/tests/bridge/http/http.test.ts b/tests/bridge/http/http.test.ts deleted file mode 100644 index a644037..0000000 --- a/tests/bridge/http/http.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import actions from '#actions' -import Message from '#core/message' -import * as files from '#files' -import std from '#std' -import * as utils from '#utils' -import {expect} from 'chai' - -describe('http', () => { - it('source-target', async () => { - const message = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) - const output = files.temporary() - const port = 2999 - - // Start http source with file target - const source = await actions.bridge.start({ - source: 'http', - sourcePort: String(port), - target: 'file', - targetFile: output, - }) - - // Send message using console source and http target - const target = await actions.bridge.start({ - source: 'console', - sourceId: String(message.id), - sourceData: message.data.map(String), - target: 'http', - targetEndpoint: `http://localhost:${port}`, - }) - - std.log('waiting for message being bridged') - await utils.sleep(25) - - expect(files.loadFile(output).trim()).to.equal(message.toString()) - - await files.deleteFile(output) - await target.stop() - await source.stop() - }) -}) diff --git a/tests/bridge/http/send.sh b/tests/bridge/http/send.sh deleted file mode 100644 index f3cfa58..0000000 --- a/tests/bridge/http/send.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -curl -X POST -H "Content-Type: application/json" localhost:3000 --data '{"id": 1, "data": [1, 2, 3]}' \ No newline at end of file diff --git a/tests/bridge/mqtt.test.ts b/tests/bridge/mqtt.test.ts new file mode 100644 index 0000000..d7fab24 --- /dev/null +++ b/tests/bridge/mqtt.test.ts @@ -0,0 +1,28 @@ +import {createBidirectionalBridgeTest, createBridgeTest} from './utils' + +// TODO: mqtt returns to original sender ... (similar but not same bug as at mqtt bus) +describe.skip('bridge', () => { + createBidirectionalBridgeTest( + 'mqtt', + { + source: 'mqtt', + }, + { + target: 'mqtt', + targetEndpoint: 'mqtt://localhost:3000', + } + ) +}) + +describe('bridge', () => { + createBridgeTest( + 'mqtt', + { + source: 'mqtt', + }, + { + target: 'mqtt', + targetEndpoint: 'mqtt://localhost:3000', + } + ) +}) diff --git a/tests/bridge/mqtt/console-mqtt.sh b/tests/bridge/mqtt/console-mqtt.sh deleted file mode 100644 index 9cbe5cc..0000000 --- a/tests/bridge/mqtt/console-mqtt.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -yarn cli bridge start --source console --source-id 0x10 --source-data 0x5 5 --target mqtt --target-endpoint mqtt://localhost:3000 \ No newline at end of file diff --git a/tests/bridge/mqtt/mqtt-file.sh b/tests/bridge/mqtt/mqtt-file.sh deleted file mode 100644 index aa8fa52..0000000 --- a/tests/bridge/mqtt/mqtt-file.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -yarn cli bridge start --source mqtt --source-port 3000 --target file --target-file out.txt \ No newline at end of file diff --git a/tests/bridge/mqtt/mqtt.test.ts b/tests/bridge/mqtt/mqtt.test.ts deleted file mode 100644 index 903cc3c..0000000 --- a/tests/bridge/mqtt/mqtt.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import actions from '#actions' -import Message from '#core/message' -import * as files from '#files' -import std from '#std' -import * as utils from '#utils' -import {expect} from 'chai' - -describe('mqtt', () => { - it('source-target', async () => { - const message = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) - const output = files.temporary() - const port = 3000 - - // Start mqtt source with file target - const source = await actions.bridge.start({ - source: 'mqtt', - sourcePort: String(port), - target: 'file', - targetFile: output, - }) - - // Send message using console source and mqtt target - const target = await actions.bridge.start({ - source: 'console', - sourceId: String(message.id), - sourceData: message.data.map(String), - target: 'mqtt', - targetEndpoint: `mqtt://localhost:${port}`, - }) - - std.log('waiting for message being bridged') - await utils.sleep(25) - - expect(files.loadFile(output).trim()).to.equal(message.toString()) - - await files.deleteFile(output) - await target.stop() - await source.stop() - }) -}) diff --git a/tests/bridge/socketio.test.ts b/tests/bridge/socketio.test.ts new file mode 100644 index 0000000..414940a --- /dev/null +++ b/tests/bridge/socketio.test.ts @@ -0,0 +1,27 @@ +import {createBidirectionalBridgeTest, createBridgeTest} from './utils' + +describe('bridge', () => { + createBidirectionalBridgeTest( + 'socketio', + { + source: 'socketio', + }, + { + target: 'socketio', + targetEndpoint: 'http://localhost:3000', + } + ) +}) + +describe('bridge', () => { + createBridgeTest( + 'socketio', + { + source: 'socketio', + }, + { + target: 'socketio', + targetEndpoint: 'http://localhost:3000', + } + ) +}) diff --git a/tests/bridge/socketio/console-socketio.sh b/tests/bridge/socketio/console-socketio.sh deleted file mode 100644 index 26e6ab1..0000000 --- a/tests/bridge/socketio/console-socketio.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -yarn cli bridge start --source console --source-id 0x10 --source-data 0x5 5 --target socketio --target-endpoint http://localhost:3000 \ No newline at end of file diff --git a/tests/bridge/socketio/socketio-file.sh b/tests/bridge/socketio/socketio-file.sh deleted file mode 100644 index b408c84..0000000 --- a/tests/bridge/socketio/socketio-file.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -set -e - -yarn cli bridge start --source socketio --target file --target-file out.txt \ No newline at end of file diff --git a/tests/bridge/socketio/socketio.test.ts b/tests/bridge/socketio/socketio.test.ts deleted file mode 100644 index fc5fb0d..0000000 --- a/tests/bridge/socketio/socketio.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -import actions from '#actions' -import Message from '#core/message' -import * as files from '#files' -import std from '#std' -import * as utils from '#utils' -import {expect} from 'chai' - -describe('socketio', () => { - it('source-target', async () => { - const message = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) - const output = files.temporary() - const port = 3001 - - // Start socketio source with file target - // TODO: if an error is thrown then the test does not abort ... - const source = await actions.bridge.start({ - source: 'socketio', - sourcePort: String(port), - target: 'file', - targetFile: output, - }) - - // Send message using console source and socketio target - const target = await actions.bridge.start({ - source: 'console', - sourceId: String(message.id), - sourceData: message.data.map(String), - target: 'socketio', - targetEndpoint: `http://localhost:${port}`, - }) - - std.log('waiting for message being bridged') - await utils.sleep(25) - - expect(files.loadFile(output).trim()).to.equal(message.toString()) - - await files.deleteFile(output) - await target.stop() - await source.stop() - }) -}) diff --git a/tests/bridge/utils.ts b/tests/bridge/utils.ts new file mode 100644 index 0000000..6ed5474 --- /dev/null +++ b/tests/bridge/utils.ts @@ -0,0 +1,163 @@ +import {BridgeSourceOptions, BridgeTargetOptions} from '#/actions/start-bridge' +import actions from '#actions' +import Message, {CANMessage} from '#core/message' +import * as files from '#files' +import std from '#std' +import * as utils from '#utils' +import hae from '#utils/hae' +import {expect} from 'chai' +import {afterEach} from 'mocha' +import * as can from 'socketcan' + +export function createBridgeTest( + name: string, + bridgeSourceOptions: BridgeSourceOptions, + bridgeTargetOptions: BridgeTargetOptions +) { + return describe(name, () => { + beforeEach(async () => { + await hae.try(async () => { + await actions.vcan.start({}) + }, `problem when creating vcan`) + }) + + it(name, async () => { + const message = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) + const output = files.temporary() + + // Start can source with file target + const bridge = await actions.bridge.start({ + ...bridgeSourceOptions, + target: 'file', + targetFile: output, + }) + + // Send message using console source and can target + const sender = await actions.bridge.start({ + source: 'console', + sourceId: String(message.id), + sourceData: message.data.map(String), + sourceExt: message.ext, + sourceRtr: message.rtr, + ...bridgeTargetOptions, + }) + + std.log('waiting for message being bridged') + await utils.sleep(25) + + const result = files.loadFile(output).trim() + const expected = message.toString() + std.log({result, expected}) + expect(result).to.equal(expected) + + await files.deleteFile(output) + await sender.stop() + await bridge.stop() + }) + + afterEach(async () => { + await hae.try(async () => { + await actions.vcan.stop({}) + }, `problem when stopping vcan`) + }) + }) +} + +/** + * sender --(can2xSender)--> source <----> target <--(can2xReceiver)--> receiver + * logger <------┘ + */ +export function createBidirectionalBridgeTest( + name: string, + bridgeSourceOptions: BridgeSourceOptions, + bridgeTargetOptions: BridgeTargetOptions +) { + return describe(name, () => { + const cans = ['can2xSender', 'can2xReceiver', 'can2xBridge'] + + beforeEach(async () => { + for (const can of cans) { + await hae.try(async () => { + await actions.vcan.start({name: can}) + }, `problem when creating vcan "${can}"`) + } + }) + + it(name, async () => { + const request = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) + const response = Message.fromJSON({id: 42, data: [4, 5, 6], ext: false, rtr: false}) + const output = files.temporary() + + // Receives "request" and returns "answer" + const receiver = can.createRawChannel(cans[1]) + receiver.addListener('onMessage', function (message: CANMessage) { + std.log('receiver received', {message}) + + std.log('ensuring that received message is request') + expect(Message.fromCAN(message).toString()).to.equal(request.toString()) + std.log('received message is request') + + std.log('ensuring that already logged message is request') + expect(files.loadFile(output).trim()).to.equal(request.toString()) + std.log('already logged message is request') + + receiver.send(response.toCAN()) + }) + receiver.start() + + const target = await actions.bridge.start({ + ...bridgeSourceOptions, + target: 'can', + targetName: cans[1], + }) + + const source = await actions.bridge.start({ + source: 'can', + sourceName: cans[0], + ...bridgeTargetOptions, + }) + + // Send message using console source and can target + const logger = await actions.bridge.start({ + source: 'can', + sourceName: cans[0], + target: 'file', + targetFile: output, + }) + + // Send message using console source and can target + const sender = await actions.bridge.start({ + source: 'console', + sourceId: String(request.id), + sourceData: request.data.map(String), + sourceExt: request.ext, + sourceRtr: request.rtr, + target: 'can', + targetName: cans[0], + }) + + std.log('waiting for message being bridged') + await utils.sleep(250) + + const result = files.loadFile(output).trim().split('\n') + const expected = [request.toString(), response.toString()] + std.log({result, expected}) + expect(result).to.deep.equal(expected) + + await files.deleteFile(output) + await sender.stop() + await logger.stop() + await source.stop() + await target.stop() + receiver.stop() + }) + + afterEach(async () => { + for (const can of cans) { + await hae.try(async () => { + await actions.vcan.stop({name: can}) + }, `problem when stopping vcan "${can}"`) + } + }) + }) +} diff --git a/tests/bridge/ws.test.ts b/tests/bridge/ws.test.ts new file mode 100644 index 0000000..4f5b1f5 --- /dev/null +++ b/tests/bridge/ws.test.ts @@ -0,0 +1,27 @@ +import {createBidirectionalBridgeTest, createBridgeTest} from './utils' + +describe('bridge', () => { + createBidirectionalBridgeTest( + 'websocket', + { + source: 'ws', + }, + { + target: 'ws', + targetEndpoint: 'ws://localhost:3000', + } + ) +}) + +describe('bridge', () => { + createBridgeTest( + 'websocket', + { + source: 'ws', + }, + { + target: 'ws', + targetEndpoint: 'ws://localhost:3000', + } + ) +}) diff --git a/tests/bridge/ws/ws.test.ts b/tests/bridge/ws/ws.test.ts deleted file mode 100644 index ce599ee..0000000 --- a/tests/bridge/ws/ws.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import actions from '#actions' -import Message from '#core/message' -import * as files from '#files' -import std from '#std' -import * as utils from '#utils' -import {expect} from 'chai' - -describe('websocket', () => { - it('source-target', async () => { - const message = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) - const output = files.temporary() - const port = 3002 - - // Start websocket source with file target - const source = await actions.bridge.start({ - source: 'ws', - sourcePort: String(port), - target: 'file', - targetFile: output, - }) - - // Send message using console source and websocket target - const target = await actions.bridge.start({ - source: 'console', - sourceId: String(message.id), - sourceData: message.data.map(String), - target: 'ws', - targetEndpoint: `ws://localhost:${port}`, - }) - - std.log('waiting for message being bridged') - await utils.sleep(25) - - expect(files.loadFile(output).trim()).to.equal(message.toString()) - - await files.deleteFile(output) - await target.stop() - await source.stop() - }) -}) diff --git a/tests/bus/ws.test.ts b/tests/bus/ws.test.ts index 11c7dc5..8539465 100644 --- a/tests/bus/ws.test.ts +++ b/tests/bus/ws.test.ts @@ -1,6 +1,6 @@ import {createBusTest} from './utils' -// TODO: message seems not to be published +// TODO: Uncaught ReferenceError: WebSocket is not defined describe.skip('bus', () => { createBusTest( 'ws', diff --git a/tests/bridge/complex/complex.test.ts b/tests/complex/complex.test.ts similarity index 64% rename from tests/bridge/complex/complex.test.ts rename to tests/complex/complex.test.ts index 231605d..e9005bb 100644 --- a/tests/bridge/complex/complex.test.ts +++ b/tests/complex/complex.test.ts @@ -3,6 +3,7 @@ import Message from '#core/message' import * as files from '#files' import std from '#std' import * as utils from '#utils' +import hae from '#utils/hae' import {expect} from 'chai' import {afterEach} from 'mocha' @@ -10,31 +11,23 @@ import {afterEach} from 'mocha' * console2can --(can2x1)--> can2socketio -> socketio2can --(can2x2)--> can2file */ describe('complex', () => { - beforeEach(async () => { - try { - await actions.vcan.start({ - name: 'can2x1', - }) - } catch (error) { - std.log('vcan "can2x1" not created', {error}) - } + const cans = ['can2x1', 'can2x2'] - try { - await actions.vcan.start({ - name: 'can2x2', - }) - } catch (error) { - std.log('vcan "can2x2" not created', {error}) + beforeEach(async () => { + for (const can of cans) { + await hae.try(async () => { + await actions.vcan.start({name: can}) + }, `problem when creating vcan "${can}"`) } }) - it('source-target', async () => { + it('complex', async () => { const message = Message.fromJSON({id: 69, data: [1, 2, 3], ext: false, rtr: false}) const output = files.temporary() const can2file = await actions.bridge.start({ source: 'can', - sourceName: 'can2x2', + sourceName: cans[1], target: 'file', targetFile: output, }) @@ -42,12 +35,12 @@ describe('complex', () => { const socketio2can = await actions.bridge.start({ source: 'socketio', target: 'can', - targetName: 'can2x2', + targetName: cans[1], }) const can2socketio = await actions.bridge.start({ source: 'can', - sourceName: 'can2x1', + sourceName: cans[0], target: 'socketio', targetEndpoint: 'http://localhost:3000', }) @@ -59,7 +52,7 @@ describe('complex', () => { sourceExt: message.ext, sourceRtr: message.rtr, target: 'can', - targetName: 'can2x1', + targetName: cans[0], }) std.log('waiting for message being bridged') @@ -75,20 +68,10 @@ describe('complex', () => { }) afterEach(async () => { - try { - await actions.vcan.stop({ - name: 'can2x1', - }) - } catch (error) { - std.log('vcan "can2x1" not stopped', {error}) - } - - try { - await actions.vcan.stop({ - name: 'can2x2', - }) - } catch (error) { - std.log('vcan "can2x" not stopped', {error}) + for (const can of cans) { + await hae.try(async () => { + await actions.vcan.stop({name: can}) + }, `problem when stopping vcan "${can}"`) } }) })