Skip to content

Commit 24e149f

Browse files
committed
feat: --serial-log-file arg
1 parent cb1952e commit 24e149f

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/help.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export function cliHelp() {
1111
{green --quiet}, {green -q} Quiet: do not print version or status messages
1212
{green --expect-text} <string> Expect the given text in the output
1313
{green --fail-text} <string> Fail if the given text is found in the output
14+
{green --serial-log-file} <string> Save the serial monitor output to the given file
1415
{green --screenshot-part} <string> Take a screenshot of the given part id (from diagram.json)
1516
{green --screenshot-time} <number> Time in simulation milliseconds to take the screenshot
1617
{green --screenshot-file} <string> File name to save the screenshot to (default: screenshot.png)

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import arg from 'arg';
22
import chalkTemplate from 'chalk-template';
3-
import { existsSync, readFileSync, writeFileSync } from 'fs';
3+
import { existsSync, readFileSync, writeFileSync, createWriteStream } from 'fs';
44
import path, { join } from 'path';
55
import YAML from 'yaml';
66
import { APIClient } from './APIClient.js';
@@ -28,6 +28,7 @@ async function main() {
2828
'--version': Boolean,
2929
'--expect-text': String,
3030
'--fail-text': String,
31+
'--serial-log-file': String,
3132
'--scenario': String,
3233
'--screenshot-part': String,
3334
'--screenshot-file': String,
@@ -43,6 +44,7 @@ async function main() {
4344
const quiet = args['--quiet'];
4445
const expectText = args['--expect-text'];
4546
const failText = args['--fail-text'];
47+
const serialLogFile = args['--serial-log-file'];
4648
const scenarioFile = args['--scenario'];
4749
const timeout = args['--timeout'] ?? 30000;
4850
const screenshotPart = args['--screenshot-part'];
@@ -126,6 +128,8 @@ async function main() {
126128
scenario.validate();
127129
}
128130

131+
const serialLogStream = serialLogFile ? createWriteStream(serialLogFile) : null;
132+
129133
if (expectText) {
130134
expectEngine.expectTexts.push(expectText);
131135
expectEngine.on('match', (text) => {
@@ -219,6 +223,8 @@ async function main() {
219223
for (const byte of bytes) {
220224
process.stdout.write(String.fromCharCode(byte));
221225
}
226+
227+
serialLogStream?.write(Buffer.from(bytes));
222228
expectEngine.feed(bytes);
223229
}
224230
if (event.event === 'chips:log') {

0 commit comments

Comments
 (0)