Skip to content

Commit

Permalink
Add sleep step. Fix build for link. Fix run params
Browse files Browse the repository at this point in the history
  • Loading branch information
sokolovstas committed Dec 19, 2023
1 parent 9c18402 commit 0328c54
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ beforeAll:
- get: url # GET запрос
...
steps:
- sleep: milliseconds # Подождать перед выполнением
- post: url # POST запрос
log: varName/json # вывести в лог переменную varName или json ответ
body: # тело запроса
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"graph-data-structure": "^3.3.0",
"picocolors": "^1.0.0",
"typescript": "^5.2.2",
"yaml": "^2.3.1",
"yaml": "^2.3.4",
"yargs": "^17.7.2"
},
"devDependencies": {
Expand Down
17 changes: 3 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,23 @@ import {
loadSettings,
runCleanup,
runTestFile,
} from "./test";
} from "./test.js";

const yargv = await yargs(hideBin(process.argv))
.usage("Usage: yapi <options> <path>")
.option("pause-cleanup", {
alias: "pc",
alias: "p",
type: "boolean",
default: false,
description: "Pause before cleanup run",
})
.option("help", {
alias: "h",
type: "boolean",
default: false,
description: "Pause before cleanup run",
description: "Show help",
})
.parserConfiguration({ "unknown-options-as-args": true });

const args = await yargv.parse();
args.pauseCleanup =
args._.includes("-pc") || args._.includes("--pause-cleanup");

args.help = args._.includes("-h") || args._.includes("--help");

if (args.help) {
yargv.showHelp();
process.exit(0);
}

const folder = args._[args._.length - 1];
const testsFolder = resolve(folder.toString());
Expand Down
5 changes: 5 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export interface TestStep extends TestSettings {
patch?: string;
delete?: string;

sleep?: number;

log?: string;

body?: Record<string, TestVar>;
Expand Down Expand Up @@ -103,6 +105,9 @@ function getUrl(url: string) {
async function runStep(s: TestStep) {
let response: Response = null;
let json = {};
if (s.sleep) {
await new Promise((r) => setTimeout(r, s.sleep));
}
if (s.post) {
const path = getUrl(s.post);
console.log(pc.bgBlue(` - POST ${path}`));
Expand Down
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
Expand Down

0 comments on commit 0328c54

Please sign in to comment.