@cbrl/testing 0.1.0 → 0.2.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/README.md +64 -2
- package/dist/playwright.d.mts +86 -0
- package/dist/playwright.mjs +112 -0
- package/dist/vitest/jsdom.d.mts +17 -0
- package/dist/vitest/jsdom.mjs +46 -0
- package/package.json +18 -5
- package/dist/firebase.d.mts +0 -42
- package/dist/firebase.mjs +0 -50
package/README.md
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
# @cbrl/testing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Test helpers for Vitest and Playwright.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
pnpm add -D @cbrl/testing vitest @vitest/coverage-v8
|
|
7
|
+
# Playwright presets (optional peer):
|
|
8
|
+
pnpm add -D @playwright/test
|
|
7
9
|
```
|
|
8
10
|
|
|
9
11
|
| Entry | Export |
|
|
10
12
|
| --------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
|
|
11
13
|
| `@cbrl/testing/vitest` | `coverageBase()`: v8 provider, `src/**` include, test files excluded, `text-summary` + `json-summary` reporters |
|
|
12
14
|
| `@cbrl/testing/vitest/server-only-shim` | Empty module to alias `server-only` to in tests |
|
|
15
|
+
| `@cbrl/testing/vitest/jsdom` | `installJsdomPolyfills()`: stubs `ResizeObserver`, `matchMedia`, `scrollIntoView` and Pointer Capture |
|
|
13
16
|
| `@cbrl/testing/a11y` | `expectNoA11yViolations(container)`: axe-core check for jsdom component tests (page-level `region` rule off) |
|
|
14
|
-
| `@cbrl/testing/
|
|
17
|
+
| `@cbrl/testing/playwright` | `defineE2EConfig()`, `defineSmokeConfig()` and `smokeSuite()` presets |
|
|
18
|
+
|
|
19
|
+
## Vitest
|
|
15
20
|
|
|
16
21
|
```ts
|
|
17
22
|
// vitest.config.ts
|
|
@@ -40,3 +45,60 @@ resolve: {
|
|
|
40
45
|
},
|
|
41
46
|
}
|
|
42
47
|
```
|
|
48
|
+
|
|
49
|
+
Polyfill the browser APIs Radix primitives need under jsdom:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
// vitest.setup.ts
|
|
53
|
+
import '@testing-library/jest-dom/vitest'
|
|
54
|
+
import { installJsdomPolyfills } from '@cbrl/testing/vitest/jsdom'
|
|
55
|
+
|
|
56
|
+
installJsdomPolyfills()
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Playwright
|
|
60
|
+
|
|
61
|
+
`defineE2EConfig` boots the app and runs chromium. On CI (`CI` set) it serves a
|
|
62
|
+
production build, never reuses a running server, forbids `.only` and reports
|
|
63
|
+
with GitHub annotations; locally it runs the dev server. Spread it to add app
|
|
64
|
+
specifics:
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
// playwright.config.ts
|
|
68
|
+
import { defineE2EConfig } from '@cbrl/testing/playwright'
|
|
69
|
+
import { defineConfig } from '@playwright/test'
|
|
70
|
+
|
|
71
|
+
export default defineConfig({
|
|
72
|
+
...defineE2EConfig({
|
|
73
|
+
port: 3000,
|
|
74
|
+
testDir: './src',
|
|
75
|
+
testMatch: '**/_e2e/**/*.spec.ts',
|
|
76
|
+
webServerEnv: { ENABLE_TEST_AUTH: 'true' },
|
|
77
|
+
// devCommand: 'pnpm run dev', ciCommand: 'pnpm run build && pnpm run start -p 3000'
|
|
78
|
+
}),
|
|
79
|
+
globalSetup: './e2e/global-setup.ts',
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Post-deploy smoke tests against a deployed URL (fails fast when the env var is
|
|
84
|
+
missing):
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
// playwright.smoke.config.ts
|
|
88
|
+
import { defineSmokeConfig } from '@cbrl/testing/playwright'
|
|
89
|
+
|
|
90
|
+
export default defineSmokeConfig() // { testDir: './_smoke', baseUrlEnv: 'SMOKE_BASE_URL' }
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
// _smoke/health.spec.ts
|
|
95
|
+
import { smokeSuite } from '@cbrl/testing/playwright'
|
|
96
|
+
import { expect, test } from '@playwright/test'
|
|
97
|
+
|
|
98
|
+
// GET /api/health -> 200 { status: 'ok' }, and `/` renders with a title.
|
|
99
|
+
smokeSuite({ healthPath: '/api/health' })
|
|
100
|
+
|
|
101
|
+
test('listing renders', async ({ page }) => {
|
|
102
|
+
expect((await page.goto('/listing'))?.status()).toBeLessThan(400)
|
|
103
|
+
})
|
|
104
|
+
```
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { PlaywrightTestConfig } from "@playwright/test";
|
|
2
|
+
/** Options for {@link defineE2EConfig}. */
|
|
3
|
+
interface E2EConfigOptions {
|
|
4
|
+
/** Port the app server listens on. The base URL is derived from it. */
|
|
5
|
+
readonly port: number;
|
|
6
|
+
/** Directory Playwright searches for specs, relative to the config file. */
|
|
7
|
+
readonly testDir: string;
|
|
8
|
+
/** Spec glob(s) inside `testDir`. Default `'**\/*.spec.ts'`. */
|
|
9
|
+
readonly testMatch?: string | RegExp | readonly (string | RegExp)[];
|
|
10
|
+
/** Env passed to the app server (test-only flags, local service keys…). */
|
|
11
|
+
readonly webServerEnv?: Readonly<Record<string, string>>;
|
|
12
|
+
/** Server command outside CI. Default `'pnpm run dev'`. */
|
|
13
|
+
readonly devCommand?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Server command on CI: a production build, so specs never race on-demand
|
|
16
|
+
* compilation. Default `` `pnpm run build && pnpm run start -p ${port}` ``.
|
|
17
|
+
*/
|
|
18
|
+
readonly ciCommand?: string;
|
|
19
|
+
/** Host the base URL points at. Default `'127.0.0.1'`. */
|
|
20
|
+
readonly host?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Base Playwright config for an E2E suite that boots the app itself.
|
|
24
|
+
*
|
|
25
|
+
* On CI (`process.env.CI` set) it runs the production build, never reuses a
|
|
26
|
+
* running server, forbids `.only` and reports with GitHub annotations; locally
|
|
27
|
+
* it runs the dev server and reuses one already up. Always chromium, no
|
|
28
|
+
* retries, traces kept for failing tests. Spread the result into Playwright's
|
|
29
|
+
* `defineConfig` to add app specifics (`globalSetup`, `workers`, `shard`…).
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { defineE2EConfig } from '@cbrl/testing/playwright'
|
|
34
|
+
* import { defineConfig } from '@playwright/test'
|
|
35
|
+
*
|
|
36
|
+
* export default defineConfig({
|
|
37
|
+
* ...defineE2EConfig({ port: 3000, testDir: './src', testMatch: '**\/_e2e/**\/*.spec.ts' }),
|
|
38
|
+
* workers: 2,
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function defineE2EConfig(options: E2EConfigOptions): PlaywrightTestConfig;
|
|
43
|
+
/** Options for {@link defineSmokeConfig}. */
|
|
44
|
+
interface SmokeConfigOptions {
|
|
45
|
+
/** Directory with the smoke specs. Default `'./_smoke'`. */
|
|
46
|
+
readonly testDir?: string;
|
|
47
|
+
/** Env var holding the deployed URL to smoke-test. Default `'SMOKE_BASE_URL'`. */
|
|
48
|
+
readonly baseUrlEnv?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Playwright config for post-deploy smoke tests against a deployed URL. Starts
|
|
52
|
+
* no server; fails fast when the URL env var is missing. Retries twice (a
|
|
53
|
+
* fresh deployment can be cold) and records a trace on the first retry.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* // playwright.smoke.config.ts
|
|
58
|
+
* import { defineSmokeConfig } from '@cbrl/testing/playwright'
|
|
59
|
+
*
|
|
60
|
+
* export default defineSmokeConfig()
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function defineSmokeConfig(options?: SmokeConfigOptions): PlaywrightTestConfig;
|
|
64
|
+
/** Options for {@link smokeSuite}. */
|
|
65
|
+
interface SmokeSuiteOptions {
|
|
66
|
+
/** Health endpoint that answers `200` with `{ status: 'ok' }`. Default `'/api/health'`. */
|
|
67
|
+
readonly healthPath?: string;
|
|
68
|
+
/** Page that must render with a non-empty title. Default `'/'`. */
|
|
69
|
+
readonly homePath?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Register the baseline smoke tests in the calling spec file: the health
|
|
73
|
+
* endpoint returns `200` with `status: 'ok'`, and the home page renders
|
|
74
|
+
* (status below 400) with a non-empty `<title>`. Add app-specific smoke tests
|
|
75
|
+
* next to the call.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* // _smoke/health.spec.ts
|
|
80
|
+
* import { smokeSuite } from '@cbrl/testing/playwright'
|
|
81
|
+
*
|
|
82
|
+
* smokeSuite()
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export declare function smokeSuite(options?: SmokeSuiteOptions): void;
|
|
86
|
+
export type { E2EConfigOptions, SmokeConfigOptions, SmokeSuiteOptions };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { requireEnv } from "@cbrl/env";
|
|
2
|
+
import { devices, expect, test } from "@playwright/test";
|
|
3
|
+
// src/playwright/config.ts
|
|
4
|
+
const chromium = {
|
|
5
|
+
name: "chromium",
|
|
6
|
+
use: { ...devices["Desktop Chrome"] }
|
|
7
|
+
};
|
|
8
|
+
const isCI = () => Boolean(process.env.CI);
|
|
9
|
+
/**
|
|
10
|
+
* Base Playwright config for an E2E suite that boots the app itself.
|
|
11
|
+
*
|
|
12
|
+
* On CI (`process.env.CI` set) it runs the production build, never reuses a
|
|
13
|
+
* running server, forbids `.only` and reports with GitHub annotations; locally
|
|
14
|
+
* it runs the dev server and reuses one already up. Always chromium, no
|
|
15
|
+
* retries, traces kept for failing tests. Spread the result into Playwright's
|
|
16
|
+
* `defineConfig` to add app specifics (`globalSetup`, `workers`, `shard`…).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { defineE2EConfig } from '@cbrl/testing/playwright'
|
|
21
|
+
* import { defineConfig } from '@playwright/test'
|
|
22
|
+
*
|
|
23
|
+
* export default defineConfig({
|
|
24
|
+
* ...defineE2EConfig({ port: 3000, testDir: './src', testMatch: '**\/_e2e/**\/*.spec.ts' }),
|
|
25
|
+
* workers: 2,
|
|
26
|
+
* })
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
function defineE2EConfig(options) {
|
|
30
|
+
const { port, testDir, testMatch = "**/*.spec.ts", webServerEnv = {}, devCommand = "pnpm run dev", ciCommand = `pnpm run build && pnpm run start -p ${port}`, host = "127.0.0.1" } = options;
|
|
31
|
+
const ci = isCI();
|
|
32
|
+
const baseURL = `http://${host}:${port}`;
|
|
33
|
+
return {
|
|
34
|
+
testDir,
|
|
35
|
+
testMatch: typeof testMatch === "string" || testMatch instanceof RegExp ? testMatch : [...testMatch],
|
|
36
|
+
fullyParallel: true,
|
|
37
|
+
forbidOnly: ci,
|
|
38
|
+
retries: 0,
|
|
39
|
+
reporter: ci ? "github" : "list",
|
|
40
|
+
use: {
|
|
41
|
+
baseURL,
|
|
42
|
+
trace: "retain-on-failure"
|
|
43
|
+
},
|
|
44
|
+
projects: [chromium],
|
|
45
|
+
webServer: {
|
|
46
|
+
command: ci ? ciCommand : devCommand,
|
|
47
|
+
url: baseURL,
|
|
48
|
+
reuseExistingServer: !ci,
|
|
49
|
+
timeout: ci ? 3e5 : 12e4,
|
|
50
|
+
env: { ...webServerEnv }
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Playwright config for post-deploy smoke tests against a deployed URL. Starts
|
|
56
|
+
* no server; fails fast when the URL env var is missing. Retries twice (a
|
|
57
|
+
* fresh deployment can be cold) and records a trace on the first retry.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* // playwright.smoke.config.ts
|
|
62
|
+
* import { defineSmokeConfig } from '@cbrl/testing/playwright'
|
|
63
|
+
*
|
|
64
|
+
* export default defineSmokeConfig()
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
function defineSmokeConfig(options = {}) {
|
|
68
|
+
const { testDir = "./_smoke", baseUrlEnv = "SMOKE_BASE_URL" } = options;
|
|
69
|
+
const baseURL = requireEnv(baseUrlEnv);
|
|
70
|
+
return {
|
|
71
|
+
testDir,
|
|
72
|
+
testMatch: "**/*.spec.ts",
|
|
73
|
+
fullyParallel: true,
|
|
74
|
+
forbidOnly: isCI(),
|
|
75
|
+
retries: 2,
|
|
76
|
+
reporter: "html",
|
|
77
|
+
use: {
|
|
78
|
+
baseURL,
|
|
79
|
+
trace: "on-first-retry"
|
|
80
|
+
},
|
|
81
|
+
projects: [chromium]
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
// src/playwright/smoke.ts
|
|
85
|
+
/**
|
|
86
|
+
* Register the baseline smoke tests in the calling spec file: the health
|
|
87
|
+
* endpoint returns `200` with `status: 'ok'`, and the home page renders
|
|
88
|
+
* (status below 400) with a non-empty `<title>`. Add app-specific smoke tests
|
|
89
|
+
* next to the call.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* // _smoke/health.spec.ts
|
|
94
|
+
* import { smokeSuite } from '@cbrl/testing/playwright'
|
|
95
|
+
*
|
|
96
|
+
* smokeSuite()
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
function smokeSuite(options = {}) {
|
|
100
|
+
const { healthPath = "/api/health", homePath = "/" } = options;
|
|
101
|
+
test("health endpoint returns ok", async ({ request }) => {
|
|
102
|
+
const res = await request.get(healthPath);
|
|
103
|
+
expect(res.status()).toBe(200);
|
|
104
|
+
expect(await res.json()).toMatchObject({ status: "ok" });
|
|
105
|
+
});
|
|
106
|
+
test("home page renders", async ({ page }) => {
|
|
107
|
+
const res = await page.goto(homePath);
|
|
108
|
+
expect(res?.status()).toBeLessThan(400);
|
|
109
|
+
await expect(page).toHaveTitle(/.+/);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
export { defineE2EConfig, defineSmokeConfig, smokeSuite };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stub the browser APIs jsdom lacks but Radix primitives, sonner and
|
|
3
|
+
* next-themes call: `ResizeObserver`, `matchMedia` (never matches),
|
|
4
|
+
* `Element#scrollIntoView` and the Pointer Capture API. Only missing APIs are
|
|
5
|
+
* defined, so a real implementation or a test's own mock wins. Call it once
|
|
6
|
+
* from the vitest `setupFiles` of a jsdom project.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* // vitest.setup.ts
|
|
11
|
+
* import '@testing-library/jest-dom/vitest'
|
|
12
|
+
* import { installJsdomPolyfills } from '@cbrl/testing/vitest/jsdom'
|
|
13
|
+
*
|
|
14
|
+
* installJsdomPolyfills()
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function installJsdomPolyfills(): void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/vitest/jsdom.ts
|
|
2
|
+
const noop = () => {};
|
|
3
|
+
var ResizeObserverStub = class {
|
|
4
|
+
observe() {}
|
|
5
|
+
unobserve() {}
|
|
6
|
+
disconnect() {}
|
|
7
|
+
};
|
|
8
|
+
function matchMediaStub(query) {
|
|
9
|
+
return {
|
|
10
|
+
matches: false,
|
|
11
|
+
media: query,
|
|
12
|
+
onchange: null,
|
|
13
|
+
addEventListener: noop,
|
|
14
|
+
removeEventListener: noop,
|
|
15
|
+
addListener: noop,
|
|
16
|
+
removeListener: noop,
|
|
17
|
+
dispatchEvent: () => false
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Stub the browser APIs jsdom lacks but Radix primitives, sonner and
|
|
22
|
+
* next-themes call: `ResizeObserver`, `matchMedia` (never matches),
|
|
23
|
+
* `Element#scrollIntoView` and the Pointer Capture API. Only missing APIs are
|
|
24
|
+
* defined, so a real implementation or a test's own mock wins. Call it once
|
|
25
|
+
* from the vitest `setupFiles` of a jsdom project.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* // vitest.setup.ts
|
|
30
|
+
* import '@testing-library/jest-dom/vitest'
|
|
31
|
+
* import { installJsdomPolyfills } from '@cbrl/testing/vitest/jsdom'
|
|
32
|
+
*
|
|
33
|
+
* installJsdomPolyfills()
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
function installJsdomPolyfills() {
|
|
37
|
+
if (typeof globalThis.ResizeObserver === "undefined") globalThis.ResizeObserver = ResizeObserverStub;
|
|
38
|
+
if (typeof globalThis.matchMedia !== "function") globalThis.matchMedia = matchMediaStub;
|
|
39
|
+
if (typeof Element === "undefined") return;
|
|
40
|
+
const proto = Element.prototype;
|
|
41
|
+
if (typeof proto.scrollIntoView !== "function") proto.scrollIntoView = noop;
|
|
42
|
+
if (typeof proto.hasPointerCapture !== "function") proto.hasPointerCapture = () => false;
|
|
43
|
+
if (typeof proto.setPointerCapture !== "function") proto.setPointerCapture = noop;
|
|
44
|
+
if (typeof proto.releasePointerCapture !== "function") proto.releasePointerCapture = noop;
|
|
45
|
+
}
|
|
46
|
+
export { installJsdomPolyfills };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cbrl/testing",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Test helpers: Vitest coverage base, server-only shim, jsdom polyfills, jest-axe a11y matcher, and Playwright E2E/smoke presets.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Kayron Cabral",
|
|
7
7
|
"homepage": "https://github.com/kaycabral/toolkit/tree/main/packages/testing#readme",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"vitest",
|
|
18
|
+
"playwright",
|
|
18
19
|
"testing",
|
|
19
20
|
"coverage",
|
|
20
21
|
"a11y",
|
|
@@ -24,8 +25,9 @@
|
|
|
24
25
|
"sideEffects": false,
|
|
25
26
|
"exports": {
|
|
26
27
|
"./a11y": "./dist/a11y.mjs",
|
|
27
|
-
"./
|
|
28
|
+
"./playwright": "./dist/playwright.mjs",
|
|
28
29
|
"./vitest": "./dist/vitest.mjs",
|
|
30
|
+
"./vitest/jsdom": "./dist/vitest/jsdom.mjs",
|
|
29
31
|
"./vitest/server-only-shim": "./dist/vitest/server-only-shim.mjs",
|
|
30
32
|
"./package.json": "./package.json"
|
|
31
33
|
},
|
|
@@ -34,27 +36,38 @@
|
|
|
34
36
|
],
|
|
35
37
|
"dependencies": {
|
|
36
38
|
"jest-axe": "^10.0.0",
|
|
37
|
-
"@cbrl/env": "^0.1.
|
|
39
|
+
"@cbrl/env": "^0.1.1"
|
|
38
40
|
},
|
|
39
41
|
"peerDependencies": {
|
|
42
|
+
"@playwright/test": ">=1.50",
|
|
40
43
|
"vitest": ">=3"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
43
46
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
47
|
+
"@playwright/test": "^1.56.1",
|
|
44
48
|
"@types/jest-axe": "^3.5.9",
|
|
45
49
|
"@types/node": "^25.6.2",
|
|
46
50
|
"@vitest/coverage-v8": "^4.1.6",
|
|
47
51
|
"eslint": "^9.39.4",
|
|
52
|
+
"jsdom": "^29.1.1",
|
|
48
53
|
"publint": "^0.3.25",
|
|
49
54
|
"tsdown": "^0.23.7",
|
|
50
55
|
"typescript": "^5.9.3",
|
|
51
56
|
"vitest": "^4.1.6",
|
|
52
|
-
"@cbrl/eslint-config": "0.
|
|
57
|
+
"@cbrl/eslint-config": "0.2.0",
|
|
53
58
|
"@cbrl/tsconfig": "0.1.0"
|
|
54
59
|
},
|
|
55
60
|
"publishConfig": {
|
|
56
61
|
"access": "public"
|
|
57
62
|
},
|
|
63
|
+
"peerDependenciesMeta": {
|
|
64
|
+
"@playwright/test": {
|
|
65
|
+
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"vitest": {
|
|
68
|
+
"optional": true
|
|
69
|
+
}
|
|
70
|
+
},
|
|
58
71
|
"scripts": {
|
|
59
72
|
"build": "tsdown",
|
|
60
73
|
"typecheck": "tsc --noEmit",
|
package/dist/firebase.d.mts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
};
|
package/dist/firebase.mjs
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
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 };
|