|
15 | 15 | import cli.scaffold_argocd as scaffold_argocd |
16 | 16 | import cli.scaffold_sre as scaffold_sre |
17 | 17 | import cli.scaffold_devcontainer as scaffold_devcontainer |
| 18 | +import cli.scaffold_unittest as scaffold_unittest |
18 | 19 | import cli.process_first as process_first |
19 | 20 | from cli import __version__ |
20 | 21 |
|
@@ -559,6 +560,74 @@ def scaffold_cicd_cmd( |
559 | 560 | flags += ["--custom-values", custom_values] |
560 | 561 | _run_scaffold(scaffold_cicd.main, flags) |
561 | 562 |
|
| 563 | + |
| 564 | +# ── scaffold unittest ──────────────────────────────────────────────────────── |
| 565 | + |
| 566 | +@scaffold_app.command("unittest") |
| 567 | +def scaffold_unittest_cmd( |
| 568 | + ctx: typer.Context, |
| 569 | + name: str = typer.Option("my-app", envvar="DEVOPS_OS_UNITTEST_NAME", |
| 570 | + help="Project / application name"), |
| 571 | + languages: str = typer.Option("python", envvar="DEVOPS_OS_UNITTEST_LANGUAGES", |
| 572 | + help=( |
| 573 | + "Comma-separated languages to generate tests for: " |
| 574 | + "python, javascript, typescript, go" |
| 575 | + )), |
| 576 | + framework: str = typer.Option("", envvar="DEVOPS_OS_UNITTEST_FRAMEWORK", |
| 577 | + help=( |
| 578 | + "Testing framework override (auto-selected by default). " |
| 579 | + "JS/TS: jest | mocha | vitest. Python: pytest. Go: go-test." |
| 580 | + )), |
| 581 | + coverage: bool = typer.Option(True, envvar="DEVOPS_OS_UNITTEST_COVERAGE", |
| 582 | + help="Include coverage configuration (default: true)"), |
| 583 | + output_dir: str = typer.Option("unittest", "--output-dir", |
| 584 | + envvar="DEVOPS_OS_UNITTEST_OUTPUT_DIR", |
| 585 | + help="Root output directory for generated files"), |
| 586 | +): |
| 587 | + """Generate unit testing configuration and sample test files. |
| 588 | +
|
| 589 | + \b |
| 590 | + Supported languages and their default frameworks: |
| 591 | + python → pytest + pytest-cov |
| 592 | + javascript → Jest (override with --framework mocha | vitest) |
| 593 | + typescript → Jest (override with --framework mocha | vitest) |
| 594 | + go → go test |
| 595 | +
|
| 596 | + \b |
| 597 | + Output files (default: unittest/ directory): |
| 598 | + unittest/pytest.ini Python pytest configuration |
| 599 | + unittest/conftest.py Python shared fixtures |
| 600 | + unittest/tests/__init__.py Python test-package marker |
| 601 | + unittest/tests/test_sample.py Python sample unit tests |
| 602 | + unittest/jest.config.js JavaScript/TypeScript Jest config |
| 603 | + unittest/vitest.config.js JavaScript/TypeScript Vitest config |
| 604 | + unittest/.mocharc.js JavaScript/TypeScript Mocha config |
| 605 | + unittest/tests/sample.test.js JavaScript/TypeScript sample tests |
| 606 | + unittest/<name>_test.go Go sample unit test file |
| 607 | + unittest/Makefile.test Go Makefile test targets |
| 608 | +
|
| 609 | + \b |
| 610 | + Examples: |
| 611 | + devopsos scaffold unittest --name my-app --languages python |
| 612 | + devopsos scaffold unittest --name my-app --languages javascript --framework jest |
| 613 | + devopsos scaffold unittest --name my-app --languages typescript --framework vitest |
| 614 | + devopsos scaffold unittest --name my-api --languages go |
| 615 | + devopsos scaffold unittest --name my-app --languages python,javascript,go |
| 616 | + """ |
| 617 | + _show_help_if_no_opts(ctx) |
| 618 | + flags = [ |
| 619 | + "--name", name, |
| 620 | + "--languages", languages, |
| 621 | + "--output-dir", output_dir, |
| 622 | + ] |
| 623 | + if framework: |
| 624 | + flags += ["--framework", framework] |
| 625 | + if not coverage: |
| 626 | + # coverage defaults to True; only pass flag when False |
| 627 | + flags.append("--no-coverage") |
| 628 | + _run_scaffold(scaffold_unittest.main, flags) |
| 629 | + |
| 630 | + |
562 | 631 | @app.command() |
563 | 632 | def init( |
564 | 633 | directory: str = typer.Option(".", "--dir", help="Target directory in which the .devcontainer folder will be created (defaults to the current directory)"), |
|
0 commit comments