-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit test for the Fastify API #9
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8073901
feat: add unit tests for Fastify API
sweep-ai[bot] 6250620
feat: Add Step CI runner script
sweep-ai[bot] b1d49ec
feat: Add GitHub action to run tests
sweep-ai[bot] e845768
feat: Updated .github/workflows/test.yml
sweep-ai[bot] 89e5613
Merge main into sweep/add-unit-test-for-fastify-api_1
sweep-ai[bot] aa5d4d2
feat: Updated Dockerfile
sweep-ai[bot] c16b6b7
Merge main into sweep/add-unit-test-for-fastify-api_1
sweep-ai[bot] 779d3be
Merge main into sweep/add-unit-test-for-fastify-api_1
sweep-ai[bot] e288a49
chore: remove install bun with npm
jellydn e7467ac
chore: export fastify server
jellydn d9fa58d
feat: Updated tests/api.test.ts
sweep-ai[bot] dd50073
feat: Updated server.ts
sweep-ai[bot] 9d00319
feat: Updated tests/api.test.ts
sweep-ai[bot] 48322e0
Merge main into sweep/add-unit-test-for-fastify-api_1
sweep-ai[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: Run tests | ||
|
||
on: push | ||
|
||
jobs: | ||
run-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v2 | ||
- name: Install bun | ||
run: npm install -g bun | ||
- name: Install dependencies | ||
run: bun install | ||
- name: Run tests | ||
run: bun test |
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,5 @@ | ||
import { runFromFile } from '@stepci/runner'; | ||
|
||
runFromFile('./tests/api.test.ts') | ||
.then(console.log) | ||
.catch(console.error); |
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,39 @@ | ||
import { Server, IncomingMessage, ServerResponse } from 'http'; | ||
import { server } from '../server'; | ||
|
||
let server: fastify.FastifyInstance<Server, IncomingMessage, ServerResponse>; | ||
|
||
beforeAll(async () => { | ||
await server.ready(); | ||
}); | ||
|
||
afterAll(() => { | ||
server.close(); | ||
}); | ||
|
||
describe('Fastify API', () => { | ||
it('should respond with 200 on GET /api', async () => { | ||
const response = await server.inject({ | ||
method: 'GET', | ||
url: '/api', | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
}); | ||
|
||
it('should respond with 200 on GET /api/hello', async () => { | ||
const response = await server.inject({ | ||
method: 'GET', | ||
url: '/api/hello', | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
}); | ||
|
||
it('should respond with 200 and pong on GET /api/ping', async () => { | ||
const response = await server.inject({ | ||
method: 'GET', | ||
url: '/api/ping', | ||
}); | ||
expect(response.statusCode).toBe(200); | ||
expect(JSON.parse(response.body)).toEqual({ pong: 'it worked!' }); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This package
@stepci/runner
need to add topackage.json
as depedence.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to make changes. This could be due to an unclear request or a bug in my code.
As a reminder, comments on a file only modify that file. Comments on a PR(at the bottom of the "conversation" tab) can modify the entire PR. Please try again or contact us on Discord