Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: CI

on:
push:
branches: [ "**" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
34 changes: 34 additions & 0 deletions __tests__/server.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const request = require('supertest');
const http = require('http');

let app;
let server;

beforeAll(async () => {
// Ensure server is running before tests (npm test starts it)
});

describe('basic endpoints', () => {
test('GET /pixel.gif returns 200 and gif', async () => {
const res = await request('http://localhost:8080').get('/pixel.gif').query({ event_type: 'page_view' });
expect(res.status).toBe(200);
expect(res.headers['content-type']).toMatch(/image\/gif/);
expect(res.headers['cache-control']).toMatch(/no-store/);
expect(res.body.length).toBeGreaterThan(0);
});

test('POST /event accepts JSON and returns 204', async () => {
const res = await request('http://localhost:8080')
.post('/event')
.send({ url: 'http://example.com', event_type: 'page_view' })
.set('Content-Type', 'application/json');
expect(res.status).toBe(204);
});

test('GET /stats returns HTML', async () => {
const res = await request('http://localhost:8080').get('/stats');
expect(res.status).toBe(200);
expect(res.headers['content-type']).toMatch(/text\/html/);
expect(res.text).toMatch(/Tiny Tracker/);
});
});
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('jest').Config} */
module.exports = {
testEnvironment: 'node',
testMatch: ['**/__tests__/**/*.test.js'],
collectCoverage: true,
coverageReporters: ['text', 'lcov'],
};
Loading