@@ -16,47 +16,46 @@ afterEach(() => {
1616 vi . unstubAllEnvs ( ) ;
1717} ) ;
1818
19- describe ( "init package.json creation" , ( ) => {
20- it . each ( [ "existing" , "concurrent" , "dangling symlink" ] ) (
21- "preserves a %s entry while completing initialization" ,
22- async ( kind ) => {
23- const dir = fs . mkdtempSync ( join ( tmpdir ( ) , "hf-init-package-" ) ) ;
24- const project = join ( dir , "project" ) ;
25- const packagePath = join ( project , "package.json" ) ;
26- const target = join ( dir , "missing-target.json" ) ;
27- const original = await vi . importActual < typeof fs > ( "node:fs" ) ;
28- let injected = false ;
29- vi . mocked ( fs . existsSync ) . mockImplementation ( ( path ) => {
30- if ( path === packagePath && ! injected ) {
31- injected = true ;
32- if ( kind === "dangling symlink" ) fs . symlinkSync ( target , packagePath ) ;
33- else fs . writeFileSync ( packagePath , '{"name":"preserve-me"}\n' ) ;
34- return kind === "existing" ;
35- }
36- return original . existsSync ( path ) ;
19+ describe ( "init config creation" , ( ) => {
20+ it . each (
21+ [ "package.json" , "hyperframes.json" ] . flatMap ( ( filename ) =>
22+ [ "existing" , "concurrent" , "dangling symlink" ] . map ( ( kind ) => ( { filename, kind } ) ) ,
23+ ) ,
24+ ) ( "preserves $kind $filename while completing initialization" , async ( { filename, kind } ) => {
25+ const dir = fs . mkdtempSync ( join ( tmpdir ( ) , "hf-init-package-" ) ) ;
26+ const project = join ( dir , "project" ) ;
27+ const packagePath = join ( project , filename ) ;
28+ const target = join ( dir , "missing-target.json" ) ;
29+ const original = await vi . importActual < typeof fs > ( "node:fs" ) ;
30+ let injected = false ;
31+ vi . mocked ( fs . existsSync ) . mockImplementation ( ( path ) => {
32+ if ( path === packagePath && ! injected ) {
33+ injected = true ;
34+ if ( kind === "dangling symlink" ) fs . symlinkSync ( target , packagePath ) ;
35+ else fs . writeFileSync ( packagePath , '{"name":"preserve-me"}\n' ) ;
36+ return kind === "existing" ;
37+ }
38+ return original . existsSync ( path ) ;
39+ } ) ;
40+ vi . stubEnv ( "HYPERFRAMES_SKIP_SKILLS" , "1" ) ;
41+ const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
42+ try {
43+ await runCommand ( init , {
44+ rawArgs : [ project , "--example" , "blank" , "--non-interactive" ] ,
3745 } ) ;
38- vi . stubEnv ( "HYPERFRAMES_SKIP_SKILLS" , "1" ) ;
39- const log = vi . spyOn ( console , "log" ) . mockImplementation ( ( ) => { } ) ;
40- try {
41- await runCommand ( init , {
42- rawArgs : [ project , "--example" , "blank" , "--non-interactive" ] ,
43- } ) ;
44- expect ( injected ) . toBe ( true ) ;
45- if ( kind === "dangling symlink" ) {
46- expect ( fs . lstatSync ( packagePath ) . isSymbolicLink ( ) ) . toBe ( true ) ;
47- expect ( fs . existsSync ( target ) ) . toBe ( false ) ;
48- } else {
49- expect ( fs . readFileSync ( packagePath , "utf-8" ) ) . toBe ( '{"name":"preserve-me"}\n' ) ;
50- }
51- expect ( fs . existsSync ( join ( project , "index.html" ) ) ) . toBe ( true ) ;
52- expect ( log . mock . calls . flat ( ) . join ( "\n" ) ) . toContain ( "npm run dev" ) ;
53- expect ( fs . readdirSync ( project ) . filter ( ( name ) => name . startsWith ( ".hf-create-" ) ) ) . toEqual (
54- [ ] ,
55- ) ;
56- } finally {
57- vi . mocked ( fs . existsSync ) . mockImplementation ( original . existsSync ) ;
58- fs . rmSync ( dir , { recursive : true , force : true } ) ;
46+ expect ( injected ) . toBe ( true ) ;
47+ if ( kind === "dangling symlink" ) {
48+ expect ( fs . lstatSync ( packagePath ) . isSymbolicLink ( ) ) . toBe ( true ) ;
49+ expect ( fs . existsSync ( target ) ) . toBe ( false ) ;
50+ } else {
51+ expect ( fs . readFileSync ( packagePath , "utf-8" ) ) . toBe ( '{"name":"preserve-me"}\n' ) ;
5952 }
60- } ,
61- ) ;
53+ expect ( fs . existsSync ( join ( project , "index.html" ) ) ) . toBe ( true ) ;
54+ expect ( log . mock . calls . flat ( ) . join ( "\n" ) ) . toContain ( "npm run dev" ) ;
55+ expect ( fs . readdirSync ( project ) . filter ( ( name ) => name . startsWith ( ".hf-create-" ) ) ) . toEqual ( [ ] ) ;
56+ } finally {
57+ vi . mocked ( fs . existsSync ) . mockImplementation ( original . existsSync ) ;
58+ fs . rmSync ( dir , { recursive : true , force : true } ) ;
59+ }
60+ } ) ;
6261} ) ;
0 commit comments