Skip to content

Commit 66a0ee9

Browse files
committed
chore: wip
1 parent 1762256 commit 66a0ee9

14 files changed

+340
-256
lines changed

packages/launchpad/src/install-core.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,17 @@ export async function downloadPackage(
410410

411411
// Skip actual downloads in test environment unless explicitly allowed
412412
// Note: Tests use mock fetch, so this only blocks real network calls
413-
if (process.env.NODE_ENV === 'test' && process.env.LAUNCHPAD_ALLOW_NETWORK !== '1' && !globalThis.fetch.toString().includes('mockFetch')) {
414-
throw new Error('Network calls disabled in test environment')
413+
if (process.env.NODE_ENV === 'test' && process.env.LAUNCHPAD_ALLOW_NETWORK !== '1') {
414+
// Check if fetch is mocked by looking for our mock marker or function name
415+
const fetchStr = globalThis.fetch.toString()
416+
const isMocked = fetchStr.includes('mockFetch')
417+
|| fetchStr.includes('Mock response')
418+
|| fetchStr.includes('testing.org')
419+
|| (globalThis.fetch as any).__isMocked === true
420+
421+
if (!isMocked) {
422+
throw new Error('Network calls disabled in test environment')
423+
}
415424
}
416425

417426
const response = await fetch(url, {
@@ -672,7 +681,13 @@ export async function downloadPackage(
672681
}
673682

674683
// Check if we're in test mode with mock data or if the file is not a valid archive
675-
const isMockData = process.env.NODE_ENV === 'test' && globalThis.fetch.toString().includes('mockFetch')
684+
const fetchStr = globalThis.fetch.toString()
685+
const isMockData = process.env.NODE_ENV === 'test' && (
686+
fetchStr.includes('mockFetch')
687+
|| fetchStr.includes('Mock response')
688+
|| fetchStr.includes('testing.org')
689+
|| (globalThis.fetch as any).__isMocked === true
690+
)
676691

677692
// Check if the archive file is valid by reading the first few bytes
678693
let isValidArchive = false

packages/launchpad/test/core-environment-validation.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ async function mockFetch(url: string | URL | Request, _init?: RequestInit): Prom
4343

4444
// Set up test environment
4545
process.env.NODE_ENV = 'test'
46-
globalThis.fetch = mockFetch as typeof fetch
46+
const mockedFetch = mockFetch as typeof fetch
47+
;(mockedFetch as any).__isMocked = true
48+
globalThis.fetch = mockedFetch
4749

4850
// Cleanup function to restore original fetch
4951
function restoreOriginalFetch() {

0 commit comments

Comments
 (0)