Skip to content

Commit

Permalink
feat: --serial-log-file arg
Browse files Browse the repository at this point in the history
  • Loading branch information
urish committed Sep 30, 2023
1 parent cb1952e commit 24e149f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function cliHelp() {
{green --quiet}, {green -q} Quiet: do not print version or status messages
{green --expect-text} <string> Expect the given text in the output
{green --fail-text} <string> Fail if the given text is found in the output
{green --serial-log-file} <string> Save the serial monitor output to the given file
{green --screenshot-part} <string> Take a screenshot of the given part id (from diagram.json)
{green --screenshot-time} <number> Time in simulation milliseconds to take the screenshot
{green --screenshot-file} <string> File name to save the screenshot to (default: screenshot.png)
Expand Down
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import arg from 'arg';
import chalkTemplate from 'chalk-template';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { existsSync, readFileSync, writeFileSync, createWriteStream } from 'fs';
import path, { join } from 'path';
import YAML from 'yaml';
import { APIClient } from './APIClient.js';
Expand Down Expand Up @@ -28,6 +28,7 @@ async function main() {
'--version': Boolean,
'--expect-text': String,
'--fail-text': String,
'--serial-log-file': String,
'--scenario': String,
'--screenshot-part': String,
'--screenshot-file': String,
Expand All @@ -43,6 +44,7 @@ async function main() {
const quiet = args['--quiet'];
const expectText = args['--expect-text'];
const failText = args['--fail-text'];
const serialLogFile = args['--serial-log-file'];
const scenarioFile = args['--scenario'];
const timeout = args['--timeout'] ?? 30000;
const screenshotPart = args['--screenshot-part'];
Expand Down Expand Up @@ -126,6 +128,8 @@ async function main() {
scenario.validate();
}

const serialLogStream = serialLogFile ? createWriteStream(serialLogFile) : null;

if (expectText) {
expectEngine.expectTexts.push(expectText);
expectEngine.on('match', (text) => {
Expand Down Expand Up @@ -219,6 +223,8 @@ async function main() {
for (const byte of bytes) {
process.stdout.write(String.fromCharCode(byte));
}

serialLogStream?.write(Buffer.from(bytes));
expectEngine.feed(bytes);
}
if (event.event === 'chips:log') {
Expand Down

0 comments on commit 24e149f

Please sign in to comment.