Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy test file mode #3

Merged
merged 3 commits into from
Nov 18, 2024
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
2 changes: 0 additions & 2 deletions .test/.gitignore

This file was deleted.

45 changes: 9 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# aitestgen

Generate testcases from natural language descriptions
Generate testcases from natural language descriptions.

A command-line tool that leverages AI to automatically generate test cases from natural language prompts. This tool helps developers quickly create comprehensive test suites by describing what they want to test in plain English.

Expand All @@ -16,44 +16,19 @@ yarn add -g aitestgen

## Usage

### Basic Command
Set OpenAI key

```bash
aitestgen [options] [prompt]
export OPENAI_API_KEY="<YOUR_KEY_HERE>"
```

### Options
Generate testsuite from test prompt file ([todo.xml](examples/testprompts/todo.xml))

```txt

Usage: index [options]

Generate test from prompting

Options:
-o, --out <path> Output path for generated test file (default: "app.test.ts")
-gd, --gendir <path> Directory to save generated cache (default: ".gen/")
-p, --provider <provider> Set model provider "openai" "ollama" (default: "openai")
-m, --model <model> Specify model to use (default: "gpt-4o-mini")
-oh, --ollamahost <url> Set Ollama endpoint (default: "http://localhost:11434")
-hl, --headless <bool> Set browser headless mode (default: true)
-t, --test Run test only (default: false)
-v, --verbose Verbose log (default: false)
-h, --help display help for command

```

### Examples

Generate new tests:
```bash
aitestgen -- go to http://localhost:3000 and fill the form then expect successful message
aitestgen gen -f examples/testprompts/todo.xml
```

Run generated tests using Vitest:
```bash
aitestgen --test
```
the generated output will be saved at `todo.testsuite.test.ts`

## Contributing

Expand All @@ -71,12 +46,12 @@ git clone https://github.com/wuttinanhi/aitestgen
yarn install
```

3. Run tests
3. Run project tests
```bash
yarn test
```

4. Link this package
4. Link this package to use locally
```bash
yarn link
```
Expand All @@ -87,10 +62,8 @@ yarn link
| Option | Description |
|--------|-------------|
| `start` | Start the program. |
| `test` | Test the specs |
| `gentest` | Test the generated code |
| `test` | Run project tests |
| `lint` | Lint codebase |
| `translate` | Translate test steps only |


## License
Expand Down
8 changes: 4 additions & 4 deletions examples/testprompts/todo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
<model>gpt-4o-mini</model>
<testcases>
<testcase>
<name>Should remove a todo</name>
<name>Should add a todo</name>
<prompt>
1. go to https://microsoftedge.github.io/Demos/demo-to-do/
2. add a todo "Cook Dinner"
3. expected added todo "Cook Dinner" in the list
4. remove added to do
5. expected empty to do list
</prompt>
</testcase>
<testcase>
<name>Should add a todo</name>
<name>Should remove a todo</name>
<prompt>
1. go to https://microsoftedge.github.io/Demos/demo-to-do/
2. add a todo "Cook Dinner"
3. expected added todo "Cook Dinner" in the list
4. remove added to do
5. expected empty to do list
</prompt>
</testcase>
</testcases>
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"author": "wuttinanhi",
"license": "MIT",
"type": "module",
"homepage": "https://github.com/wuttinanhi/aitestgen",
"repository": "https://github.com/wuttinanhi/aitestgen",
"npm.packageManager": "auto",
"bin": {
"aitestgen": "index.ts"
Expand Down Expand Up @@ -33,9 +35,7 @@
"start": "tsx index.ts",
"test": "vitest tests",
"gentest": "vitest run app.test.ts",
"lint": "tsc --noEmit --skipLibCheck --project tsconfig.json",
"translate": "tsx src/cmds/translate.ts",
"dev:quick": "tsx index.ts --verbose -- go to http://localhost:3000 and fill the form then expect successful message"
"lint": "tsc --noEmit --skipLibCheck --project tsconfig.json"
},
"devDependencies": {
"@types/node": "^22.9.0"
Expand Down
20 changes: 10 additions & 10 deletions src/cmds/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Command, createCommand } from "commander";
import { makeGenCommand, runGenMode } from "./gen.ts";
import { makePromptCommand, runPromptMode } from "./prompt.ts";
import { makeTestCommand, runTestMode } from "./test.ts";
import { addGenericOptions } from "./options.ts";
import { GenCommand } from "./gen.ts";
import { addGenericOptions } from "../helpers/cli.ts";
import { PromptCommand } from "./prompt.ts";
import { TestCommand } from "./test.ts";

export async function main() {
const program = new Command();
Expand All @@ -12,28 +12,28 @@ export async function main() {
This tool helps developers quickly create comprehensive test suites by describing what they want to test in plain English.`,
);

const promptCommand = makePromptCommand();
const promptCommand = new PromptCommand();
program.addCommand(promptCommand);

const genCommand = makeGenCommand();
const genCommand = new GenCommand();
program.addCommand(genCommand);

const testCommand = makeTestCommand();
const testCommand = new TestCommand();
program.addCommand(testCommand);

program.parse();

switch (program.args[0]) {
case "prompt":
promptCommand.parse();
runPromptMode(promptCommand.args, promptCommand.opts());
promptCommand.run();
break;
case "test":
runTestMode();
testCommand.run();
break;
case "gen":
genCommand.parse();
runGenMode(genCommand.args, genCommand.opts());
genCommand.run();
break;
default:
console.log("Unknown args:", program.args[0]);
Expand Down
Loading