-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a792187
commit 420e991
Showing
6 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters