Skip to content

Commit

Permalink
Merge pull request #11 from sammynave/sveltekit-2
Browse files Browse the repository at this point in the history
Sveltekit 2
  • Loading branch information
sammynave committed Dec 17, 2023
2 parents b1729e7 + 378da2c commit ba05619
Show file tree
Hide file tree
Showing 99 changed files with 2,414 additions and 1,191 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ REDIS_WS_SERVER=redis://:password@localhost:6379
REDIS_WS_PASSWORD=password

# needed for docker initialization
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_DB=startup
20 changes: 20 additions & 0 deletions .env.testing.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Public
PUBLIC_FAKTORY_URL=http://localhost:7420

# Private
FAKTORY_URL=tcp://localhost:7419
FAKTORY_PASSWORD=''
DATABASE_URL=postgres://postgres:password@localhost:5432/startup-testing
SENDGRID_API_KEY='YOUR_API_KEY'
REDIS_WS_SERVER=redis://:test-password@localhost:6379
REDIS_WS_PASSWORD=test-password

# needed for docker initialization
POSTGRES_USER=postgres
POSTGRES_PASSWORD=password
POSTGRES_DB=startup-testing

# https://node.testcontainers.org/supported-container-runtimes/
# playwright workaround with colima
NODE_OPTIONS=--dns-result-order=ipv4first

83 changes: 83 additions & 0 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: E2E Tests

run-name: ${{github.actor}} e2e tests

on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
Run-E2E-Tests:
runs-on: ubuntu-latest
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres
# Provide the password for postgres
# Set health checks to wait until postgres has started
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: startup
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 6379:6379
env:
PUBLIC_FAKTORY_URL: http://localhost:7420
FAKTORY_URL: tcp://localhost:7419
FAKTORY_PASSWORD: ''
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: startup
DATABASE_URL: postgres://postgres:password@localhost:5432/startup
# why does this work instead of localhost?
REDIS_WS_SERVER: redis://:password@127.0.0.1:6379
REDIS_WS_PASSWORD: password
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: pnpm
- name: Install deps
run: pnpm install --frozen-lockfile
- name: Playwright
run: pnpx playwright install --with-deps
- name: Migrate DATABASE_URL
run: pnpm run db:migrate
- name: Test
run: pnpm run ci:integration
- name: Upload results
uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
45 changes: 45 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Static Analysis

run-name: ${{github.actor}} static analysis

on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
Run-Lint:
runs-on: ubuntu-latest
env:
PUBLIC_FAKTORY_URL: http://localhost:7420
FAKTORY_URL: tcp://localhost:7419
FAKTORY_PASSWORD: ''
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: startup
DATABASE_URL: postgres://postgres:password@localhost:5432/startup
# why does this work instead of localhost?
REDIS_WS_SERVER: redis://:password@127.0.0.1:6379
REDIS_WS_PASSWORD: password
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: pnpm
- name: Install deps
run: pnpm install --frozen-lockfile
- name: Lint
run: pnpm run lint
- name: Check Types
run: pnpm run check
32 changes: 32 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Unit Tests

run-name: ${{github.actor}} unit tests

on:
push:
branches:
- main
pull_request:

permissions:
contents: read

jobs:
Run-Unit-Tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 20
cache: pnpm
- name: Install deps
run: pnpm install --frozen-lockfile
- name: Test
run: pnpm run ci:unit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ node_modules
.env
.env.*
!.env.example
!.env.testing.example
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
test-results
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
- [x] code climate

# TODO someday

- [ ] CRDT + offline first + absurdSQL
- [ ] liveblocks/partkit style collaboration
- [ ] https://electric-sql.com/docs/intro/local-first


