-
-
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
Changes from 10 commits
8073901
6250620
b1d49ec
e845768
89e5613
aa5d4d2
c16b6b7
779d3be
e288a49
e7467ac
d9fa58d
dd50073
9d00319
48322e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
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); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,42 @@ | ||||||
import { fastify } from 'fastify'; | ||||||
import { Server, IncomingMessage, ServerResponse } from 'http'; | ||||||
import app from '../app'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to export app from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
|
||||||
let server: fastify.FastifyInstance<Server, IncomingMessage, ServerResponse>; | ||||||
|
||||||
beforeAll(async () => { | ||||||
server = fastify(); | ||||||
server.register(app); | ||||||
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!' }); | ||||||
}); | ||||||
}); |
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