Skip to content

Commit

Permalink
feat: add --dump options
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Dec 24, 2021
1 parent 69d7127 commit fbd5e3b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dev": "ts-node src/bin.ts",
"build": "tsc -p tsconfig.build.json",
"clean": "rimraf dist",
"test": "yarn build && jest",
"test": "jest",
"prepublish": "npm run -s clean && npm run -s build"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/Reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class Reporter {
if (args.timeMs > 0) {
timeStr = " (" + (args.timeMs / 1000).toFixed(3) + ")";
}
const dump = _.get(args.state, "run.dump");
const dump = _.get(args.state, "run.dump") || this.options.dump;
if (!args.err) {
process.stdout.write(chalk.green(`${timeStr} ✔\n`));
if (dump) {
Expand Down
1 change: 1 addition & 0 deletions src/Runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface RunOptions {
ci?: boolean;
reset?: boolean;
dryRun?: boolean;
dump?: boolean;
only?: string;
}

Expand Down
7 changes: 7 additions & 0 deletions src/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const argv = require("yargs/yargs")(process.argv.slice(2)) // eslint-disable-lin
type: "string",
describe: "Run specific module/case",
},
dump: {
type: "boolean",
describe: "Force print req/res data",
},
})
.argv;

Expand Down Expand Up @@ -56,6 +60,9 @@ async function main(argv) {
reset: argv.reset,
};
}
if (argv.dump) {
runOptions.dump = true;
}
const exitCode = await runner.run(runOptions);
process.exit(exitCode);
} catch (err) {
Expand Down
14 changes: 14 additions & 0 deletions tests/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ mod1
"
`;

exports[`cli with options --only --dump 1`] = `
"main
test4 ✔
{
\\"req\\": {
\\"v1\\": \\"a\\"
},
\\"res\\": {
\\"v1\\": \\"a\\"
}
}
"
`;

exports[`cli with options --only 1`] = `
"main
test4 ✔
Expand Down
5 changes: 5 additions & 0 deletions tests/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ describe("cli", () => {
expect(code).toEqual(1);
expect(stdout).toMatchSnapshot();
});
test("with options --only --dump", async () => {
const { stdout, code } = await spwanTest("cli/main.jsona", ["--only", "main.test4", "--dump"]);
expect(code).toEqual(0);
expect(stdout).toMatchSnapshot();
});
test("still start from last failed", async () => {
const { stdout, code } = await spwanTest("cli/main.jsona");
expect(code).toEqual(1);
Expand Down

0 comments on commit fbd5e3b

Please sign in to comment.