Skip to content

Commit

Permalink
fix append
Browse files Browse the repository at this point in the history
  • Loading branch information
milesstoetzner committed Sep 22, 2023
1 parent 49d4623 commit 0fb523a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/target/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function loadYAML<T>(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()
}

Expand Down
3 changes: 2 additions & 1 deletion tests/bridge/socketio.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import {createBidirectionalBridgeTest, createBridgeTest} from './utils'

// TODO: make this work
describe.skip('bridge', () => {
// The logger claims to have written 69 into output file but at the end only 42 is present
describe('bridge', () => {
createBidirectionalBridgeTest(
'socketio',
{
Expand Down
13 changes: 11 additions & 2 deletions tests/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function createBridgeTest(
}

/**
* sender --(can2xSender)--> source <--(can2xBridge)--> target <--(can2xReceiver)--> receiver
* sender --(can2xSender)--> source <----> target <--(can2xReceiver)--> receiver
* logger <------┘
*/
export function createBidirectionalBridgeTest(
Expand Down Expand Up @@ -92,7 +92,15 @@ export function createBidirectionalBridgeTest(
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()
Expand Down Expand Up @@ -139,8 +147,9 @@ export function createBidirectionalBridgeTest(
await files.deleteFile(output)
await sender.stop()
await logger.stop()
await target.stop()
await source.stop()
await target.stop()
receiver.stop()
})

afterEach(async () => {
Expand Down

0 comments on commit 0fb523a

Please sign in to comment.