Skip to content

Commit 1a420e5

Browse files
committed
Fix type imports in test utilities
- Use type-only imports for SpawnError and SpawnOptions - Replace non-existent SetupSdkResult with CResult<SocketSdk> - Fix import order per eslint rules
1 parent 6f24d8c commit 1a420e5

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

test/utils.mts

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { fileURLToPath } from 'node:url'
33

44
import { it, vi } from 'vitest'
55

6-
import { SpawnOptions, spawn } from '@socketsecurity/registry/lib/spawn'
6+
import { spawn } from '@socketsecurity/registry/lib/spawn'
77
import { stripAnsi } from '@socketsecurity/registry/lib/strings'
88

99
import constants, { FLAG_HELP, FLAG_VERSION } from '../src/constants.mts'
1010

11-
import type { SetupSdkResult } from '../src/utils/sdk.mts'
11+
import type { CResult } from '../src/types.mts'
12+
import type {
13+
SpawnError,
14+
SpawnOptions,
15+
} from '@socketsecurity/registry/lib/spawn'
16+
import type { SocketSdk } from '@socketsecurity/sdk'
1217
import type { MockedFunction } from 'vitest'
1318

1419
const __filename = fileURLToPath(import.meta.url)
@@ -120,16 +125,18 @@ function sanitizeTokens(str: string): string {
120125
return result
121126
}
122127

123-
export function cleanOutput(output: string): string {
128+
export function cleanOutput(output: string | Buffer<ArrayBufferLike>): string {
124129
return toAsciiSafeString(
125130
normalizeLogSymbols(
126131
normalizeNewlines(
127132
stripZeroWidthSpace(
128-
sanitizeTokens(stripTokenErrorMessages(stripAnsi(output.trim()))),
133+
sanitizeTokens(
134+
stripTokenErrorMessages(stripAnsi(String(output).trim())),
135+
),
129136
),
130137
),
131138
),
132-
)
139+
).trim()
133140
}
134141

135142
/**
@@ -224,16 +231,17 @@ export async function spawnSocketCli(
224231
stdout: cleanOutput(output.stdout),
225232
stderr: cleanOutput(output.stderr),
226233
}
227-
} catch (e: unknown) {
234+
} catch (e) {
235+
const maybeSpawnError = e as SpawnError
228236
return {
229237
status: false,
230-
code: e?.['code'] || 1,
238+
code: maybeSpawnError?.['code'] || 1,
231239
error: {
232-
message: e?.['message'] || '',
233-
stack: e?.['stack'] || '',
240+
message: maybeSpawnError?.['message'] || '',
241+
stack: maybeSpawnError?.['stack'] || '',
234242
},
235-
stdout: cleanOutput(e?.['stdout'] ?? ''),
236-
stderr: cleanOutput(e?.['stderr'] ?? ''),
243+
stdout: cleanOutput(maybeSpawnError?.['stdout'] ?? ''),
244+
stderr: cleanOutput(maybeSpawnError?.['stderr'] ?? ''),
237245
}
238246
}
239247
}
@@ -246,7 +254,10 @@ export function mockSetupSdkSuccess(
246254
mockSetupSdk: MockedFunction<any>,
247255
sdkData: any = {},
248256
): void {
249-
mockSetupSdk.mockResolvedValue({ ok: true, data: sdkData } as SetupSdkResult)
257+
mockSetupSdk.mockResolvedValue({
258+
ok: true,
259+
data: sdkData,
260+
} as CResult<SocketSdk>)
250261
}
251262

252263
/**
@@ -260,7 +271,7 @@ export function mockSetupSdkFailure(
260271
mockSetupSdk.mockResolvedValue({
261272
ok: false,
262273
...error,
263-
} as SetupSdkResult)
274+
} as CResult<SocketSdk>)
264275
}
265276

266277
/**

0 commit comments

Comments
 (0)