11// Dependency Changes Report tests cover dependency changes report script behavior.
2+ import { spawnSync } from "node:child_process" ;
3+ import path from "node:path" ;
24import { describe , expect , it } from "vitest" ;
35import {
46 createDependencyChangesReport ,
@@ -7,6 +9,18 @@ import {
79 parseArgs ,
810} from "../../scripts/dependency-changes-report.mjs" ;
911
12+ function runCli ( ...args : string [ ] ) {
13+ return spawnSync ( process . execPath , [ "scripts/dependency-changes-report.mjs" , ...args ] , {
14+ cwd : path . resolve ( "." ) ,
15+ encoding : "utf8" ,
16+ } ) ;
17+ }
18+
19+ function expectNoNodeStack ( stderr : string ) {
20+ expect ( stderr ) . not . toContain ( "Node.js" ) ;
21+ expect ( stderr ) . not . toContain ( "\n at " ) ;
22+ }
23+
1024describe ( "dependency-changes-report" , ( ) => {
1125 it ( "reports added, removed, and changed packages" , ( ) => {
1226 const report = createDependencyChangesReport ( {
@@ -72,4 +86,20 @@ describe("dependency-changes-report", () => {
7286 expect ( ( ) => parseArgs ( [ flag , "--json" ] ) ) . toThrow ( `${ flag } requires a value` ) ;
7387 }
7488 } ) ;
89+
90+ it ( "reports CLI argument errors without a Node stack trace" , ( ) => {
91+ const missingBase = runCli ( ) ;
92+ expect ( missingBase . status ) . toBe ( 1 ) ;
93+ expect ( missingBase . stdout ) . toBe ( "" ) ;
94+ expect ( missingBase . stderr . trim ( ) ) . toBe (
95+ "Expected --base-ref <git-ref> or --base-lockfile <path>." ,
96+ ) ;
97+ expectNoNodeStack ( missingBase . stderr ) ;
98+
99+ const unknownArg = runCli ( "--wat" ) ;
100+ expect ( unknownArg . status ) . toBe ( 1 ) ;
101+ expect ( unknownArg . stdout ) . toBe ( "" ) ;
102+ expect ( unknownArg . stderr . trim ( ) ) . toBe ( "Unsupported argument: --wat" ) ;
103+ expectNoNodeStack ( unknownArg . stderr ) ;
104+ } ) ;
75105} ) ;
0 commit comments