@@ -7,24 +7,28 @@ const cwd = resolve(__dirname, '..')
77const  output  =  join ( cwd ,  'output' ) 
88const  cli  =  require . resolve ( resolve ( cwd ,  '..' ) ) 
99
10- // remove npm config when spawning so config set by test commands don't interfere 
11- const  env  =  Object . fromEntries ( 
12-   Object . entries ( process . env ) . filter ( ( [ k ] )  =>  ! k . toLowerCase ( ) . startsWith ( 'npm_config_' ) ) 
13- ) 
10+ const  rmOutput  =  ( )  =>  fs . rm ( output ,  {  recursive : true ,  force : true  } ) . catch ( ( )  =>  { } ) 
1411
15- const  rm  =  ( d )  =>  fs . rm ( d ,  {  recursive : true ,  force : true  } ) . catch ( ( )  =>  { } ) 
12+ const  spawnNpm  =  ( args ,  opts )  =>  { 
13+   // remove npm config when spawning so config set by test commands don't interfere 
14+   const  env  =  Object . entries ( process . env ) 
15+     . filter ( ( [ k ] )  =>  ! k . toLowerCase ( ) . startsWith ( 'npm_config_' ) ) 
16+ 
17+   return  spawn ( 'node' ,  [ cli ,  ...args ] ,  { 
18+     env : Object . fromEntries ( env ) , 
19+     stdioString : true , 
20+     ...opts , 
21+   } ) 
22+ } 
1623
1724t . test ( 'docs' ,  async  ( t )  =>  { 
18-   t . teardown ( ( )   =>   rm ( output ) ) 
25+   t . teardown ( rmOutput ) 
1926
20-   await  rm ( output ) 
27+   await  rmOutput ( ) 
2128  t . rejects ( ( )  =>  fs . stat ( output ) ) 
2229
23-   const  docs  =  await  spawn ( 'node' ,  [ cli ,  'run' ,  'build' ] ,  { 
24-     cwd, 
25-     env, 
26-     stdioString : true , 
27-   } ) 
30+   // calling run build will rebuild cmark-gfm with a prebuild script 
31+   const  docs  =  await  spawnNpm ( [ 'run' ,  'build' ] ,  {  cwd } ) 
2832
2933  t . equal ( docs . code ,  0 ) 
3034  t . ok ( ( await  fs . stat ( output ) ) . isDirectory ( ) ) 
0 commit comments