A scenario-based API flow testing tool built with Deno.
注意: このプロジェクトは現在開発中のため、使用には注意してください。 Note: This project is currently under development. Use with caution.
First, install Deno:
curl -fsSL https://deno.land/install.sh | shAdd the library to your project's deno.json:
{
"imports": {
"scenario-flow": "https://raw.githubusercontent.com/u-na-gi/scenario-flow/main/scenario-flow/mod.ts"
}
}Install the CLI tool globally:
deno install --global -A -n sfcli https://raw.githubusercontent.com/u-na-gi/scenario-flow/main/scenario-flow-cli/main.tsCreate a scenario file (e.g., login.sf.ts):
import { ScenarioFlow } from "scenario-flow";
export const login = new ScenarioFlow({
apiBaseUrl: "http://localhost:3000/",
}).step(async (ctx) => {
const res = await ctx.fetcher({
method: "POST",
urlPaths: ["login"],
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: "testuser",
password: "password",
}),
});
if (res.ok) {
const data = await res.json();
console.log("Login successful:", data);
ctx.addContext("token", data.token);
}
});
if (import.meta.main) {
await login.execute();
}The CLI tool automatically finds and executes all .sf.ts files in a directory:
# Show help
sfcli -h
# Run all .sf.ts files in current directory
sfcli .
# Run all .sf.ts files in specified directory
sfcli ./scenarios- 🔍 Recursive search for
.sf.tsfiles - 🌐 Automatic network permissions (
--allow-net) - 📊 Execution summary and error reporting
- 🛠️ Easy installation and global access
import { ScenarioFlow } from "scenario-flow";
const apiTest = new ScenarioFlow({
apiBaseUrl: "https://api.example.com/",
})
.step(async (ctx) => {
// First step: Login
const loginRes = await ctx.fetcher({
method: "POST",
urlPaths: ["auth", "login"],
body: JSON.stringify({ username: "test", password: "test" }),
});
const { token } = await loginRes.json();
ctx.addContext("authToken", token);
})
.step(async (ctx) => {
// Second step: Get user data
const token = ctx.getContext<string>("authToken");
const userRes = await ctx.fetcher({
method: "GET",
urlPaths: ["user", "profile"],
headers: {
"Authorization": `Bearer ${token}`,
},
});
const userData = await userRes.json();
console.log("User data:", userData);
});
if (import.meta.main) {
await apiTest.execute();
}# Create your scenario files
mkdir scenarios
echo 'import { ScenarioFlow } from "scenario-flow"; ...' > scenarios/test.sf.ts
# Run all scenarios
sfcli scenarios
# Output:
# Searching for .sf.ts files in: scenarios
# Found 1 .sf.ts files:
# - /path/to/scenarios/test.sf.ts
# Executing: /path/to/scenarios/test.sf.ts
# Successfully executed: /path/to/scenarios/test.sf.ts
# Execution summary: 1/1 files executed successfully.This project includes comprehensive unit tests for all core modules.
# Run all tests
deno task test
# Run core library tests with coverage
deno task test:core
# Run CLI tests
deno task test:cli
# Generate coverage report
deno task test:coverage
# Run CI pipeline locally
deno task ciThe test suite includes:
- 41 unit tests covering all core functionality
- Integration tests for real-world scenarios
- Error handling tests for robust error management
- Type safety tests for TypeScript compliance
- Mock-based testing for isolated unit testing
Test files are located in:
scenario-flow/core/__tests__/- Core library testsscenario-flow-cli/__tests__/main_test.ts- CLI functionality tests
# Clone the repository
git clone https://github.com/u-na-gi/scenario-flow.git
cd scenario-flow
# Run all tests
deno task test
# Run examples
cd example
deno task test
# Run CLI tests
cd ../scenario-flow-cli
deno task test- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License.