pl-api: initialize tests

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2026-02-27 02:27:57 +01:00
parent 632346642d
commit 00dddbece6
7 changed files with 63 additions and 4 deletions

View File

@ -24,7 +24,10 @@
"lint": "oxlint",
"fmt": "oxfmt",
"fmt:check": "oxfmt --check",
"precommit": "lint-staged"
"precommit": "lint-staged",
"test": "vitest run",
"test:watch": "vitest",
"test:coverage": "vitest run --coverage"
},
"dependencies": {
"blurhash": "^2.0.5",
@ -39,6 +42,7 @@
"@types/http-link-header": "^1.0.7",
"@types/node": "^25.3.0",
"@types/semver": "^7.7.1",
"@vitest/coverage-v8": "4.0.18",
"oxfmt": "^0.35.0",
"oxlint": "^1.50.0",
"typedoc": "^0.28.17",
@ -47,6 +51,7 @@
"typescript": "^5.9.3",
"vite": "^7.3.1",
"vite-plugin-dts": "^4.5.4",
"vitest": "^4.0.18",
"ws": "^8.19.0"
},
"lint-staged": {

View File

@ -0,0 +1,29 @@
import { describe, expect, it } from 'vitest';
import { isDefaultAvatar, isDefaultHeader } from '@/utils/accounts';
describe('isDefaultHeader', () => {
it('detects GoToSocial default header', () => {
expect(isDefaultHeader('https://gts.mkljczk.pl/assets/default_header.webp')).toBe(true);
});
it('detects NeoDB default headers', () => {
expect(isDefaultHeader('https://neodb.social/static/img/missing.5fa23ea9f65e.png')).toBe(true);
});
});
describe('isDefaultAvatar', () => {
it('detects GoToSocial default avatar', () => {
expect(
isDefaultAvatar('https://gts.mkljczk.pl/assets/default_avatars/GoToSocial_icon4.webp'),
).toBe(true);
});
it('returns false for non-default avatar', () => {
expect(
isDefaultAvatar(
'https://example.com/fileserver/01Z0G3Q7MWJ7DKMFYA2DDZ9T32/attachment/original/01KGZ1PKJF1JJ4GVKRBB2F2QME.jpegavatar.jpg',
),
).toBe(false);
});
});

View File

@ -5,6 +5,9 @@
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"paths": {
"@/*": ["./src/*"]
},
/* Bundler mode */
"moduleResolution": "bundler",

View File

@ -1,3 +1,4 @@
import { fileURLToPath, URL } from 'node:url';
import { resolve } from 'path';
import { defineConfig } from 'vite';
@ -5,7 +6,7 @@ import dts from 'vite-plugin-dts';
import pkg from './package.json';
export default defineConfig({
export default defineConfig(() => ({
plugins: [dts({ include: ['lib'], insertTypesEntry: true })],
build: {
copyPublicDir: false,
@ -21,7 +22,21 @@ export default defineConfig({
external: Object.keys(pkg.dependencies),
},
},
resolve: {
alias: [
{
find: '@/',
replacement: fileURLToPath(new URL('./lib/', import.meta.url)),
},
],
},
server: {
port: Number(process.env.PORT ?? 7313),
},
});
test: {
globals: true,
environment: 'jsdom',
include: ['tests/**/*.test.{ts,tsx}'],
css: false,
},
}));