Skip to content

Commit

Permalink
refactor(clientreplay): split command up into run and command itself
Browse files Browse the repository at this point in the history
  • Loading branch information
bobvanderlinden committed May 24, 2020
1 parent d616903 commit 162f703
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/clientreplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ const { transformRequest } = require("./transform");
const { createCommandAction } = require("./command-utils");
const http = require("http");

async function clientreplay({ input, record, ...options }) {
async function run({ inputHar, ...options }) {
const agent = new http.Agent({ keepAlive: true });
const har = await readHarFile(input);
const recordedEntries = [];
for (const entry of har.log.entries) {
for (const entry of inputHar.log.entries) {
const readHarRequest = entry.request;
log.debug("Read request", { readHarRequest });
const outgoingHarRequest = transformRequest(readHarRequest, options);
Expand All @@ -25,7 +24,13 @@ async function clientreplay({ input, record, ...options }) {
})
);
}
await writeHarFile(record, createHar({ entries: recordedEntries }));
return createHar({ entries: recordedEntries });
}

async function runCommand({ input, record, ...options }) {
const inputHar = await readHarFile(input);
const result = await run({ inputHar, ...options });
await writeHarFile(record, result);
}

function defineCommand(program) {
Expand All @@ -38,10 +43,11 @@ function defineCommand(program) {
.requiredOption("--record <har_file>")
.option("--replace-hostname <new_hostname>")
.option("--replace-port <new_port>")
.action(createCommandAction(clientreplay));
.action(createCommandAction(runCommand));
}

module.exports = {
clientreplay,
run,
runCommand,
defineCommand,
};

0 comments on commit 162f703

Please sign in to comment.