9 files changed
+834
-136
No files matched your search
@@ -0,0 +1,26 @@
|
|||||||
|
name: Node.js CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ['main']
|
||||||
|
pull_request:
|
||||||
|
branches: ['main']
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
node-version: [20.x]
|
||||||
|
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: ${{ matrix.node-version }}
|
||||||
|
cache: 'npm'
|
||||||
|
- run: npm install
|
||||||
|
- run: npm test
|
||||||
+4
-2
@@ -5,6 +5,7 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
|
"test": "vitest",
|
||||||
"preview": "vite preview",
|
"preview": "vite preview",
|
||||||
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
|
||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
|
||||||
@@ -14,9 +15,9 @@
|
|||||||
"@sveltejs/kit": "^1.5.0",
|
"@sveltejs/kit": "^1.5.0",
|
||||||
"@types/nprogress": "^0.2.0",
|
"@types/nprogress": "^0.2.0",
|
||||||
"autoprefixer": "^10.4.14",
|
"autoprefixer": "^10.4.14",
|
||||||
|
"jsdom": "^22.1.0",
|
||||||
"nprogress": "^0.2.0",
|
"nprogress": "^0.2.0",
|
||||||
"postcss": "^8.4.24",
|
"postcss": "^8.4.24",
|
||||||
"rollup-plugin-visualizer": "^5.9.2",
|
|
||||||
"svelte": "^3.54.0",
|
"svelte": "^3.54.0",
|
||||||
"svelte-check": "^3.0.1",
|
"svelte-check": "^3.0.1",
|
||||||
"svelte-hero-icons": "^5.0.0",
|
"svelte-hero-icons": "^5.0.0",
|
||||||
@@ -24,7 +25,8 @@
|
|||||||
"tailwindcss": "^3.3.2",
|
"tailwindcss": "^3.3.2",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.0.0",
|
||||||
"vite": "^4.3.0"
|
"vite": "^4.3.0",
|
||||||
|
"vitest": "^0.33.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lemmy-js-client": "^0.18.0-rc.2"
|
"lemmy-js-client": "^0.18.0-rc.2"
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
export let date: Date
|
export let date: Date
|
||||||
|
export let relativeTo: Date | undefined
|
||||||
|
|
||||||
function formatRelativeDate(date: Date) {
|
function formatRelativeDate(date: Date) {
|
||||||
const now = Date.now()
|
const now = relativeTo?.getTime() ?? Date.now()
|
||||||
|
|
||||||
const diffInMillis = now - date.getTime()
|
const diffInMillis = now - date.getTime()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { tick } from 'svelte'
|
||||||
|
import FormattedNumber from '../src/lib/components/util/FormattedNumber.svelte'
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
describe('FormattedNumber.svelte', () => {
|
||||||
|
let host = document.createElement('div')
|
||||||
|
host.setAttribute('id', 'host')
|
||||||
|
document.body.appendChild(host)
|
||||||
|
|
||||||
|
it('mounts', () => {
|
||||||
|
const instance = new FormattedNumber({
|
||||||
|
target: host,
|
||||||
|
props: {
|
||||||
|
number: 1000,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(instance).toBeTruthy()
|
||||||
|
expect(host.innerHTML).toBeTruthy()
|
||||||
|
})
|
||||||
|
it('formats numbers correctly', async () => {
|
||||||
|
const instance = new FormattedNumber({
|
||||||
|
target: host,
|
||||||
|
props: {
|
||||||
|
number: 1100,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(instance).toBeTruthy()
|
||||||
|
|
||||||
|
expect(host.innerHTML).toContain('1.1K')
|
||||||
|
|
||||||
|
instance.$set({ number: 5000 })
|
||||||
|
await tick()
|
||||||
|
expect(host.innerHTML).toContain('5K')
|
||||||
|
|
||||||
|
instance.$set({ number: 6_320_000 })
|
||||||
|
await tick()
|
||||||
|
expect(host.innerHTML).toContain('6.3M')
|
||||||
|
|
||||||
|
instance.$set({
|
||||||
|
options: {
|
||||||
|
notation: 'standard',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
await tick()
|
||||||
|
expect(host.innerHTML).toContain('6,320,000')
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { isImage } from '../src/lib/ui/image.js'
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
describe('lemmy utilities', () => {
|
||||||
|
it('checks image URLs correctly', () => {
|
||||||
|
expect(isImage(`https://example.com/img.jpg?thumb=28`)).toBeTruthy()
|
||||||
|
expect(isImage(`https://test.dev/file/img.webp?great`)).toBeTruthy()
|
||||||
|
expect(isImage(`https://test.dev/file/img.jpeg?test=false`)).toBeTruthy()
|
||||||
|
expect(isImage(`https://test.dev/file/img.bmp#awesome`)).toBeTruthy()
|
||||||
|
expect(isImage(`https://test.dev/file/img.png#awesome`)).toBeTruthy()
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import RelativeDate from '../src/lib/components/util/RelativeDate.svelte'
|
||||||
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
|
describe('RelativeDate.svelte', () => {
|
||||||
|
let host = document.createElement('div')
|
||||||
|
host.setAttribute('id', 'host')
|
||||||
|
document.body.appendChild(host)
|
||||||
|
|
||||||
|
const testDate = new Date('2023-01-01 00:00:00')
|
||||||
|
const testRelativeTo = new Date('2023-01-01 01:00:00')
|
||||||
|
|
||||||
|
it('mounts', () => {
|
||||||
|
let host = document.createElement('div')
|
||||||
|
const instance = new RelativeDate({
|
||||||
|
target: host,
|
||||||
|
props: {
|
||||||
|
date: new Date(),
|
||||||
|
relativeTo: new Date(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(instance).toBeTruthy()
|
||||||
|
})
|
||||||
|
it('shows the correct date', () => {
|
||||||
|
const instance = new RelativeDate({
|
||||||
|
target: host,
|
||||||
|
props: { date: testDate, relativeTo: testRelativeTo },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(instance).toBeTruthy()
|
||||||
|
expect(host.innerHTML).toContain('1 hour ago')
|
||||||
|
})
|
||||||
|
})
|
||||||
+1
-2
@@ -1,7 +1,6 @@
|
|||||||
import { sveltekit } from '@sveltejs/kit/vite'
|
import { sveltekit } from '@sveltejs/kit/vite'
|
||||||
import { visualizer } from 'rollup-plugin-visualizer'
|
|
||||||
import { defineConfig, type PluginOption } from 'vite'
|
import { defineConfig, type PluginOption } from 'vite'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [sveltekit(), visualizer() as PluginOption],
|
plugins: [sveltekit()],
|
||||||
})
|
})
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import { svelte } from '@sveltejs/vite-plugin-svelte'
|
||||||
|
import { defineConfig } from 'vitest/dist/config'
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
// @ts-ignore
|
||||||
|
plugins: [svelte()],
|
||||||
|
test: {
|
||||||
|
globals: true,
|
||||||
|
environment: 'jsdom',
|
||||||
|
},
|
||||||
|
})
|
||||||
Reference in new issue
Block a user