Skip to content

Commit feb9e40

Browse files
authored
Merge pull request #1 from ryaneggz/ryaneggz/cicd-opencode
ryaneggz/cicd-opencode into master
2 parents 61cf893 + 5e71254 commit feb9e40

6 files changed

Lines changed: 4423 additions & 417 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "**" ]
6+
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
- uses: actions/setup-node@v4
13+
with:
14+
node-version: '20'
15+
- name: Install dependencies
16+
run: npm ci
17+
- name: Run tests
18+
run: npm test

__tests__/server.test.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const request = require('supertest');
2+
const http = require('http');
3+
4+
let app;
5+
let server;
6+
7+
beforeAll(async () => {
8+
// Ensure server is running before tests (npm test starts it)
9+
});
10+
11+
describe('basic endpoints', () => {
12+
test('GET /pixel.gif returns 200 and gif', async () => {
13+
const res = await request('http://localhost:8080').get('/pixel.gif').query({ event_type: 'page_view' });
14+
expect(res.status).toBe(200);
15+
expect(res.headers['content-type']).toMatch(/image\/gif/);
16+
expect(res.headers['cache-control']).toMatch(/no-store/);
17+
expect(res.body.length).toBeGreaterThan(0);
18+
});
19+
20+
test('POST /event accepts JSON and returns 204', async () => {
21+
const res = await request('http://localhost:8080')
22+
.post('/event')
23+
.send({ url: 'http://example.com', event_type: 'page_view' })
24+
.set('Content-Type', 'application/json');
25+
expect(res.status).toBe(204);
26+
});
27+
28+
test('GET /stats returns HTML', async () => {
29+
const res = await request('http://localhost:8080').get('/stats');
30+
expect(res.status).toBe(200);
31+
expect(res.headers['content-type']).toMatch(/text\/html/);
32+
expect(res.text).toMatch(/Tiny Tracker/);
33+
});
34+
});

jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('jest').Config} */
2+
module.exports = {
3+
testEnvironment: 'node',
4+
testMatch: ['**/__tests__/**/*.test.js'],
5+
collectCoverage: true,
6+
coverageReporters: ['text', 'lcov'],
7+
};

0 commit comments

Comments
 (0)