@specific.dev/spectest 0.38.0 → 0.41.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/dist/components/k3s.js +1 -24
- package/dist/components/supabase.d.ts +87 -27
- package/dist/components/supabase.js +352 -69
- package/dist/daemon.d.ts +38 -0
- package/dist/daemon.js +405 -946
- package/dist/harness/build-context.d.ts +82 -0
- package/dist/harness/build-context.js +113 -0
- package/dist/harness/buildkit-progress.d.ts +37 -0
- package/dist/harness/buildkit-progress.js +66 -0
- package/dist/harness/container-run.d.ts +89 -0
- package/dist/harness/container-run.js +118 -0
- package/dist/harness/file-mounts.d.ts +91 -0
- package/dist/harness/file-mounts.js +119 -0
- package/dist/harness/hostmatch.d.ts +65 -0
- package/dist/harness/hostmatch.js +108 -0
- package/dist/harness/http-proxy.d.ts +62 -0
- package/dist/harness/http-proxy.js +104 -0
- package/dist/harness/ingress-table.d.ts +148 -0
- package/dist/harness/ingress-table.js +129 -0
- package/dist/harness/log-delta.d.ts +54 -0
- package/dist/harness/log-delta.js +83 -0
- package/dist/harness/main.d.ts +47 -0
- package/dist/harness/main.js +164 -0
- package/dist/harness/methods.d.ts +54 -0
- package/dist/harness/methods.js +65 -0
- package/dist/harness/names-registry.d.ts +63 -0
- package/dist/harness/names-registry.js +90 -0
- package/dist/harness/protocol.d.ts +88 -0
- package/dist/harness/protocol.js +96 -0
- package/dist/harness/ready-poll.d.ts +47 -0
- package/dist/harness/ready-poll.js +67 -0
- package/dist/harness/service-graph.d.ts +29 -0
- package/dist/harness/service-graph.js +92 -0
- package/dist/harness/volume-paths.d.ts +70 -0
- package/dist/harness/volume-paths.js +81 -0
- package/dist/index.d.ts +3 -3
- package/dist/ingress.d.ts +1 -1
- package/dist/inspect.d.ts +23 -0
- package/dist/inspect.js +65 -0
- package/dist/resolver.js +5 -8
- package/dist/vendor/rrweb-plugin-console-record.umd.js +521 -0
- package/dist/vendor/rrweb-record.min.js +5061 -0
- package/package.json +7 -1
- package/src/aws-sigv4.ts +218 -0
- package/src/browser.ts +2040 -0
- package/src/components/aws.ts +554 -0
- package/src/components/email.ts +398 -0
- package/src/components/expo.ts +167 -0
- package/src/components/index.ts +81 -0
- package/src/components/k3s.ts +2061 -0
- package/src/components/postgres.ts +132 -0
- package/src/components/replayFake.ts +1015 -0
- package/src/components/s3.ts +132 -0
- package/src/components/supabase.ts +1699 -0
- package/src/daemon.ts +5489 -0
- package/src/harness/build-context.test.ts +0 -0
- package/src/harness/build-context.ts +146 -0
- package/src/harness/buildkit-progress.test.ts +98 -0
- package/src/harness/buildkit-progress.ts +74 -0
- package/src/harness/container-run.test.ts +209 -0
- package/src/harness/container-run.ts +158 -0
- package/src/harness/file-mounts.test.ts +185 -0
- package/src/harness/file-mounts.ts +145 -0
- package/src/harness/hostmatch.test.ts +148 -0
- package/src/harness/hostmatch.ts +109 -0
- package/src/harness/http-proxy.test.ts +156 -0
- package/src/harness/http-proxy.ts +119 -0
- package/src/harness/ingress-rebind.test.ts +125 -0
- package/src/harness/ingress-table.test.ts +172 -0
- package/src/harness/ingress-table.ts +186 -0
- package/src/harness/log-delta.test.ts +125 -0
- package/src/harness/log-delta.ts +100 -0
- package/src/harness/main.test.ts +211 -0
- package/src/harness/main.ts +196 -0
- package/src/harness/methods.test.ts +63 -0
- package/src/harness/methods.ts +92 -0
- package/src/harness/names-registry.test.ts +137 -0
- package/src/harness/names-registry.ts +108 -0
- package/src/harness/protocol.test.ts +148 -0
- package/src/harness/protocol.ts +163 -0
- package/src/harness/ready-poll.test.ts +172 -0
- package/src/harness/ready-poll.ts +93 -0
- package/src/harness/service-graph.test.ts +97 -0
- package/src/harness/service-graph.ts +97 -0
- package/src/harness/volume-paths.test.ts +102 -0
- package/src/harness/volume-paths.ts +112 -0
- package/src/ids.ts +89 -0
- package/src/index.ts +2725 -0
- package/src/ingress.ts +305 -0
- package/src/inspect.ts +739 -0
- package/src/locator.ts +716 -0
- package/src/mobile.ts +133 -0
- package/src/record-secrets.ts +41 -0
- package/src/recorder.ts +846 -0
- package/src/redis.ts +202 -0
- package/src/replay-bundle.ts +108 -0
- package/src/resolver.ts +348 -0
- package/src/s3.ts +333 -0
- package/src/sql.ts +243 -0
- package/src/terminal.ts +740 -0
- package/src/url-match.ts +67 -0
- package/src/vendor/rrweb-plugin-console-record.umd.js +521 -0
- package/src/vendor/rrweb-record.min.js +5061 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { ServiceDefinition, ServiceSetupContext } from "../index.js";
|
|
2
|
+
import { SQL, type SqlClient } from "../sql.js";
|
|
3
|
+
|
|
4
|
+
export interface PostgresOptions {
|
|
5
|
+
/** Image tag for the official `postgres` image. Default `"18-alpine"`.
|
|
6
|
+
* Ignored when {@link image} is set. */
|
|
7
|
+
version?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Full image reference, overriding the default `postgres:<version>`. For a
|
|
10
|
+
* Bun-SQL-/wire-compatible image (timescaledb, postgis, pgvector, …) you
|
|
11
|
+
* still get the instrumented client on `ctx.svc.<name>.client`.
|
|
12
|
+
*/
|
|
13
|
+
image?: string;
|
|
14
|
+
/** Database created on first boot. */
|
|
15
|
+
database: string;
|
|
16
|
+
/** Superuser name created on first boot. */
|
|
17
|
+
user: string;
|
|
18
|
+
/** Superuser password. */
|
|
19
|
+
password: string;
|
|
20
|
+
/**
|
|
21
|
+
* Whether postgres data persists across container restarts via a bind
|
|
22
|
+
* mount under `.spectest/volumes/<name>/`. Default `true`.
|
|
23
|
+
* Snapshots/forks always preserve state regardless of this flag — the
|
|
24
|
+
* volume just means a plain `docker rm`/`docker run` cycle keeps data.
|
|
25
|
+
*/
|
|
26
|
+
persistent?: boolean;
|
|
27
|
+
/** TCP port the container listens on. Default `5432`. */
|
|
28
|
+
port?: number;
|
|
29
|
+
/**
|
|
30
|
+
* CMD args appended after the image entrypoint (keeps the entrypoint, unlike
|
|
31
|
+
* `command`). For extension tuning, e.g.
|
|
32
|
+
* `["postgres", "-c", "timescaledb.max_background_workers=0"]`.
|
|
33
|
+
*/
|
|
34
|
+
args?: string[];
|
|
35
|
+
/** Extra environment variables forwarded to the container. */
|
|
36
|
+
env?: Record<string, string>;
|
|
37
|
+
/**
|
|
38
|
+
* One-shot hook that runs after the ready probe passes, before any
|
|
39
|
+
* dependent service starts and before any test. This is where schema
|
|
40
|
+
* and seed data go: the daemon captures the result into the
|
|
41
|
+
* warm-template snapshot, so it never runs again on a warm start or a
|
|
42
|
+
* fork.
|
|
43
|
+
*
|
|
44
|
+
* The argument is the full test context plus this service's `name` and
|
|
45
|
+
* its {@link PostgresHelpers}, so the instrumented client is already
|
|
46
|
+
* built:
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* db: postgres({
|
|
50
|
+
* database: "todos", user: "todos", password: "todos",
|
|
51
|
+
* setup: async ({ helpers }) => {
|
|
52
|
+
* await helpers.client`CREATE TABLE todos (
|
|
53
|
+
* id SERIAL PRIMARY KEY, text TEXT NOT NULL)`;
|
|
54
|
+
* },
|
|
55
|
+
* }),
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
setup?: (args: ServiceSetupContext<PostgresHelpers>) => void | Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Helpers a `postgres(...)` service exposes on `ctx.svc.<name>`. */
|
|
62
|
+
export interface PostgresHelpers {
|
|
63
|
+
/** An instrumented Bun SQL client — each query lands on the test event log
|
|
64
|
+
* alongside http/exec/assertion events, and its rows come back
|
|
65
|
+
* inspect-wrapped so `expect(...)` on them links to the query. See
|
|
66
|
+
* {@link SQL}. */
|
|
67
|
+
client: SqlClient;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A ready-to-use Postgres service. Drop into `environment.services`:
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* services: {
|
|
75
|
+
* db: postgres({ database: "todos", user: "todos", password: "todos" }),
|
|
76
|
+
* ...
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* Peer services reach it at `<key>:<port>` (e.g. `db:5432` for the
|
|
81
|
+
* example above). Tests get a wired-up Bun SQL client at
|
|
82
|
+
* `ctx.svc.<key>.client` — `await ctx.svc.db.client\`SELECT 1\`` — with
|
|
83
|
+
* every query recorded on the test event log.
|
|
84
|
+
*
|
|
85
|
+
* Point it at a wire-compatible image with `image`/`args`:
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* db: postgres({
|
|
89
|
+
* image: "timescale/timescaledb:latest-pg17",
|
|
90
|
+
* args: ["postgres", "-c", "timescaledb.max_background_workers=0"],
|
|
91
|
+
* database: "app", user: "app", password: "app",
|
|
92
|
+
* }),
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export function postgres(opts: PostgresOptions) {
|
|
96
|
+
const version = opts.version ?? "18-alpine";
|
|
97
|
+
const reference = opts.image ?? `postgres:${version}`;
|
|
98
|
+
const port = opts.port ?? 5432;
|
|
99
|
+
const persistent = opts.persistent ?? true;
|
|
100
|
+
// `satisfies` (instead of a return-type annotation) preserves the
|
|
101
|
+
// literal type — in particular, the `helpers` factory's return shape.
|
|
102
|
+
// The mapped type in `ServiceHandlesFor<S>` reads that to type
|
|
103
|
+
// `ctx.svc.<name>` as `{ client: SqlClient }`.
|
|
104
|
+
return {
|
|
105
|
+
image: { type: "registry", reference },
|
|
106
|
+
...(opts.args ? { args: opts.args } : {}),
|
|
107
|
+
env: {
|
|
108
|
+
POSTGRES_DB: opts.database,
|
|
109
|
+
POSTGRES_USER: opts.user,
|
|
110
|
+
POSTGRES_PASSWORD: opts.password,
|
|
111
|
+
// PGDATA lives in a subdir so postgres can initialise inside a bind
|
|
112
|
+
// mount that may not be empty on first boot.
|
|
113
|
+
PGDATA: "/var/lib/postgresql/data/pgdata",
|
|
114
|
+
...(opts.env ?? {}),
|
|
115
|
+
},
|
|
116
|
+
volumes: persistent ? [{ target: "/var/lib/postgresql/data" }] : [],
|
|
117
|
+
ports: [port],
|
|
118
|
+
readyCheck: { type: "tcp" as const, port, timeoutSecs: 60 },
|
|
119
|
+
helpers: ({ name }: { name: string }): PostgresHelpers => {
|
|
120
|
+
const url =
|
|
121
|
+
`postgres://${encodeURIComponent(opts.user)}` +
|
|
122
|
+
`:${encodeURIComponent(opts.password)}` +
|
|
123
|
+
`@${name}:${port}/${encodeURIComponent(opts.database)}`;
|
|
124
|
+
return { client: new SQL(url, { label: name }) };
|
|
125
|
+
},
|
|
126
|
+
// The user's hook, forwarded verbatim — postgres() declares none of
|
|
127
|
+
// its own. If it ever gains one, CHAIN the user's after it (the way
|
|
128
|
+
// `serviceGroup` chains a group hook after the primary part's) rather
|
|
129
|
+
// than letting either one win.
|
|
130
|
+
...(opts.setup ? { setup: opts.setup } : {}),
|
|
131
|
+
} satisfies ServiceDefinition<PostgresHelpers>;
|
|
132
|
+
}
|