Skip to content

Commit 10def36

Browse files
committed
Update test files for path handling
1 parent 205fb7b commit 10def36

3 files changed

Lines changed: 48 additions & 6 deletions

File tree

test/registry/cacache.test.mts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,54 @@
1-
import { afterEach, describe, expect, it } from 'vitest'
1+
import { mkdtempSync } from 'node:fs'
2+
import os from 'node:os'
3+
import path from 'node:path'
4+
5+
import {
6+
afterAll,
7+
afterEach,
8+
beforeAll,
9+
beforeEach,
10+
describe,
11+
expect,
12+
it,
13+
} from 'vitest'
214

315
import * as cacache from '../../registry/dist/lib/cacache.js'
16+
import { trash } from '../../scripts/utils/fs.mjs'
417

518
// Test key for cache operations.
619
const TEST_KEY = 'test-cacache-key'
720
const TEST_DATA = 'test data content'
821

922
describe('cacache module', () => {
23+
let testCacheDir: string
24+
let originalEnv: string | undefined
25+
26+
beforeAll(() => {
27+
// Create a temporary directory for test-specific cacache.
28+
testCacheDir = mkdtempSync(path.join(os.tmpdir(), 'cacache-test-'))
29+
// Override cacache directory for tests.
30+
originalEnv = process.env['SOCKET_CACACHE_DIR']
31+
process.env['SOCKET_CACACHE_DIR'] = testCacheDir
32+
})
33+
34+
afterAll(async () => {
35+
// Restore original environment.
36+
if (originalEnv === undefined) {
37+
delete process.env['SOCKET_CACACHE_DIR']
38+
} else {
39+
process.env['SOCKET_CACACHE_DIR'] = originalEnv
40+
}
41+
// Clean up test cache directory.
42+
await trash(testCacheDir)
43+
})
44+
45+
beforeEach(async () => {
46+
// Remove test key before each test for defensive cleanup.
47+
await cacache.remove(TEST_KEY).catch(() => {
48+
// Ignore cleanup errors.
49+
})
50+
})
51+
1052
afterEach(async () => {
1153
// Clean up test entries after each test.
1254
await cacache.remove(TEST_KEY).catch(() => {

test/registry/debug.test.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ describe('debug module', () => {
428428
})
429429

430430
describe('isDebugNs', () => {
431-
it('should return false when SOCKET_CLI_DEBUG is not set', () => {
432-
delete process.env['SOCKET_CLI_DEBUG']
431+
it('should return false when SOCKET_DEBUG is not set', () => {
432+
delete process.env['SOCKET_DEBUG']
433433
expect(isDebugNs('test')).toBe(false)
434434
})
435435
})

test/registry/sea-build.test.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
22

33
// Mock the httpRequest module before importing sea-build module.
4-
vi.mock('../../registry/dist/lib/http-request.js', () => {
4+
vi.mock('../../registry/src/lib/http-request', () => {
55
return {
66
httpRequest: vi.fn(),
77
}
88
})
99

10-
import { httpRequest as httpRequestActual } from '../../registry/dist/lib/http-request.js'
10+
import { httpRequest as httpRequestActual } from '../../registry/src/lib/http-request'
1111
import {
1212
getBuildTargets,
1313
getDefaultNodeVersion,
1414
getLatestCurrentRelease,
15-
} from '../../registry/dist/lib/sea-build.js'
15+
} from '../../registry/src/lib/sea-build'
1616

1717
const httpRequest = httpRequestActual as unknown as ReturnType<typeof vi.fn>
1818

0 commit comments

Comments
 (0)