Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
"devDependencies": {
"@changesets/cli": "^2.29.4",
"@types/node": "^22.14.1",
"@clack/prompts": "^0.11.0",
"@types/yargs": "^17.0.33",
"standard-version": "^9.5.0",
"typescript": "^5.8.3",
"vite": "^6.3.2",
"vitest": "^3.1.1"
"vitest": "^3.1.1",
"yargs": "^18.0.0"
}
}
16 changes: 16 additions & 0 deletions packages/clifty/test/inOut.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { describe, it, expect } from "vitest";
import { KEYS, withEnv } from "../src";

describe("Simple input and output", () => {
it("exits with a success code", async () => {
const result = await withEnv({})
.defineInteraction()
.expectOutput("This is a simple flow for testing input and output")
.whenAsked("What is your name?")
.respondWith("John", KEYS.ENTER)
.expectOutput("Hello John")
.run("node test/testcli/bin.mjs inOut");

expect(result).toBe(0);
});
});
114 changes: 57 additions & 57 deletions packages/clifty/test/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,60 +190,60 @@ describe("NPM init with steps in defineInteraction", async () => {
});
});

// describe.skip("NPM help", async () => {
// const tmpDir = tmpdir();

// const exitCode = await withEnv({
// cwd: tmpDir,
// })
// .defineInteraction()
// .expectOutput(
// `npm <command>

// Usage:

// npm install install all the dependencies in your project
// npm install <foo> add the <foo> dependency to your project
// npm test run this project's tests
// npm run <foo> run the script named <foo>
// npm <command> -h quick help on <command>
// npm -l display usage info for all commands
// npm help <term> search for help on <term>
// npm help npm more involved overview

// All commands:

// access, adduser, audit, bugs, cache, ci, completion,
// config, dedupe, deprecate, diff, dist-tag, docs, doctor,
// edit, exec, explain, explore, find-dupes, fund, get, help,
// help-search, hook, init, install, install-ci-test,
// install-test, link, ll, login, logout, ls, org, outdated,
// owner, pack, ping, pkg, prefix, profile, prune, publish,
// query, rebuild, repo, restart, root, run-script, sbom,
// search, set, shrinkwrap, star, stars, start, stop, team,
// test, token, uninstall, unpublish, unstar, update, version,
// view, whoami`
// )
// .run("npm --help");

// it("terminates with error", () => {
// // interestingly, npm --help terminates with an error code (TIL)
// expect(exitCode).toBe(1);
// });
// });

// describe.skip("NPM version", async () => {
// const tmpDir = tmpdir();

// const exitCode = await withEnv({
// cwd: tmpDir,
// })
// .defineInteraction(({ expectOutput }) => {
// expectOutput("10");
// })
// .run("npm --version");

// it("terminates successfully", () => {
// expect(exitCode).toBe(0);
// });
// });
describe("NPM help", async () => {
const tmpDir = tmpdir();

const exitCode = await withEnv({
cwd: tmpDir,
})
.defineInteraction()
.expectOutput(
`npm <command>

Usage:

npm install install all the dependencies in your project
npm install <foo> add the <foo> dependency to your project
npm test run this project's tests
npm run <foo> run the script named <foo>
npm <command> -h quick help on <command>
npm -l display usage info for all commands
npm help <term> search for help on <term>
npm help npm more involved overview

All commands:

access, adduser, audit, bugs, cache, ci, completion,
config, dedupe, deprecate, diff, dist-tag, docs, doctor,
edit, exec, explain, explore, find-dupes, fund, get, help,
help-search, hook, init, install, install-ci-test,
install-test, link, ll, login, logout, ls, org, outdated,
owner, pack, ping, pkg, prefix, profile, prune, publish,
query, rebuild, repo, restart, root, run-script, sbom,
search, set, shrinkwrap, star, stars, start, stop, team,
test, token, uninstall, unpublish, unstar, update, version,
view, whoami`
)
.run("npm --help");

it("terminates with error", () => {
// interestingly, npm --help terminates with an error code (TIL)
expect(exitCode).toBe(1);
});
});

describe("NPM version", async () => {
const tmpDir = tmpdir();

const exitCode = await withEnv({
cwd: tmpDir,
})
.defineInteraction(({ expectOutput }) => {
expectOutput("10");
})
.run("npm --version");

it("terminates successfully", () => {
expect(exitCode).toBe(0);
});
});
12 changes: 12 additions & 0 deletions packages/clifty/test/testcli/bin.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import yargs from "yargs";
import { execute as executeInOut } from "./inOut.mjs";

yargs(process.argv.slice(2))
.command("inOut", "test input and output", () => {
executeInOut();
})
.parse();

// executeInOut();

// console.log(args);
19 changes: 19 additions & 0 deletions packages/clifty/test/testcli/inOut.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as clack from "@clack/prompts";

export async function execute(args) {
clack.intro("InOut");
clack.note("This is a simple flow for testing input and output");

const name = await clack.text({
message: "What is your name?",
placeholder: "Enter your name",
});

if (clack.isCancel(name)) {
clack.cancel("Goodbye");
}

clack.log.success(`Hello ${name}`);

clack.outro("Goodbye");
}
Loading