File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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 ( / i m a g e \/ g i f / ) ;
16+ expect ( res . headers [ 'cache-control' ] ) . toMatch ( / n o - s t o r e / ) ;
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 ( / t e x t \/ h t m l / ) ;
32+ expect ( res . text ) . toMatch ( / T i n y T r a c k e r / ) ;
33+ } ) ;
34+ } ) ;
Original file line number Diff line number Diff line change 1+ /** @type {import('jest').Config } */
2+ module . exports = {
3+ testEnvironment : 'node' ,
4+ testMatch : [ '**/__tests__/**/*.test.js' ] ,
5+ collectCoverage : true ,
6+ coverageReporters : [ 'text' , 'lcov' ] ,
7+ } ;
You can’t perform that action at this time.
0 commit comments