Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-bravo-yahoo committed Nov 21, 2024
1 parent 0f26c94 commit 37670e0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 24 deletions.
44 changes: 26 additions & 18 deletions src/cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ function buildYargs(argvInput) {
// https://github.com/yargs/yargs/blob/main/docs/typescript.md?plain=1#L124
const yargsInstance = yargs(argvInput);

// these debug commands are used by the tests in environments where they can't mock out the command handler
if (
process.env.NODE_ENV !== "production" ||
process.env.DEBUG_COMMANDS === "true"
) {
yargsInstance
.command("throw", false, {
handler: () => {
throw new Error("this is a test error");
},
builder: {},
})
.command("reject", false, {
handler: async () => {
throw new Error("this is a rejected promise");
},
builder: {},
})
.command("warn", false, {
handler: async () => {
process.emitWarning("this is a warning emited on the node process");
},
builder: {},
});
}

return yargsInstance
.scriptName("fauna")
.middleware([checkForUpdates, logArgv], true)
Expand All @@ -74,24 +100,6 @@ function buildYargs(argvInput) {
.command(keyCommand)
.command(schemaCommand)
.command(databaseCommand)
.command("throw", false, {
handler: () => {
throw new Error("this is a test error");
},
builder: {},
})
.command("reject", false, {
handler: async () => {
throw new Error("this is a rejected promise");
},
builder: {},
})
.command("warn", false, {
handler: async () => {
process.emitWarning("this is a warning emited on the node process");
},
builder: {},
})
.demandCommand()
.strict(true)
.options({
Expand Down
20 changes: 14 additions & 6 deletions test/general-cli.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,21 @@ describe("cli operations", function () {
expect(notify).to.have.been.called;
});

it("does not expose debug commands in production", async function () {
const cliPath = path.resolve(__dirname, "../dist/cli.cjs");
const { stderr } = spawnSync(cliPath, ["throw"], {
encoding: "utf8",
timeout: 5000,
});

expect(stderr).to.include("Unknown argument: throw");
});

it("enables nodeJS warnings from the dev entrypoint", async function () {
const cliPath = path.resolve(__dirname, "../src/user-entrypoint.mjs");
let cli = spawnSync(cliPath, ["warn"], {
encoding: "utf8",
// input: "",
timeout: 5000,
// stdio: ["inherit", "pipe", "pipe"],
// shell: true,
});
if (cli.error) throw cli.error;
let stderr = cli.stderr;
Expand All @@ -149,10 +156,11 @@ describe("cli operations", function () {
const cliPath = path.resolve(__dirname, "../dist/cli.cjs");
let cli = spawnSync(cliPath, ["warn"], {
encoding: "utf8",
// input: "",
timeout: 5000,
// stdio: ["inherit", "pipe", "pipe"],
// shell: true,
env: {
...process.env,
DEBUG_COMMANDS: "true",
},
});
if (cli.error) throw cli.error;

Expand Down

0 comments on commit 37670e0

Please sign in to comment.