@mrciphersmith/keryx 0.4.29 → 0.4.30
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/dist/cli.js +2408 -1369
- package/dist/core.js +90 -27
- package/dist/keryx-general-worker-entry.js +82 -25
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +2 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +21 -3
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +7 -8
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +31 -7
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -84
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +18 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +12 -45
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -7,78 +7,32 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Vue patterns
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
M4): a composable (`useX()`) is routinely a standalone `.ts` file, not a
|
|
14
|
-
`.vue` SFC, and the reactivity/composable guidance below (`ref()` vs.
|
|
15
|
-
`reactive()`, lifecycle-hook-in-composables rules, the return-shape rule)
|
|
16
|
-
is exactly what a `.ts` composable needs — `ts-js-node`'s own generic
|
|
17
|
-
patterns rule has no notion of Vue's reactivity primitives at all.
|
|
10
|
+
Narrows `core-common-rules`' design-pattern guidance to Vue 3 Composition API
|
|
11
|
+
design. Applies to `*.vue` and plain `*.ts` files (a composable is usually a
|
|
12
|
+
standalone `.ts` file).
|
|
18
13
|
|
|
19
14
|
## Reactivity
|
|
20
15
|
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
-
|
|
26
|
-
props object into loose variables (`const { count } = state`) -- that
|
|
27
|
-
copies the current value and breaks the reactive link. Use `toRefs()`
|
|
28
|
-
(whole object) or `toRef()` (one property) when a template or composable
|
|
29
|
-
needs individual reactive references out of a `reactive()` object.
|
|
30
|
-
- Prefer a `computed()` over a `watch` that just re-derives and assigns a
|
|
31
|
-
value on every dependency change; reach for `watch`/`watchEffect` only
|
|
32
|
-
for a genuine side effect (a fetch, a DOM measurement, a log, syncing to
|
|
33
|
-
an external system).
|
|
34
|
-
- Give every `watch` an explicit, minimal source (`watch(() => props.id,
|
|
35
|
-
...)`, not `watch(props, ...)` with `{ deep: true }` when only one field
|
|
36
|
-
actually needs to be observed) -- a whole-object deep watch fires on every
|
|
37
|
-
unrelated field change and is expensive on large objects.
|
|
38
|
-
- Stop a `watch`/`watchEffect` created outside a component's own setup
|
|
39
|
-
scope (e.g. inside a manually managed subscription) using the stop handle
|
|
40
|
-
it returns; one created directly inside `setup`/`<script setup>` is
|
|
41
|
-
auto-stopped on unmount and needs no manual cleanup.
|
|
16
|
+
- `ref()` for a single primitive or a value often reassigned wholesale; `reactive()` for a fixed-shape object mutated in place. Do not wrap a `reactive()` object in a `ref()`.
|
|
17
|
+
- Never destructure a `reactive()` object or raw (non-`defineProps`) props object into loose variables; use `toRefs()` (whole object) or `toRef()` (one property).
|
|
18
|
+
- Prefer `computed()` over a `watch` that re-derives and assigns a value; use `watch`/`watchEffect` only for a side effect (fetch, DOM measurement, log, external sync).
|
|
19
|
+
- Give every `watch` an explicit, minimal source (`watch(() => props.id, ...)`), not `watch(props, ...)` with `{ deep: true }` for one field.
|
|
20
|
+
- Stop a `watch`/`watchEffect` created outside a component's setup scope with its returned stop handle; one inside `setup`/`<script setup>` needs none.
|
|
42
21
|
|
|
43
22
|
## Composables
|
|
44
23
|
|
|
45
|
-
- Extract a composable (`useX()`) when the same stateful logic
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
- Call composables that use lifecycle hooks (`onMounted`, `onUnmounted`,
|
|
49
|
-
`provide`/`inject`) only from another composable or directly inside
|
|
50
|
-
`setup`/`<script setup>` -- never from inside a callback, `watch`
|
|
51
|
-
handler, or `async` continuation after an `await`, where the active
|
|
52
|
-
component instance is no longer bound.
|
|
53
|
-
- A composable returns refs/computed values and functions, not a plain
|
|
54
|
-
object of dereferenced values -- return `{ count, increment }` (where
|
|
55
|
-
`count` is the `ref` itself), not `{ count: count.value, increment }`,
|
|
56
|
-
or the caller loses reactivity.
|
|
24
|
+
- Extract a composable (`useX()`) when the same stateful logic is needed in more than one component.
|
|
25
|
+
- Call a composable that uses lifecycle hooks (`onMounted`, `onUnmounted`, `provide`/`inject`) only from another composable or directly in `setup`/`<script setup>`, never from a callback, `watch` handler, or after an `await`.
|
|
26
|
+
- A composable returns the refs/computed values themselves and functions, `{ count, increment }`, not `{ count: count.value, increment }`.
|
|
57
27
|
|
|
58
28
|
## Component design
|
|
59
29
|
|
|
60
|
-
- Emit an event (`emit('update:modelValue', v)`) instead of mutating a
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
-
|
|
64
|
-
instead of hand-wiring a prop plus a separately-named update event when
|
|
65
|
-
the semantics are genuinely two-way.
|
|
66
|
-
- Keep template `v-if`/`v-for` on the same element simple; when both are
|
|
67
|
-
needed, wrap the `v-for` in a `<template>` with the `v-if` on each item,
|
|
68
|
-
or filter the source list in a `computed()`, rather than relying on
|
|
69
|
-
`eslint-plugin-vue`'s default precedence to make an implicit filter
|
|
70
|
-
correct.
|
|
71
|
-
- Prefer `provide`/`inject` for state genuinely shared down an arbitrary
|
|
72
|
-
depth of the component tree (theme, current user); prop-drilling two or
|
|
73
|
-
three levels does not need it, and a store (Pinia) is the better fit for
|
|
74
|
-
state shared across unrelated branches of the tree.
|
|
30
|
+
- Emit an event (`emit('update:modelValue', v)`) instead of mutating a prop.
|
|
31
|
+
- Use `v-model` (or `v-model:propName`) for genuinely two-way state instead of a prop plus a separately named update event.
|
|
32
|
+
- When `v-if` and `v-for` are both needed, wrap the `v-for` in a `<template>` with `v-if` on each item, or filter in a `computed()`; do not rely on default precedence.
|
|
33
|
+
- `provide`/`inject` for state shared down an arbitrary depth (theme, current user); prop-drilling two or three levels does not need it; Pinia for state shared across unrelated branches.
|
|
75
34
|
|
|
76
35
|
## Anti-patterns
|
|
77
36
|
|
|
78
|
-
- A `ref`/`reactive`
|
|
79
|
-
|
|
80
|
-
Pinia store with named actions -- it works but loses devtools tracking,
|
|
81
|
-
action naming, and testability.
|
|
82
|
-
- A deeply nested `reactive()` object mutated from many call sites with no
|
|
83
|
-
action layer -- prefer a Pinia store (or a composable with named mutator
|
|
84
|
-
functions) so state changes have one discoverable entry point.
|
|
37
|
+
- A module-scope `ref`/`reactive` mutated from several unrelated components as an ad hoc global store, instead of a Pinia store with named actions.
|
|
38
|
+
- A deeply nested `reactive()` object mutated from many call sites with no action layer; use a Pinia store (or a composable with named mutators).
|
|
@@ -7,54 +7,24 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Vue security
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
|
|
12
|
-
Node.js concerns (request validation, dependency risk) still come from
|
|
10
|
+
Narrows `core-common-rules`' security rules to Vue render-time and routing
|
|
11
|
+
risks. Applies only to `*.vue`; server-side Node.js concerns come from
|
|
13
12
|
`ts-js-node`'s security rule.
|
|
14
13
|
|
|
15
14
|
## Template injection (XSS)
|
|
16
15
|
|
|
17
|
-
- Never bind `v-html` to
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
HTML rendering is genuinely required, and keep the sanitize call next to
|
|
22
|
-
the binding so it cannot be bypassed by a later edit.
|
|
23
|
-
- Prefer interpolation (`{{ value }}`) or bound attributes (`:title="value"`)
|
|
24
|
-
over `v-html` whenever the content is plain text -- both are
|
|
25
|
-
auto-escaped by Vue's compiler, `v-html` is not.
|
|
26
|
-
- Treat a dynamic `:href`/`:src` bound to user-controlled input as
|
|
27
|
-
untrusted: reject or allowlist the scheme (`http:`/`https:`/`mailto:`)
|
|
28
|
-
before binding it, since a `javascript:` URI in an anchor's `href` still
|
|
29
|
-
executes on click.
|
|
30
|
-
- Never pass a user-controlled string into `render()`'s `h()` calls as a
|
|
31
|
-
raw HTML string; `h()` treats string children as text, but a manually
|
|
32
|
-
constructed VNode tree that re-injects raw markup reintroduces the same
|
|
33
|
-
risk `v-html` has.
|
|
16
|
+
- Never bind `v-html` to user-controlled or unsanitized content. If raw HTML is required, sanitize (e.g. DOMPurify) immediately before the binding and keep the call next to it.
|
|
17
|
+
- Prefer `{{ value }}` or `:title="value"` over `v-html` for plain text.
|
|
18
|
+
- Allowlist the scheme (`http:`/`https:`/`mailto:`) of a dynamic `:href`/`:src` bound to user-controlled input.
|
|
19
|
+
- Never pass a user-controlled string into `h()` as raw HTML, or re-inject raw markup through a hand-built VNode tree.
|
|
34
20
|
|
|
35
21
|
## Routing and SSR
|
|
36
22
|
|
|
37
|
-
- Validate and narrow a Vue Router dynamic segment (`route.params.id`)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
value.
|
|
41
|
-
- In a server-rendered (Nuxt or custom SSR) app, never read a secret,
|
|
42
|
-
session token, or unsanitized request header directly into a `ref`/
|
|
43
|
-
`reactive()` value that gets serialized into the client-hydrated state --
|
|
44
|
-
anything in the initial state payload is visible in the page source.
|
|
45
|
-
- Guard a navigation guard's redirect target (`next('/somewhere')` or
|
|
46
|
-
`router.push()`) built from a query parameter against open-redirect: only
|
|
47
|
-
redirect to a same-origin, allowlisted path, never an unvalidated
|
|
48
|
-
`redirect` query value passed straight through.
|
|
23
|
+
- Validate and narrow a Vue Router dynamic segment (`route.params.id`) before using it in a query, redirect target, or `v-html`-rendered value.
|
|
24
|
+
- In a server-rendered app (Nuxt or custom SSR), never read a secret, session token, or unsanitized request header into a `ref`/`reactive()` value serialized into client-hydrated state.
|
|
25
|
+
- Redirect from a navigation guard (`next('/somewhere')`, `router.push()`) to a query-derived target only if it is a same-origin, allowlisted path; never pass a raw `redirect` query value through.
|
|
49
26
|
|
|
50
27
|
## Store and state exposure
|
|
51
28
|
|
|
52
|
-
- Do not store a raw auth token or other secret in a Pinia store field
|
|
53
|
-
|
|
54
|
-
review -- persisted store state survives in the browser's storage past
|
|
55
|
-
the session and is readable by any script with DOM access on that
|
|
56
|
-
origin.
|
|
57
|
-
- Scope a Pinia store's `$reset()` (or manual reset) to run on logout for
|
|
58
|
-
any store holding user-specific data, so a shared browser session (or a
|
|
59
|
-
test suite reusing app state) does not leak the previous user's data
|
|
60
|
-
into the next session.
|
|
29
|
+
- Do not store a raw auth token or other secret in a Pinia store field covered by a `persist`/localStorage plugin without explicit review.
|
|
30
|
+
- Reset (`$reset()` or manual) any Pinia store holding user-specific data on logout.
|
|
@@ -7,63 +7,31 @@ metadata:
|
|
|
7
7
|
|
|
8
8
|
# Vue testing
|
|
9
9
|
|
|
10
|
-
Narrows `core-common-rules`'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
Narrows `core-common-rules`' testing rules to Vue component and composable
|
|
11
|
+
testing with Vitest and Vue Test Utils. Applies to `*.vue` tests; a plain
|
|
12
|
+
`.ts` composable's unit tests follow `ts-js-node`'s testing rule unless they
|
|
13
|
+
mount a component.
|
|
14
14
|
|
|
15
15
|
## Layout and runner
|
|
16
16
|
|
|
17
|
-
- Co-locate a component's test
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
second layout.
|
|
21
|
-
- Use the project's configured runner (Vitest is standard for Vue 3 /
|
|
22
|
-
Vite projects) and its already-configured DOM environment (`happy-dom`
|
|
23
|
-
or `jsdom`); do not add a second test runner or DOM environment for new
|
|
24
|
-
tests.
|
|
25
|
-
- Use `@vue/test-utils`'s `mount()` for a component that needs its full
|
|
26
|
-
render tree and child components resolved, and `shallowMount()` only
|
|
27
|
-
when child components are irrelevant to the behavior under test and
|
|
28
|
-
stubbing them meaningfully reduces noise.
|
|
17
|
+
- Co-locate a component's test (`OrderSummary.spec.ts`) or use the project's `__tests__` convention; match the existing layout.
|
|
18
|
+
- Use the project's configured runner (Vitest) and DOM environment (`happy-dom` or `jsdom`); add no second runner or environment.
|
|
19
|
+
- Use `mount()` when the full render tree and child components are needed; `shallowMount()` only when child components are irrelevant to the behavior under test.
|
|
29
20
|
|
|
30
21
|
## Querying and interaction
|
|
31
22
|
|
|
32
|
-
- Query by test id, role, or visible text (`wrapper.find('[data-testid=...]')`,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
styling.
|
|
36
|
-
- Trigger user interaction through Test Utils' `trigger()` (`await
|
|
37
|
-
wrapper.find(selector).trigger('click')`) or `@testing-library/vue`'s
|
|
38
|
-
`fireEvent`, and `await` it -- Vue's DOM updates are asynchronous, so an
|
|
39
|
-
un-awaited trigger asserts against stale DOM.
|
|
40
|
-
- Assert on rendered output and emitted events (`wrapper.emitted('update')`),
|
|
41
|
-
not on a component's internal reactive state reached through
|
|
42
|
-
`wrapper.vm` -- `vm` access ties the test to implementation details that
|
|
43
|
-
change without changing behavior.
|
|
23
|
+
- Query by test id, role, or visible text (`wrapper.find('[data-testid=...]')`, or `@testing-library/vue` `getByRole`/`getByText` if the project uses it), not a CSS class or structure selector.
|
|
24
|
+
- Trigger interaction with `trigger()` (or `@testing-library/vue`'s `fireEvent`) and `await` it.
|
|
25
|
+
- Assert on rendered output and emitted events (`wrapper.emitted('update')`), not internal state through `wrapper.vm`.
|
|
44
26
|
|
|
45
27
|
## Props, emits, and stores
|
|
46
28
|
|
|
47
|
-
- Pass required props explicitly through `mount(Component, { props: {...}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
- Assert an emitted event with `wrapper.emitted('eventName')` and check
|
|
51
|
-
the payload array, not just that the event fired -- a wrong payload is a
|
|
52
|
-
real bug an emitted-only check misses.
|
|
53
|
-
- For a component that uses Pinia, create a fresh test Pinia instance per
|
|
54
|
-
test (`createTestingPinia()` from `@pinia/testing`, or `createPinia()` +
|
|
55
|
-
`setActivePinia()`) rather than reusing one instance across tests, so
|
|
56
|
-
store state from one test cannot leak into the next.
|
|
29
|
+
- Pass required props explicitly through `mount(Component, { props: {...} })`; do not let defaults cover a prop whose value matters to the assertion.
|
|
30
|
+
- Check the emitted payload array, not only that the event fired.
|
|
31
|
+
- For a Pinia component, create a fresh Pinia per test (`createTestingPinia()` from `@pinia/testing`, or `createPinia()` + `setActivePinia()`).
|
|
57
32
|
|
|
58
33
|
## Mocking and determinism
|
|
59
34
|
|
|
60
|
-
- Mock network
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
- Use Vitest's fake timers (`vi.useFakeTimers()`) for a component that
|
|
64
|
-
debounces, polls, or delays, and restore real timers afterward
|
|
65
|
-
(`vi.useRealTimers()`) so later tests are not affected.
|
|
66
|
-
- Flush pending reactivity updates with `await nextTick()` (or the
|
|
67
|
-
awaited `trigger()`/`flushPromises()` the project already imports)
|
|
68
|
-
before asserting on DOM that changes after an async composable call
|
|
69
|
-
resolves, instead of adding an arbitrary `setTimeout` wait.
|
|
35
|
+
- Mock network at the request boundary (the composable/service function, or MSW at the fetch layer), not inside component internals.
|
|
36
|
+
- Use `vi.useFakeTimers()` for debounce/poll/delay, and restore with `vi.useRealTimers()`.
|
|
37
|
+
- Flush reactivity with `await nextTick()` (or the awaited `trigger()`/`flushPromises()` the project imports) before asserting on DOM that changes after an async call, not an arbitrary `setTimeout`.
|