LIST

svelte vitest repository integration test

inspiration: db test with in-memory postgres https://github.com/drizzle-team/drizzle-orm/issues/4205 separate tests https://github.com/vitest-dev/vitest/discussions/4675 https://vitest.dev/guide/workspace.html (https://svelte.dev/docs/svelte/testing) (https://vitest.dev/api/vi.html#vi-mock) //vitest.workspace.ts import { defineWorkspace } from 'vitest/config' import tsconfigPaths from "vite-tsconfig-paths" import { sveltekit } from '@sveltejs/kit/vite'; export default defineWorkspace([ { test: { name: 'unit', include: ['**/*.spec.ts'], exclude: [ '**/*architecture.spec.ts', '**/*.spec.svelte.ts', '**/**.db.spec.ts' ], }, }, { plugins: [sveltekit()], test: { name: 'svelte unit', include: ['**/*.spec.svelte.ts'], }, }, { test: { name: 'architecture', include: ['**/architecture.spec.ts'], // More integration test related setup here....

March 24, 2025

tsarch alternative typscript architecture test

could not get tsarch working npm uninstall tsarch inspired by https://stackoverflow.com/a/69210603/820837 hacked together my own (in a very rough state) src/architecture.spec.ts import { describe, expect, it } from 'vitest'; import { verifyArchitecture } from './archtest'; describe('Architecture test', () => { it('services should not depend on db', async () => { expect(await verifyArchitecture({ filesFromFolder: 'src/lib/server/services', notDependOnFolder: 'src/lib/server/db' })).toEqual([]); }); it('repositories should not depend on services', async () => { expect(await verifyArchitecture({ filesFromFolder: 'src/lib/server/repositories', notDependOnFolder: 'src/lib/server/services' }))....

March 14, 2025

PetProject: Explore cloudflare and svelte-kit

Explore cloudflare and svelte-kit

November 1, 2024

jest typescript test fetch

example-service.ts import { OktaAuth } from '@okta/okta-auth-js' export interface FooData { hello: string } export interface FooResult { success: boolean extraInfoForFrontend: string } export async function foo(oktaAuth: OktaAuth, data: FooData): Promise<FooResult> { const accessToken = oktaAuth.getAccessToken() try { const response = await fetch("/foo", { headers: { Authorization: `Bearer ${accessToken}`, }, }) const json = await response.json() return { success: true, extraInfoForFrontend: json.message, } } catch (err) { return { success: false, extraInfoForFrontend: 'Could not get data', } } } example-service....

March 24, 2023

typescript compile alias cmd for tsc

npm install --save-dev typescript ./.envrc export_alias tsc 'npx tsc'

September 26, 2022

AWS & Typescript Masterclass - 10. Using AWS inside a React project with Amplify

82-93 (82) Section intro introduce AWS Amplify in the browser Get temporary credentials in the Browser CORS issues App will be approaching it’s final form (83) Setup and Amplify install npm i aws-amplify @aws-amplify/auth npm i aws-sdk (84) Cognito login from React code model.ts import {CognitoUser} from '@aws-aplify/auth' export interface User { userName: string cognitoUser: CognitoUser } service/AuthService import {Auth} from "aws-amplify"; import Amplify from "aws-amplify"; import {CognitoUser} from "@aws-amplify/auth"; import {config} from "....

September 17, 2022

AWS & Typescript Masterclass - 9. Front-end for our back-end with React

62-81 (63) Create react app and git npx create-react-app space-finder-frontend --template typescript (64) Basic project structure folder structure components: ui components (*.tsx) model: types (*.ts) services: non-ui code (*.ts) util (*.ts) (65) state, props, child, parent change in state or props triggers re-render props are immutable state is mutable this.setState({ counterState: this.state.counterState + 1 }) use state / props this.state.counterState this.props.counterProp typescript class defines type of Props and State interface Props { counterProp: number } interface State { counterState: number } export class MyComponent extends React....

September 17, 2022

TypeScript: Pattern: Lazy Singleton

singleton.interface.ts export default interface Singleton<T> { getValue: () => T } foo.ts class FooSingleton implements Singleton<Foo> [ private foo: Foo getValue() { if(!foo) this.foo = new Foo(); return this.foo; } } const fooSingleton = new FooSingleton() export default fooSingleton as Singleton<Foo> Do keep in mind the disadvantages of the singleton pattern (src: Design Patterns in TypeScript - Singleton _ The Startup)

September 17, 2022

AWS & Typescript Masterclass - 14. Typescript recap

100-123 (103) Types inferred type var a = 'hello' // inferred string explicit type var a:string = 'hello' // explicit string var arr: string[] = [] arr.push('hello') // ok arr.push(123) // nok ANY - last resort var a:any = 'hello' a = 3; //ok a = true //ok (104) User defined types objects have types functions have types interface interface Person { firstName: string, lastName: string, } type type job = string type specificJob = 'Engineer' | 'Programmer' combining types > found in AWS sdk...

September 12, 2022

AWS & Typescript Masterclass - 6. AWS DynamoDb with CDK and Lambda

32-43 (32) section intro (33) put item npm i @types/aws-lambda (34) getting data from ApiGateway const item = typeof event.body == 'object' ? event.body : JSON.parse(event.body) >? why this check for parsing? is this testing only, or is this random in prod? (35-36) DynamoDB + lambda // create table const table = new Table(this.stack, this.props.tableName, { partitionKey: { name: this.props.primaryKey, type: AttributeType.STRING, }, tableName: this.props.tableName }) // create lambda const id = `${this....

September 12, 2022