Skip to content

Commit

Permalink
test(CLI Onboarding): Cover dev mode feed step (#11848)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danwakeem committed Mar 21, 2023
1 parent 9c7e5b4 commit 69581cb
Show file tree
Hide file tree
Showing 2 changed files with 408 additions and 14 deletions.
36 changes: 22 additions & 14 deletions lib/cli/interactive-setup/console-dev-mode-feed.js
Expand Up @@ -71,7 +71,7 @@ const handleSocketMessage = (context) => (data) => {
}
process.stdout.write(`${colorize(JSON.stringify(parsedBody, null, 2), jsonColors)}\n`);
} catch (error) {
process.stdout.write(chalk.grey.bold(`${str}${str.endsWith('\n') ? '' : '\n'}`));
process.stdout.write(chalk.grey(`${str}${str.endsWith('\n') ? '' : '\n'}`));
}
};

Expand All @@ -88,11 +88,11 @@ const handleSocketMessage = (context) => (data) => {
);
if (verbose) {
if (activity.input) {
process.stdout.write(headerChalk.bold('Input\n'));
process.stdout.write(headerChalk('Input\n'));
tryPrintJSON(activity.input);
}
if (activity.output) {
process.stdout.write(headerChalk.bold('Output\n'));
process.stdout.write(headerChalk('Output\n'));
tryPrintJSON(activity.output);
}
}
Expand Down Expand Up @@ -172,17 +172,6 @@ const startDevModeFeed = async (context, devModeFeedConnection) =>
}, 1000 * 60 * 60 * 1.5); // Check for activity every 1.5 hours

let stillWorkingTimer = createStillWorkingTimeout();
const watchStream = (feed) => {
feed.on('message', (data) => {
// Ignore connection message
const parsedData = JSON.parse(data.toString('utf-8'));
if (!parsedData.resetThrottle) {
clearTimeout(stillWorkingTimer);
stillWorkingTimer = createStillWorkingTimeout();
}
});
};
watchStream(devModeFeedConnection);

const connectionRefreshTimer = setInterval(async () => {
const newConnection = await connectToWebSocket({
Expand Down Expand Up @@ -219,6 +208,25 @@ const startDevModeFeed = async (context, devModeFeedConnection) =>
consoleMonitoringCounter.responses = 0;
consoleMonitoringCounter.events = 0;
}, 1000 * 60); // Publish every 60 seconds

const watchStream = (feed) => {
feed.on('message', (data) => {
// Ignore connection message
const parsedData = JSON.parse(data.toString('utf-8'));
if (!parsedData.resetThrottle) {
clearTimeout(stillWorkingTimer);
stillWorkingTimer = createStillWorkingTimeout();
}
});
feed.on('close', () => {
// Clean up if we receive a close event
clearInterval(eventPublishTimer);
clearInterval(connectionRefreshTimer);
clearTimeout(stillWorkingTimer);
resolve();
});
};
watchStream(devModeFeedConnection);
});

module.exports = {
Expand Down

0 comments on commit 69581cb

Please sign in to comment.