@cbrl/testing 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kayron Cabral
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
- # Temporary Holding Version
1
+ # @cbrl/testing
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Small Vitest helpers.
4
+
5
+ ```sh
6
+ pnpm add -D @cbrl/testing vitest @vitest/coverage-v8
7
+ ```
8
+
9
+ | Entry | Export |
10
+ | --------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
11
+ | `@cbrl/testing/vitest` | `coverageBase()`: v8 provider, `src/**` include, test files excluded, `text-summary` + `json-summary` reporters |
12
+ | `@cbrl/testing/vitest/server-only-shim` | Empty module to alias `server-only` to in tests |
13
+ | `@cbrl/testing/a11y` | `expectNoA11yViolations(container)`: axe-core check for jsdom component tests (page-level `region` rule off) |
14
+ | `@cbrl/testing/firebase` | Fail-fast readers for the env `firebase emulators:exec` injects, and a Playwright `webServer` builder |
15
+
16
+ ```ts
17
+ // vitest.config.ts
18
+ import { coverageBase } from '@cbrl/testing/vitest'
19
+ import { defineConfig } from 'vitest/config'
20
+
21
+ export default defineConfig({
22
+ test: {
23
+ coverage: {
24
+ ...coverageBase(),
25
+ // Keep thresholds inline so `autoUpdate` can ratchet them in this file.
26
+ thresholds: { statements: 90, branches: 85, functions: 90, lines: 90, autoUpdate: true },
27
+ },
28
+ },
29
+ })
30
+ ```
31
+
32
+ Alias `server-only` in tests:
33
+
34
+ ```ts
35
+ import { fileURLToPath } from 'node:url'
36
+
37
+ resolve: {
38
+ alias: {
39
+ 'server-only': fileURLToPath(import.meta.resolve('@cbrl/testing/vitest/server-only-shim')),
40
+ },
41
+ }
42
+ ```
@@ -0,0 +1 @@
1
+ export declare function expectNoA11yViolations(container: Element): Promise<void>;
package/dist/a11y.mjs ADDED
@@ -0,0 +1,22 @@
1
+ import { axe, toHaveNoViolations } from "jest-axe";
2
+ import { expect } from "vitest";
3
+ // src/vitest/a11y.ts
4
+ /**
5
+ * Shared accessibility assertion for jsdom component tests, backed by axe-core
6
+ * (via jest-axe). Design-system components are exactly where automated a11y
7
+ * checks pay off — a violation here propagates to every consuming app.
8
+ *
9
+ * import { expectNoA11yViolations } from '@cbrl/testing/a11y'
10
+ * const { container } = render(<Button>Salvar</Button>)
11
+ * await expectNoA11yViolations(container)
12
+ *
13
+ * The jest-axe matcher is registered once here so callers only deal with the
14
+ * wrapper — no per-file `expect.extend` and no matcher type augmentation.
15
+ * Requires a DOM environment (`environment: 'jsdom'`).
16
+ */
17
+ expect.extend(toHaveNoViolations);
18
+ async function expectNoA11yViolations(container) {
19
+ const results = await axe(container, { rules: { region: { enabled: false } } });
20
+ expect(results).toHaveNoViolations();
21
+ }
22
+ export { expectNoA11yViolations };
@@ -0,0 +1,42 @@
1
+ /** Emulator project id (matches the `--project` passed to emulators:exec). */
2
+ export declare const emulatorProjectId: () => string;
3
+ /** `host:port` of the Firestore emulator. */
4
+ export declare const firestoreEmulatorHost: () => string;
5
+ /** `host:port` of the Auth emulator. */
6
+ export declare const authEmulatorHost: () => string;
7
+ /** `host:port` of the Storage emulator. */
8
+ export declare const storageEmulatorHost: () => string;
9
+ export interface FirebaseEmulatorWebServerOptions {
10
+ /** Command that starts the app server, e.g. `'pnpm run dev'`. */
11
+ readonly command: string;
12
+ /**
13
+ * Port the app listens on. The health-check URL is *derived* from it, so the
14
+ * URL can never drift from the server the way a hard-coded URL did (the
15
+ * classic "config says :3000 but the dev script runs :3003" bug).
16
+ */
17
+ readonly port: number;
18
+ /** Emulator project id — must match the `--project` of emulators:exec. */
19
+ readonly projectId: string;
20
+ /**
21
+ * App-specific public/test env, merged over the Firebase defaults below.
22
+ * Use fixed test constants here, never `process.env.X ?? 'literal'`.
23
+ */
24
+ readonly env?: Readonly<Record<string, string>>;
25
+ /** Reuse a server already running locally. Default: true unless on CI. */
26
+ readonly reuseExistingServer?: boolean;
27
+ /** Server boot timeout in ms. Default 120_000. */
28
+ readonly timeoutMs?: number;
29
+ }
30
+ /**
31
+ * Build the Playwright `webServer` config for an emulator-backed e2e run.
32
+ * Emulator hosts + `GCLOUD_PROJECT` are injected by emulators:exec and inherited
33
+ * by the server subprocess — deliberately not set here, so there is no
34
+ * literal-default to mask a missing emulator.
35
+ */
36
+ export declare function firebaseEmulatorWebServer(opts: FirebaseEmulatorWebServerOptions): {
37
+ command: string;
38
+ url: string;
39
+ reuseExistingServer: boolean;
40
+ timeout: number;
41
+ env: Record<string, string>;
42
+ };
@@ -0,0 +1,50 @@
1
+ import { requireEnv } from "@cbrl/env";
2
+ // src/firebase/index.ts
3
+ /**
4
+ * Shared Firebase emulator test harness.
5
+ *
6
+ * Every Firebase app wires its e2e/integration suite to the emulator the same
7
+ * way: run under `firebase emulators:exec` (which injects the emulator hosts +
8
+ * project), read those injected values fail-fast, and point Playwright's
9
+ * web server at the app. Re-implementing that per app caused drift — divergent
10
+ * fake values, the `process.env.X ?? 'literal'` anti-pattern, and host/port
11
+ * mismatches. This module is the single source of truth for all of it.
12
+ *
13
+ * Lives under the agnostic `@cbrl/testing` package (subpath `/firebase`) so
14
+ * non-Firebase test helpers can join later.
15
+ */
16
+ /** Emulator project id (matches the `--project` passed to emulators:exec). */
17
+ const emulatorProjectId = () => requireEnv("GCLOUD_PROJECT");
18
+ /** `host:port` of the Firestore emulator. */
19
+ const firestoreEmulatorHost = () => requireEnv("FIRESTORE_EMULATOR_HOST");
20
+ /** `host:port` of the Auth emulator. */
21
+ const authEmulatorHost = () => requireEnv("FIREBASE_AUTH_EMULATOR_HOST");
22
+ /** `host:port` of the Storage emulator. */
23
+ const storageEmulatorHost = () => requireEnv("FIREBASE_STORAGE_EMULATOR_HOST");
24
+ /**
25
+ * Build the Playwright `webServer` config for an emulator-backed e2e run.
26
+ * Emulator hosts + `GCLOUD_PROJECT` are injected by emulators:exec and inherited
27
+ * by the server subprocess — deliberately not set here, so there is no
28
+ * literal-default to mask a missing emulator.
29
+ */
30
+ function firebaseEmulatorWebServer(opts) {
31
+ const { command, port, projectId, env = {}, reuseExistingServer, timeoutMs = 12e4 } = opts;
32
+ const serverEnv = {
33
+ NEXT_PUBLIC_USE_FIREBASE_EMULATORS: "true",
34
+ FIREBASE_ADMIN_PROJECT_ID: projectId,
35
+ NEXT_PUBLIC_FIREBASE_PROJECT_ID: projectId,
36
+ NEXT_PUBLIC_FIREBASE_API_KEY: "emulator-fake-key",
37
+ NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN: `${projectId}.firebaseapp.com`,
38
+ NEXT_PUBLIC_FIREBASE_APP_ID: "emulator-fake-app-id",
39
+ NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET: `${projectId}.firebasestorage.app`,
40
+ ...env
41
+ };
42
+ return {
43
+ command,
44
+ url: `http://127.0.0.1:${port}`,
45
+ reuseExistingServer: reuseExistingServer ?? !process.env.CI,
46
+ timeout: timeoutMs,
47
+ env: serverEnv
48
+ };
49
+ }
50
+ export { authEmulatorHost, emulatorProjectId, firebaseEmulatorWebServer, firestoreEmulatorHost, storageEmulatorHost };
@@ -0,0 +1 @@
1
+ export {}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare function coverageBase(): {
2
+ provider: "v8";
3
+ include: string[];
4
+ exclude: string[];
5
+ reporter: ("json-summary" | "text-summary")[];
6
+ reportsDirectory: string;
7
+ };
@@ -0,0 +1,16 @@
1
+ // src/vitest/index.ts
2
+ function coverageBase() {
3
+ return {
4
+ provider: "v8",
5
+ include: ["src/**/*.{ts,tsx}"],
6
+ exclude: [
7
+ "src/**/*.{test,spec}.{ts,tsx}",
8
+ "src/**/*.integration.test.{ts,tsx}",
9
+ "src/**/*.d.ts",
10
+ "src/**/__mocks__/**"
11
+ ],
12
+ reporter: ["text-summary", "json-summary"],
13
+ reportsDirectory: "./coverage"
14
+ };
15
+ }
16
+ export { coverageBase };
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@cbrl/testing",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Vitest helpers: shared v8 coverage base, server-only shim, jest-axe a11y matcher and a Firebase emulator env helper.",
5
+ "license": "MIT",
6
+ "author": "Kayron Cabral",
7
+ "homepage": "https://github.com/kaycabral/toolkit/tree/main/packages/testing#readme",
8
+ "bugs": {
9
+ "url": "https://github.com/kaycabral/toolkit/issues"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/kaycabral/toolkit.git",
14
+ "directory": "packages/testing"
15
+ },
16
+ "keywords": [
17
+ "vitest",
18
+ "testing",
19
+ "coverage",
20
+ "a11y",
21
+ "jest-axe"
22
+ ],
23
+ "type": "module",
24
+ "sideEffects": false,
25
+ "exports": {
26
+ "./a11y": "./dist/a11y.mjs",
27
+ "./firebase": "./dist/firebase.mjs",
28
+ "./vitest": "./dist/vitest.mjs",
29
+ "./vitest/server-only-shim": "./dist/vitest/server-only-shim.mjs",
30
+ "./package.json": "./package.json"
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "dependencies": {
36
+ "jest-axe": "^10.0.0",
37
+ "@cbrl/env": "^0.1.0"
38
+ },
39
+ "peerDependencies": {
40
+ "vitest": ">=3"
41
+ },
42
+ "devDependencies": {
43
+ "@arethetypeswrong/cli": "^0.18.5",
44
+ "@types/jest-axe": "^3.5.9",
45
+ "@types/node": "^25.6.2",
46
+ "@vitest/coverage-v8": "^4.1.6",
47
+ "eslint": "^9.39.4",
48
+ "publint": "^0.3.25",
49
+ "tsdown": "^0.23.7",
50
+ "typescript": "^5.9.3",
51
+ "vitest": "^4.1.6",
52
+ "@cbrl/eslint-config": "0.1.0",
53
+ "@cbrl/tsconfig": "0.1.0"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public"
57
+ },
58
+ "scripts": {
59
+ "build": "tsdown",
60
+ "typecheck": "tsc --noEmit",
61
+ "test": "vitest run --coverage",
62
+ "check:package": "node ../../scripts/check-package.mjs --types",
63
+ "lint": "eslint ."
64
+ }
6
65
  }