chore: seminarhof customer project
This commit is contained in:
4
packages/functions/tests/.env.test
Normal file
4
packages/functions/tests/.env.test
Normal file
@@ -0,0 +1,4 @@
|
||||
# Environment variables required by createConfig() during tests.
|
||||
# Add any env vars your config.ts reads at module load time.
|
||||
# This file is loaded via --env-file and is NOT committed to version control.
|
||||
NODE_ENV=test
|
||||
24
packages/functions/tests/package.json
Normal file
24
packages/functions/tests/package.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "tests",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Function test harness — Cucumber over in-process Pikku RPC with stubbed services.",
|
||||
"scripts": {
|
||||
"test": "node --env-file=.env.test node_modules/.bin/cucumber-js --config tests/cucumber.mjs --tags 'not @skip'",
|
||||
"test:tag": "node --env-file=.env.test node_modules/.bin/cucumber-js --config tests/cucumber.mjs --tags",
|
||||
"coverage": "pikku tests coverage",
|
||||
"tsc": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"@pikku/cucumber": "0.12.9",
|
||||
"@pikku/kysely-node-sqlite": "^0.12.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cucumber/cucumber": "^11.0.0",
|
||||
"@types/node": "^22",
|
||||
"c8": "^10.0.0",
|
||||
"tsx": "^4.21.0",
|
||||
"typescript": "~5.8.0"
|
||||
}
|
||||
}
|
||||
7
packages/functions/tests/tests/cucumber.mjs
Normal file
7
packages/functions/tests/tests/cucumber.mjs
Normal file
@@ -0,0 +1,7 @@
|
||||
export default {
|
||||
requireModule: ['tsx'],
|
||||
require: ['tests/support/**/*.ts', 'tests/steps/**/*.ts'],
|
||||
paths: ['tests/features/**/*.feature'],
|
||||
format: ['progress', 'html:tests/reports/cucumber-report.html'],
|
||||
forceExit: true,
|
||||
}
|
||||
24
packages/functions/tests/tests/features/example.feature
Normal file
24
packages/functions/tests/tests/features/example.feature
Normal file
@@ -0,0 +1,24 @@
|
||||
Feature: Example function test
|
||||
|
||||
Starter scenario created by `pikku tests init`. It uses only the built-in
|
||||
pikku/cucumber steps (no custom step code) and passes out of the box, so the
|
||||
Run-tests button and coverage report work immediately. Replace it with real
|
||||
scenarios that call your RPCs — see the commented example at the bottom.
|
||||
|
||||
Scenario: the function-test harness is wired up
|
||||
Given the data "example" is:
|
||||
| hello | world |
|
||||
Then the data "example" is not empty
|
||||
|
||||
# Real example — call one of your RPCs and assert the outcome. Uncomment and
|
||||
# adapt (run `pikku meta` to list versioned RPC names and input schemas):
|
||||
#
|
||||
# Scenario: an anonymous user cannot reach a protected RPC
|
||||
# When an anonymous user calls "yourProtectedRpc"
|
||||
# Then the call fails with "Unauthorized"
|
||||
#
|
||||
# Scenario: a public RPC returns data
|
||||
# When an anonymous user calls "yourPublicRpc" with:
|
||||
# | someField | someValue |
|
||||
# Then the call succeeds
|
||||
# And the result has "id"
|
||||
7
packages/functions/tests/tests/support/hooks.ts
Normal file
7
packages/functions/tests/tests/support/hooks.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import '../../../.pikku/pikku-bootstrap.gen.js'
|
||||
import { Before, After, BeforeAll, AfterAll, setDefaultTimeout, Given, When, Then } from '@cucumber/cucumber'
|
||||
import { registerHooks, registerCommonSteps } from '@pikku/cucumber'
|
||||
import { db } from './services.js'
|
||||
|
||||
registerHooks({ Before, After, BeforeAll, AfterAll, setDefaultTimeout }, db)
|
||||
registerCommonSteps({ Given, When, Then })
|
||||
44
packages/functions/tests/tests/support/services.ts
Normal file
44
packages/functions/tests/tests/support/services.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { createNodeSqliteKysely, createCoercionPlugin } from '@pikku/kysely-node-sqlite'
|
||||
import { createDbUtils, type StubTracker } from '@pikku/cucumber'
|
||||
import { createConfig } from '../../../src/config.js'
|
||||
import { createSingletonServices } from '../../../src/services.js'
|
||||
import { coercionMap } from '../../../.pikku/db/coercion.gen.js'
|
||||
import type { DB } from '../../../.pikku/db/schema.js'
|
||||
import { dirname, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url))
|
||||
const repoRoot = (p: string) => resolve(__dirname, '../../../../..', p)
|
||||
|
||||
export const db = createDbUtils({
|
||||
migrationsDir: repoRoot('db/sqlite'),
|
||||
seedFile: repoRoot('db/sqlite-seed.sql'),
|
||||
})
|
||||
|
||||
type StubKysely = ReturnType<typeof createNodeSqliteKysely<DB>>
|
||||
|
||||
const REAL_SERVICES = (kysely: StubKysely) => ({ kysely })
|
||||
|
||||
export async function createStubServices(dbFile: string, tracker: StubTracker) {
|
||||
const kysely = createNodeSqliteKysely<DB>({
|
||||
filename: dbFile,
|
||||
camelCase: true,
|
||||
plugins: [createCoercionPlugin({ map: coercionMap })],
|
||||
})
|
||||
|
||||
const real = REAL_SERVICES(kysely)
|
||||
const injected = new Proxy(real as Record<string, unknown>, {
|
||||
get(target, prop: string) {
|
||||
if (prop in target) return target[prop]
|
||||
return tracker.stub(prop)
|
||||
},
|
||||
})
|
||||
|
||||
const config = await createConfig()
|
||||
const services = await createSingletonServices(
|
||||
{ ...config, dev: { db: { file: dbFile } } } as never,
|
||||
injected as never,
|
||||
)
|
||||
|
||||
return { services, kysely }
|
||||
}
|
||||
5
packages/functions/tests/tests/support/world.ts
Normal file
5
packages/functions/tests/tests/support/world.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { World, setWorldConstructor } from '@cucumber/cucumber'
|
||||
import { createFunctionWorld } from '@pikku/cucumber'
|
||||
import { createStubServices } from './services.js'
|
||||
|
||||
createFunctionWorld(World, setWorldConstructor, createStubServices)
|
||||
18
packages/functions/tests/tsconfig.json
Normal file
18
packages/functions/tests/tsconfig.json
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"types": [
|
||||
"node"
|
||||
],
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true,
|
||||
"resolveJsonModule": true,
|
||||
"strict": true
|
||||
},
|
||||
"include": [
|
||||
"tests/**/*.ts"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user