-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { test, expect, describe, beforeAll, afterAll } from 'bun:test'; | ||
import { execa, type ResultPromise } from 'execa'; | ||
|
||
const url = 'http://localhost:7071'; | ||
const healthPath = '/api/SimpleHttpTrigger'; | ||
|
||
function waitForServer(url: string) { | ||
return new Promise<void>((resolve, reject) => { | ||
const checkServer = async () => { | ||
try { | ||
const response = await fetch(url); | ||
if (response.ok) { | ||
resolve(); | ||
} else { | ||
setTimeout(checkServer, 1000); | ||
} | ||
} catch (error) { | ||
setTimeout(checkServer, 1000); | ||
} | ||
}; | ||
checkServer(); | ||
}); | ||
} | ||
|
||
describe('e2e-local', () => { | ||
let serverProcess: | ||
| ResultPromise<{ | ||
stdout: 'inherit'; | ||
killSignal: 'SIGKILL'; | ||
}> | ||
| undefined; | ||
let serverLogs = ''; | ||
|
||
beforeAll(async () => { | ||
// Place Azure Functions into the current directory | ||
serverProcess = execa({ stdout: 'inherit', killSignal: 'SIGKILL' })`func start --verbose`; | ||
// Wait for the server to be ready | ||
await waitForServer(new URL(healthPath, url).toString()); | ||
}); | ||
|
||
afterAll(async () => { | ||
if (serverProcess) { | ||
console.log('Killing server process'); | ||
serverProcess.kill(); | ||
} | ||
}); | ||
|
||
test('should return 200 OK', async () => { | ||
try { | ||
const response = await fetch(new URL('/api/SimpleHttpTrigger', url).toString()); | ||
expect(response.status).toBe(200); | ||
} catch (error) { | ||
console.error(serverLogs); // Print server logs on failure | ||
throw new Error('Server did not respond with 200 OK'); | ||
} | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test, expect, describe, beforeAll } from 'bun:test'; | ||
|
||
describe('e2e-remote', () => { | ||
|
||
let url: string | undefined; | ||
let apiKey: string | undefined; | ||
|
||
beforeAll(() => { | ||
url = process.env.AZURE_FUNCTIONS_URL; | ||
apiKey = process.env.AZURE_FUNCTIONS_API_KEY; | ||
if (!url) throw new Error('AZURE_FUNCTIONS_URL not set'); | ||
Check failure on line 11 in infra/azure-functions/src/e2e-remote.test.ts GitHub Actions / e2e-local (ubuntu-latest, node, latest, node18-linux-x64, true, RESOURCE_IDENTIFIER_NODE18_LINUX_...error: AZURE_FUNCTIONS_URL not set
Check failure on line 11 in infra/azure-functions/src/e2e-remote.test.ts GitHub Actions / e2e-local (windows-latest, node, latest, node18-win-x64, true, RESOURCE_IDENTIFIER_NODE18_WIN_X64)error: AZURE_FUNCTIONS_URL not set
Check failure on line 11 in infra/azure-functions/src/e2e-remote.test.ts GitHub Actions / e2e-local (ubuntu-latest, bun, latest, bun-linux-x64, true, RESOURCE_IDENTIFIER_BUN_LINUX_X64)error: AZURE_FUNCTIONS_URL not set
Check failure on line 11 in infra/azure-functions/src/e2e-remote.test.ts GitHub Actions / e2e-local (windows-latest, bun, latest, bun-win-x64, true, RESOURCE_IDENTIFIER_BUN_WIN_X64)error: AZURE_FUNCTIONS_URL not set
Check failure on line 11 in infra/azure-functions/src/e2e-remote.test.ts GitHub Actions / e2e-local (macos-latest, bun, latest, bun-macos-x64, false, RESOURCE_IDENTIFIER_BUN_MACOS_X64)error: AZURE_FUNCTIONS_URL not set
|
||
if (!apiKey) throw new Error('AZURE_FUNCTIONS_API_KEY not set'); | ||
console.log(`Testing remote Azure Functions at ${url}`); | ||
}); | ||
|
||
test('should return 200 OK', async () => { | ||
const response = await fetch(new URL(`/api/SimpleHttpTrigger?code=${apiKey}`, url).toString(), { | ||
method: 'GET', | ||
}); | ||
|
||
expect(response.status).toBe(200); | ||
}); | ||
}); |
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.