codefeed/test/test.ts

41 lines
1.5 KiB
TypeScript

import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
import * as codefeed from '../ts/index.js';
import * as qenv from '@push.rocks/qenv';
const testQenv = new qenv.Qenv('./', '.nogit/');
let testCodeFeed: codefeed.CodeFeed;
tap.test('first test', async () => {
const token = await testQenv.getEnvVarOnDemand('GITEA_TOKEN');
// console.log('token', token);
// seed lastRunTimestamp to 1 year ago and enable in-memory caching for 1 year
const oneYearMs = 365 * 24 * 60 * 60 * 1000;
const oneYearAgo = new Date(Date.now() - oneYearMs).toISOString();
testCodeFeed = new codefeed.CodeFeed(
'https://code.foss.global',
token,
oneYearAgo,
{ enableCache: true, cacheWindowMs: oneYearMs, enableNpmCheck: false }
);
expect(testCodeFeed).toBeInstanceOf(codefeed.CodeFeed);
});
tap.test('fetchAllCommitsFromInstance', async () => {
const commits = await testCodeFeed.fetchAllCommitsFromInstance();
// log the actual results so we can inspect them
console.log('Fetched commits:', JSON.stringify(commits, null, 2));
expect(commits).toBeArray();
expect(commits.length).toBeGreaterThan(0);
// expect(commits[0]).toBeTypeofObject();
expect(commits[0].baseUrl).toBeTypeofString();
expect(commits[0].org).toBeTypeofString();
expect(commits[0].repo).toBeTypeofString();
expect(commits[0].timestamp).toBeTypeofString();
expect(commits[0].hash).toBeTypeofString();
expect(commits[0].commitMessage).toBeTypeofString();
expect(commits[0].tagged).toBeTypeofBoolean();
});
tap.start();