1- import { expect , test } from "bun:test" ;
1+ import { afterEach , beforeEach , expect , test } from "bun:test" ;
2+ import { mkdtemp , rm , writeFile } from "node:fs/promises" ;
3+ import { tmpdir } from "node:os" ;
24import { resolve } from "node:path" ;
35
6+ let tempDir : string | null = null ;
7+ let tempGlobalConfigPath : string | null = null ;
8+ let previousGlobalConfigPath : string | undefined ;
9+ let previousHome : string | undefined ;
10+ let previousLogger : string | undefined ;
11+ let previousSetupSyncMode : string | undefined ;
12+
13+ beforeEach ( async ( ) => {
14+ tempDir = await mkdtemp ( resolve ( tmpdir ( ) , "hack-linear-alias-" ) ) ;
15+ tempGlobalConfigPath = resolve ( tempDir , "hack.config.json" ) ;
16+ previousGlobalConfigPath = process . env . HACK_GLOBAL_CONFIG_PATH ;
17+ previousHome = process . env . HOME ;
18+ previousLogger = process . env . HACK_LOGGER ;
19+ previousSetupSyncMode = process . env . HACK_SETUP_SYNC_MODE ;
20+ process . env . HACK_GLOBAL_CONFIG_PATH = tempGlobalConfigPath ;
21+ process . env . HOME = tempDir ;
22+ process . env . HACK_LOGGER = "console" ;
23+ process . env . HACK_SETUP_SYNC_MODE = "off" ;
24+ await writeFile ( tempGlobalConfigPath , "{}\n" ) ;
25+ } ) ;
26+
27+ afterEach ( async ( ) => {
28+ if ( tempDir ) {
29+ await rm ( tempDir , { recursive : true , force : true } ) ;
30+ }
31+ tempDir = null ;
32+ tempGlobalConfigPath = null ;
33+ if ( previousGlobalConfigPath === undefined ) {
34+ process . env . HACK_GLOBAL_CONFIG_PATH = undefined ;
35+ } else {
36+ process . env . HACK_GLOBAL_CONFIG_PATH = previousGlobalConfigPath ;
37+ }
38+ if ( previousHome === undefined ) {
39+ process . env . HOME = undefined ;
40+ } else {
41+ process . env . HOME = previousHome ;
42+ }
43+ if ( previousLogger === undefined ) {
44+ process . env . HACK_LOGGER = undefined ;
45+ } else {
46+ process . env . HACK_LOGGER = previousLogger ;
47+ }
48+ if ( previousSetupSyncMode === undefined ) {
49+ process . env . HACK_SETUP_SYNC_MODE = undefined ;
50+ } else {
51+ process . env . HACK_SETUP_SYNC_MODE = previousSetupSyncMode ;
52+ }
53+ } ) ;
54+
455test ( "hack linear alias forwards extension options like --json" , async ( ) => {
556 const proc = Bun . spawn (
657 [
@@ -11,8 +62,14 @@ test("hack linear alias forwards extension options like --json", async () => {
1162 "--json" ,
1263 ] ,
1364 {
14- cwd : resolve ( import . meta. dir , ".." ) ,
15- env : process . env ,
65+ cwd : tempDir ?? resolve ( import . meta. dir , ".." ) ,
66+ env : {
67+ ...process . env ,
68+ HACK_GLOBAL_CONFIG_PATH : tempGlobalConfigPath ?? "" ,
69+ HACK_LOGGER : "console" ,
70+ HACK_SETUP_SYNC_MODE : "off" ,
71+ HOME : tempDir ?? process . env . HOME ?? "" ,
72+ } ,
1673 stdin : "ignore" ,
1774 stdout : "pipe" ,
1875 stderr : "pipe" ,
0 commit comments