Skip to content

Commit

Permalink
Added test for getMeasurements() of compare.ts
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Mar 24, 2024
1 parent bce9857 commit db62d16
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/backend/compare/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export async function getMeasurementsAsJson(
completeRequestAndHandlePromise(start, db, 'get-measurements');
}

async function getMeasurements(
/**
* Only exported for testing, meant to be private.
*/
export async function getMeasurements(
projectSlug: string,
runId: number,
baseCommitId: string,
Expand Down
44 changes: 44 additions & 0 deletions tests/backend/compare/db-measurements.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { describe, expect, it, beforeAll, afterAll } from '@jest/globals';

import {
TestDatabase,
closeMainDb,
createAndInitializeDB
} from '../db/db-testing.js';
import { loadLargePayload } from '../../payload.js';
import { getMeasurements } from '../../../src/backend/compare/compare.js';

describe('compare view: getMeasurements()', () => {
let db: TestDatabase;

beforeAll(async () => {
db = await createAndInitializeDB('compare_view_get_m', 0, false);
const largeTestData = loadLargePayload();
await db.recordAllData(largeTestData);
});

afterAll(async () => {
if (db) return db.close();
});

it('should give expected results for runId 1', async () => {
const results = await getMeasurements(
'Large-Example-Project',
10,
'58666d1c84c652306f930daa72e7a47c58478e86',
'58666d1c84c652306f930daa72e7a47c58478e86',
db
);

expect(results).toHaveLength(1);
if (results === null) return;
expect(results[0].data).toHaveLength(1);
expect(results[0].data[0].criterion).toEqual('total');
expect(results[0].data[0].values).toHaveLength(1);
expect(results[0].data[0].values[0]).toHaveLength(1000);
});
});

afterAll(async () => {
return closeMainDb();
});

0 comments on commit db62d16

Please sign in to comment.