Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changepacks/changepack_log_0F-1MEkW9sLWK_J0m2245.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"changes": { "packages/next-plugin/package.json": "Patch" },
"note": "Add forced boot code",
"date": "2025-11-19T08:36:56.984126800Z"
}
61 changes: 61 additions & 0 deletions packages/next-plugin/src/__tests__/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ vi.mock('@devup-ui/wasm', async (original) => ({
registerTheme: vi.fn(),
getThemeInterface: vi.fn(),
getDefaultTheme: vi.fn(),
getCss: vi.fn(() => ''),
exportSheet: vi.fn(() =>
JSON.stringify({
css: {},
Expand Down Expand Up @@ -89,6 +90,15 @@ describe('DevupUINextPlugin', () => {
})
})
describe('turbo', () => {
beforeEach(() => {
// Mock fetch globally to prevent "http://localhost:undefined" errors
global.fetch = vi.fn(() => Promise.resolve({} as Response))
})

afterEach(() => {
vi.restoreAllMocks()
})

it('should apply turbo config', async () => {
vi.stubEnv('TURBOPACK', '1')
vi.mocked(existsSync)
Expand Down Expand Up @@ -390,5 +400,56 @@ describe('DevupUINextPlugin', () => {
DEVUP_UI_DEFAULT_THEME: 'light',
})
})
it('should handle debugPort fetch failure in development mode', async () => {
vi.stubEnv('TURBOPACK', '1')
vi.stubEnv('NODE_ENV', 'development')
vi.stubEnv('PORT', '3000')
vi.mocked(existsSync)
.mockReturnValueOnce(true)
.mockReturnValueOnce(true)
.mockReturnValueOnce(true)
.mockReturnValueOnce(false)
vi.mocked(writeFileSync).mockReturnValue()

// Mock process.exit to prevent actual exit
const originalExit = process.exit
const exitSpy = vi.fn()
process.exit = exitSpy as any

// Mock process.debugPort
const originalDebugPort = process.debugPort
process.debugPort = 9229

// Mock fetch globally before calling DevupUI
const originalFetch = global.fetch
const fetchMock = vi.fn((url: string | URL) => {
const urlString = typeof url === 'string' ? url : url.toString()
if (urlString.includes('9229')) {
return Promise.reject(new Error('Connection refused'))
}
return Promise.resolve({} as Response)
})
global.fetch = fetchMock as any

// Use fake timers to control setTimeout
vi.useFakeTimers()

try {
DevupUI({})

// Wait for the fetch promise to reject (this triggers the catch handler)
// The catch handler sets up a setTimeout, so we need to wait for that
await vi.runAllTimersAsync()

// Verify process.exit was called with code 77
expect(exitSpy).toHaveBeenCalledWith(77)
} finally {
// Restore
vi.useRealTimers()
global.fetch = originalFetch
process.exit = originalExit
process.debugPort = originalDebugPort
}
})
})
})
8 changes: 7 additions & 1 deletion packages/next-plugin/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ export function DevupUI(
)

if (process.env.NODE_ENV !== 'production') {
// dev
// check if debugger is attached
fetch('http://localhost:' + process.env.PORT)
fetch('http://localhost:' + process.debugPort).catch(() => {
setTimeout(() => {
process.exit(77)
}, 500)
})
process.env.TURBOPACK_DEBUG_JS = '*'
process.env.NODE_OPTIONS ??= ''
process.env.NODE_OPTIONS += ' --inspect-brk'
Expand Down