test: add vitest

* feature(root): add vitest and some basic tests

* fix(test): after rebase + added referrars test and more sites

* fix(test): test broken after rebase

* fix(test): provide db url to make prisma happy

* fix tests
This commit is contained in:
Carl-Gerhard Lindesvärd
2025-06-06 19:14:18 +02:00
committed by GitHub
parent 09c83ddeb4
commit 5445d6309e
23 changed files with 1131 additions and 3133 deletions

View File

@@ -1,56 +0,0 @@
import fs from 'node:fs';
import path from 'node:path';
// extras
const extraReferrers = {
'bsky.app': { type: 'social', name: 'Bluesky' },
};
function transform(data: any) {
const obj: Record<string, unknown> = {};
for (const type in data) {
for (const name in data[type]) {
const domains = data[type][name].domains ?? [];
for (const domain of domains) {
obj[domain] = {
type,
name,
};
}
}
}
return obj;
}
async function main() {
// Get document, or throw exception on error
try {
const data = await fetch(
'https://s3-eu-west-1.amazonaws.com/snowplow-hosted-assets/third-party/referer-parser/referers-latest.json',
).then((res) => res.json());
fs.writeFileSync(
path.resolve(__dirname, '../src/referrers/index.ts'),
[
'// This file is generated by the script get-referrers.ts',
'',
'// The data is fetch from snowplow-referer-parser https://github.com/snowplow-referer-parser/referer-parser',
`// The orginal referers.yml is based on Piwik's SearchEngines.php and Socials.php, copyright 2012 Matthieu Aubry and available under the GNU General Public License v3.`,
'',
`const referrers: Record<string, { type: string, name: string }> = ${JSON.stringify(
{
...transform(data),
...extraReferrers,
},
)} as const;`,
'export default referrers;',
].join('\n'),
'utf-8',
);
} catch (e) {
console.log(e);
}
}
main();