[![Maintainability](https://api.codeclimate.com/v1/badges/a8aace40021825ebb5de/maintainability)](https://codeclimate.com/github/sammynave/startup/maintainability)

# Getting started
Expand Down Expand Up @@ -75,6 +75,17 @@ You'll also need to create an `Env Group` to store the env `PUBLIC_FAKTORY_URL`

See the [Render docs](https://render.com/docs/blueprint-spec) for more info

# Testing

## E2E with Playwright

[Colima + testcontianers work around](https://node.testcontainers.org/supported-container-runtimes/)

```bash
export DOCKER_HOST=unix://${HOME}/.colima/default/docker.sock
export TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock
```

# Integrated websockets server(s)

TODO - rewrite this
Expand All @@ -83,11 +94,11 @@ This repo contains two examples (`/src/routes/app/websocket-example/using-pub-su

Key files:

- `prod-server.ts` - this is how you'll start your prod server (see `render.yaml`)
- `vite.config.ts` - here we create a small plugin to insert the websocket server at `/websocket` path for the dev and preview servers (`configureServer` and `configurePreviewServer`)
- `vite-plugins/vite-plugin-svelte-kit-integrated-websocket-server.ts` - this file contains the functions that create the server (`createWSSGlobalInstance`) and host it (`onHttpServerUpgrade`) referenced in the step above. This technique relies on attaching the websocket server to the global state.
- `ws-server.ts` This file also has utility functions to help out when getting and setting the websocket server: `getStreamWss/getPubSubWss` and `setStreamsWss/setPubSubWss`
- `src/hooks.server.ts` - this file initializes our websocket servers and adds a reference to it to `locals`. this way we can trigger events from other places in our Svelte server, for example, the default action in `src/routes/app/websocket-example/using-streams/+page.server.ts`. Here we're grabbing the server (`sWss`) off of the `event.locals` object and then triggering a reload for all of our connected clients.
- `prod-server.ts` - this is how you'll start your prod server (see `render.yaml`)
- `vite.config.ts` - here we create a small plugin to insert the websocket server at `/websocket` path for the dev and preview servers (`configureServer` and `configurePreviewServer`)
- `vite-plugins/vite-plugin-svelte-kit-integrated-websocket-server.ts` - this file contains the functions that create the server (`createWSSGlobalInstance`) and host it (`onHttpServerUpgrade`) referenced in the step above. This technique relies on attaching the websocket server to the global state.
- `ws-server.ts` This file also has utility functions to help out when getting and setting the websocket server: `getStreamWss/getPubSubWss` and `setStreamsWss/setPubSubWss`
- `src/hooks.server.ts` - this file initializes our websocket servers and adds a reference to it to `locals`. this way we can trigger events from other places in our Svelte server, for example, the default action in `src/routes/app/websocket-example/using-streams/+page.server.ts`. Here we're grabbing the server (`sWss`) off of the `event.locals` object and then triggering a reload for all of our connected clients.

Example files that make use of this setup:

Expand Down
24 changes: 12 additions & 12 deletions components.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"$schema": "https://shadcn-svelte.com/schema.json",
"style": "default",
"tailwind": {
"config": "tailwind.config.js",
"css": "src/app.postcss",
"baseColor": "slate"
},
"aliases": {
"components": "$lib/components",
"utils": "$lib/utils"
}
}
"$schema": "https://shadcn-svelte.com/schema.json",
"style": "default",
"tailwind": {
"config": "tailwind.config.js",
"css": "src/app.postcss",
"baseColor": "slate"
},
"aliases": {
"components": "$lib/components",
"utils": "$lib/utils"
}
}
2 changes: 1 addition & 1 deletion dev-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ async function startWorker() {
});
}

startWorker();
startWorker();
71 changes: 36 additions & 35 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,67 @@
"build:render": "bash ./render-build.sh",
"preview": "vite preview",
"prod": "tsm ./prod-server.ts",
"test": "npm run test:integration && npm run test:unit",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --plugin-search-dir . --check . && eslint .",
"format": "prettier --plugin-search-dir . --write .",
"test:integration": "playwright test",
"test:ui": "playwright test --ui",
"ci:integration": "playwright test",
"ci:unit": "vitest run",
"test:integration": "playwright test --ui --config ./playwright.local.config.ts",
"test:unit": "vitest",
"db:generate": "drizzle-kit generate:pg",
"db:push": "drizzle-kit push:pg",
"db:migrate": "node ./migrate.js",
"db:drop-migration": "drizzle-kit drop"
},
"devDependencies": {
"@playwright/test": "^1.39.0",
"@sveltejs/adapter-auto": "^2.1.0",
"@sveltejs/adapter-node": "^1.3.1",
"@sveltejs/kit": "^1.26.0",
"@playwright/test": "^1.40.1",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/adapter-node": "^2.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.1",
"@testcontainers/postgresql": "^10.3.2",
"@types/ws": "^8.5.9",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"autoprefixer": "^10.4.14",
"@types/ws": "^8.5.10",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"autoprefixer": "^10.4.16",
"dotenv": "^16.3.1",
"drizzle-kit": "^0.19.13",
"eslint": "^8.52.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-svelte": "^2.34.0",
"postcss": "^8.4.24",
"postcss-load-config": "^4.0.1",
"drizzle-kit": "^0.20.6",
"eslint": "^8.55.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.35.1",
"postcss": "^8.4.32",
"postcss-load-config": "^5.0.2",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"svelte": "^4.2.2",
"svelte-check": "^3.5.2",
"svelte": "^4.2.8",
"svelte-check": "^3.6.2",
"svelte-headless-table": "^0.17.7",
"tailwindcss": "^3.3.2",
"tailwindcss": "^3.3.6",
"testcontainers": "^10.3.2",
"tslib": "^2.6.2",
"tsm": "^2.3.0",
"typescript": "^5.2.2",
"vite": "^4.5.0",
"vitest": "^0.32.4"
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vitest": "^1.0.4"
},
"type": "module",
"dependencies": {
"@lucia-auth/adapter-postgresql": "^2.0.1",
"bits-ui": "^0.6.2",
"@lucia-auth/adapter-postgresql": "^2.0.2",
"bits-ui": "^0.11.7",
"clsx": "^2.0.0",
"drizzle-orm": "^0.28.6",
"drizzle-orm": "^0.29.1",
"faktory-worker": "^4.5.1",
"formsnap": "^0.2.0",
"formsnap": "^0.4.1",
"ioredis": "^5.3.2",
"lucia": "^2.7.1",
"lucide-svelte": "^0.288.0",
"nanoid": "^5.0.3",
"postgres": "^3.4.0",
"sveltekit-superforms": "^1.8.0",
"tailwind-merge": "^1.14.0",
"tailwind-variants": "^0.1.14",
"ws": "^8.14.2",
"lucia": "^2.7.5",
"lucide-svelte": "^0.297.0",
"nanoid": "^5.0.4",
"postgres": "^3.4.3",
"sveltekit-superforms": "^1.12.0",
"tailwind-merge": "^2.1.0",
"tailwind-variants": "^0.1.18",
"ws": "^8.15.1",
"zod": "^3.22.4"
}
}
Loading

0 comments on commit ba05619

Please sign in to comment.