@owlmeans/test 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,3 +9,20 @@ Foundation helpers shared by the OwlMeans test packages and individual package t
9
9
  - `loadFixture<T>(relPath)` — JSON fixture loader rooted at the consuming package's `tests/fixtures/`.
10
10
 
11
11
  Tests must be located at `packages/<pkg>/tests/`, named `*.spec.ts`. See the `testing-overview` skill for the full strategy.
12
+
13
+ <!-- owlmeans:agent-guidance:start -->
14
+ ## Agent guidance
15
+
16
+ This package ships embedded Claude Code skills and GitHub Copilot instructions under
17
+ `agent-meta/`. After installing your `@owlmeans/*` packages, run the OwlMeans
18
+ agent-skills installer to place them into your project's native locations
19
+ (`.claude/skills/` and `.github/instructions/`):
20
+
21
+ ```sh
22
+ npx @owlmeans/agent-skills
23
+ ```
24
+
25
+ The embedded files are version-matched to this package release. Do not edit them
26
+ directly — they are regenerated on each publish. To contribute guidance edits,
27
+ open a PR against the source monorepo.
28
+ <!-- owlmeans:agent-guidance:end -->
@@ -0,0 +1,16 @@
1
+ ---
2
+ applyTo: "**/*.test.ts, **/*.spec.ts, **/*.ts"
3
+ ---
4
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
5
+
6
+ # Category A — Unit Tests (no mocks)
7
+
8
+ - Tests in `<your-package>/tests/*.spec.ts`. Use `bun:test` (`describe`, `test`, `expect`).
9
+ - Build a real context once in `tests/context.ts` and export a helper specs call. No mocks.
10
+ - Sibling packages are imported normally. If you feel the urge to mock one, you're in the wrong category — move to integration instead.
11
+ - Cover `.claude/skills/<pkg>/SKILL.md` and `README.md` cases first.
12
+ - Max 3-4 tests per method/function.
13
+ - Don't test utils, types, or context plumbing.
14
+ - Per-package `package.json` script: `"test": "bun test ./tests"`.
15
+
16
+ See `.claude/skills/testing-unit/SKILL.md` for the full pattern.
@@ -0,0 +1,30 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "package": "@owlmeans/test",
4
+ "version": "0.1.8",
5
+ "generatedAt": "2026-06-11T16:30:27.164Z",
6
+ "canonicalRepo": "https://github.com/owlmeans/common",
7
+ "entries": [
8
+ {
9
+ "kind": "skill",
10
+ "name": "testing-overview",
11
+ "category": "multi-package",
12
+ "file": "skills/testing-overview/SKILL.md",
13
+ "canonicalPath": ".claude/skills/testing-overview/SKILL.md"
14
+ },
15
+ {
16
+ "kind": "skill",
17
+ "name": "testing-unit",
18
+ "category": "package-specific",
19
+ "file": "skills/testing-unit/SKILL.md",
20
+ "canonicalPath": ".claude/skills/testing-unit/SKILL.md"
21
+ },
22
+ {
23
+ "kind": "instruction",
24
+ "name": "testing-unit",
25
+ "category": "package-specific",
26
+ "file": "instructions/testing-unit.instructions.md",
27
+ "canonicalPath": ".github/instructions/testing-unit.instructions.md"
28
+ }
29
+ ]
30
+ }
@@ -0,0 +1,55 @@
1
+ ---
2
+ name: testing-overview
3
+ description: Decision matrix for which testing strategy to use per package in the OwlMeans Common monorepo (unit no-mocks / unit with auth-mocks / env-gated integration / Playwright acceptance) plus the eight invariants that apply to every package. Auto-invoked when "tests" or "testing" is mentioned.
4
+ ---
5
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
6
+
7
+ # Testing Strategy — OwlMeans Common
8
+
9
+ Every package falls into exactly one of four testing categories. The category drives which `@owlmeans/test*` package(s) the tests depend on, where tests live, and what mocking is allowed.
10
+
11
+ ## Categories
12
+
13
+ | Cat | Strategy | Tests location | Runtime | Mocks? | Skill |
14
+ |-----|----------|----------------|---------|--------|-------|
15
+ | A | Unit, real sibling-package imports | `tests/*.spec.ts` | `bun test` | None | `testing-unit` |
16
+ | B | Unit with auth/authz mocks | `tests/*.spec.ts` | `bun test` | Only auth/authz, only via `@owlmeans/test-auth` | `testing-auth-unit` |
17
+ | C | Integration, env-gated | `tests/*.spec.ts` | `bun test` | None | `testing-integration` |
18
+ | D | Component-level acceptance, real chromium | `tests/*.spec.ts` | `bun test` (drives Playwright as a library) | None | `testing-ui` |
19
+
20
+ ## Package → category map
21
+
22
+ - **A** (~31): `basic-ids`, `context`, `config`, `error`, `flow`, `i18n`, `module`, `route`, `router`, `resource`, `socket`, `state`, `static-resource`, `client-route`, `client-config`, `client-context`, `client-resource`, `client-module`, `client-flow`, `client-socket`, `server-route`, `server-config`, `server-context`, `server-module`, `payment`, `api`, `api-config`, `api-config-client`, `api-config-server`, `web-router`, `web-db`
23
+ - **B** (~13): `auth`, `auth-common`, `basic-keys`, `basic-envelope`, `did`, `client-auth`, `client-did`, `server-auth`, `oidc`, `server-oidc-rp`, `server-oidc-provider`, `web-oidc-rp`, `web-oidc-provider`, `wled`, `client-payment`
24
+ - **C** (~10): `mongo`, `mongo-resource`, `redis`, `redis-resource`, `kluster`, `storage-common`, `storage-resource`, `image-resource`, `server-api`, `server-app`, `queue`
25
+ - **D** (~8): `client`, `client-i18n`, `client-panel`, `client-wl`, `web-client`, `web-flow`, `web-panel`, `web-wl`
26
+ - **None**: `dep-config`, `_tpl`
27
+
28
+ ## Eight invariants (apply everywhere)
29
+
30
+ 1. **Tests live next to `src/` in `<your-package>/tests/`**, named `*.spec.ts`. They are outside `rootDir: ./src/` so `tsc -b` already excludes them.
31
+ 2. **One real context per package**, set up in `tests/context.ts`. It builds a real `BasicContext` / server / client context (whatever the package documents in its `SKILL.md`), provisions real sibling-package services and resources, and exports a single helper specs import.
32
+ 3. **Cross-package imports are real.** No mocks for sibling packages. Auth/authz is the only mockable boundary, only in category B, only via `@owlmeans/test-auth`.
33
+ 4. **Don't test context wiring** in every package. Trust `@owlmeans/context`'s own tests.
34
+ 5. **Don't test utils. Don't test types.** Max 3-4 tests per method/function.
35
+ 6. **Cover the package's `SKILL.md` and `README.md` cases first.** Those are the documented consumption surfaces — tests validate them as executable specs before reaching for internal coverage.
36
+ 7. **Env-gated provisioning** for category C: if a required env var is empty, neither the dependent service is provisioned in the test context nor are the specs that need it executed. Specs self-skip with a printed reason — never fail.
37
+ 8. **No new mocks.** If a test seems to need a mock that isn't auth/authz, the test belongs in category C (and the package belongs in category C) — write an integration test, not a fake.
38
+
39
+ ## Running tests
40
+
41
+ - All packages from root: `bun run test`
42
+ - One package: `cd <your-package> && bun test ./tests` — same line for every category
43
+ - Integration tests: `MONGO_URL=... bun run test` — empty values skip cleanly
44
+ - One-time UI setup: `bunx playwright install chromium` (downloads the browser the `playwright` library drives in category D)
45
+
46
+ ## What to test (always)
47
+
48
+ Services, components, helpers, and broad domain models that aren't already exposed via a service. Cover the `SKILL.md` use cases first, then the `README.md` examples, then any non-trivial invariants documented in code comments.
49
+
50
+ ## What NOT to test
51
+
52
+ - Utils (`src/utils/*` or `src/utils.ts`) — internal package implementation.
53
+ - Type-only files (`src/types.ts`).
54
+ - Context plumbing — already covered by `@owlmeans/context`.
55
+ - Anything you'd need to mock a sibling OwlMeans package to test.
@@ -0,0 +1,82 @@
1
+ ---
2
+ name: testing-unit
3
+ description: Category-A unit tests for OwlMeans Common packages — no mocks, real sibling-package imports, services/components/helpers focus. Auto-invoked when writing tests in non-auth, non-integration, non-UI packages.
4
+ ---
5
+ <!-- AUTO-GENERATED — do not edit. Regenerate via sync-agent-meta. -->
6
+
7
+ # Unit Tests — Category A (no mocks)
8
+
9
+ Apply this skill when adding tests to packages in category A (see `testing-overview`). The list includes core abstractions (`context`, `config`, `error`, `module`, `route`, `resource`, …) and platform-agnostic services (`api`, `state`, `flow`, `i18n`, `client-flow`, `client-socket`, `server-route`, `server-context`, `web-router`, `web-db`, …).
10
+
11
+ ## Layout
12
+
13
+ ```
14
+ <your-package>/
15
+ ├── src/...
16
+ ├── tests/
17
+ │ ├── context.ts # one real context, shared across specs
18
+ │ ├── <area>.spec.ts # *.spec.ts only
19
+ │ └── fixtures/ # JSON fixtures, optional
20
+ ```
21
+
22
+ ## `tests/context.ts` — single source of truth
23
+
24
+ Build a real context exactly the way the package's `SKILL.md` documents downstream apps building it. No mocks. Sibling packages are imported normally.
25
+
26
+ ```ts
27
+ import { AppType, Layer, makeBasicContext } from '@owlmeans/context'
28
+ import type { BasicConfig, BasicContext } from '@owlmeans/context'
29
+
30
+ export const makeTestCtx = (overrides: Partial<BasicConfig> = {}): BasicContext<BasicConfig> =>
31
+ makeBasicContext({
32
+ ready: false,
33
+ service: '<pkg>-tests',
34
+ layer: Layer.Service,
35
+ type: AppType.Backend,
36
+ ...overrides,
37
+ })
38
+ ```
39
+
40
+ Specs import `makeTestCtx()` (or whatever helper fits) and never call `makeBasicContext` directly. This keeps the wiring centralised so a context-shape change only touches one file per package.
41
+
42
+ ## Spec shape
43
+
44
+ ```ts
45
+ import { describe, expect, test } from 'bun:test'
46
+ import { makeTestCtx } from './context.js'
47
+
48
+ describe('<package> — <area>', () => {
49
+ test('does the thing the SKILL.md documents', () => {
50
+ const ctx = makeTestCtx()
51
+ /* exercise the real public API */
52
+ })
53
+ })
54
+ ```
55
+
56
+ Use `bun:test`'s `describe`/`test`/`expect`. No `vi.mock`, no `jest.mock`, no test doubles.
57
+
58
+ ## Rules
59
+
60
+ - **Max 3-4 tests per method/function.** Cover the happy path, the documented edge cases, and at most one invariant.
61
+ - **Test services, components, helpers, broad domain models.** Test domain models only when the model has functionality the service facade does not expose.
62
+ - **Skip utils** (`src/utils/*`) — they are internal.
63
+ - **Skip types** (`src/types.ts`).
64
+ - **Cover `SKILL.md` and `README.md` first.** Tests are executable docs of the documented use cases.
65
+ - **No mocks.** If a test seems to need one, the package likely belongs in category C (integration) or the test is asking the wrong question.
66
+ - Cross-package imports are normal `import` statements; the workspace links resolve them.
67
+
68
+ ## Wiring `bun test`
69
+
70
+ Per-package `package.json`:
71
+
72
+ ```json
73
+ "scripts": {
74
+ "test": "bun test ./tests"
75
+ }
76
+ ```
77
+
78
+ `bun:test` is built-in — no devDeps to add. The root `bun run test` script runs every package's `test` script via workspace filters.
79
+
80
+ ## When auth shows up
81
+
82
+ If a category-A package starts to need an authenticated identity to exercise a behaviour, that behaviour belongs in a different package — the auth-aware sibling. Don't reach for `@owlmeans/test-auth` here. Move the test to category B (and possibly the implementation) instead of dragging an auth dep into a low-layer package.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/test",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -21,10 +21,10 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
- "@owlmeans/context": "^0.1.7"
24
+ "@owlmeans/context": "^0.1.8"
25
25
  },
26
26
  "devDependencies": {
27
- "@owlmeans/dep-config": "^0.1.7",
27
+ "@owlmeans/dep-config": "^0.1.8",
28
28
  "@types/bun": "^1.3.0",
29
29
  "nodemon": "^3.1.11",
30
30
  "typescript": "^6.0.2"