@venturekit/testing 0.0.20 → 0.0.21
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 +105 -39
- package/bin/ensure-db.mjs +64 -0
- package/dist/ensure-database.d.ts +43 -0
- package/dist/ensure-database.d.ts.map +1 -0
- package/dist/ensure-database.js +76 -0
- package/dist/ensure-database.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/playwright/auth-setup.d.ts +58 -0
- package/dist/playwright/auth-setup.d.ts.map +1 -0
- package/dist/playwright/auth-setup.js +79 -0
- package/dist/playwright/auth-setup.js.map +1 -0
- package/dist/playwright/fixtures.d.ts +39 -0
- package/dist/playwright/fixtures.d.ts.map +1 -0
- package/dist/playwright/fixtures.js +46 -0
- package/dist/playwright/fixtures.js.map +1 -0
- package/dist/playwright/index.d.ts +24 -0
- package/dist/playwright/index.d.ts.map +1 -0
- package/dist/playwright/index.js +21 -0
- package/dist/playwright/index.js.map +1 -0
- package/dist/playwright/storage-state.d.ts +28 -0
- package/dist/playwright/storage-state.d.ts.map +1 -0
- package/dist/playwright/storage-state.js +40 -0
- package/dist/playwright/storage-state.js.map +1 -0
- package/dist/playwright/web-servers.d.ts +135 -0
- package/dist/playwright/web-servers.d.ts.map +1 -0
- package/dist/playwright/web-servers.js +122 -0
- package/dist/playwright/web-servers.js.map +1 -0
- package/dist/stack.d.ts +20 -0
- package/dist/stack.d.ts.map +1 -1
- package/dist/stack.js +12 -0
- package/dist/stack.js.map +1 -1
- package/dist/stage-db.d.ts +88 -0
- package/dist/stage-db.d.ts.map +1 -0
- package/dist/stage-db.js +96 -0
- package/dist/stage-db.js.map +1 -0
- package/package.json +25 -6
package/dist/stage-db.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stage database naming + creation.
|
|
3
|
+
*
|
|
4
|
+
* `vk dev --stage <s>` and `vk migrate --env <s>` both derive their local
|
|
5
|
+
* Postgres database from the *declared database intent*, not from the
|
|
6
|
+
* environment: `<databases[].name ?? id>_<stage>`, with dashes folded to
|
|
7
|
+
* underscores so the result is a valid unquoted identifier. An inherited
|
|
8
|
+
* `DATABASE_URL` does **not** override that choice.
|
|
9
|
+
*
|
|
10
|
+
* Two consequences bite every test harness, and both are silent:
|
|
11
|
+
*
|
|
12
|
+
* 1. Point `vk migrate` at a name you picked yourself and the API will
|
|
13
|
+
* happily serve a *different*, unmigrated database — the suite fails
|
|
14
|
+
* with `relation "…" does not exist` rather than a connection error.
|
|
15
|
+
* 2. Nothing creates the database. `vk migrate` connects to it and fails
|
|
16
|
+
* with `database "…" does not exist` on any cold machine or CI runner.
|
|
17
|
+
*
|
|
18
|
+
* `stageDatabaseName` mirrors the CLI's derivation so a harness never has
|
|
19
|
+
* to hardcode the name; `ensureStageDatabase` (./ensure-database.ts) closes
|
|
20
|
+
* the creation gap.
|
|
21
|
+
*
|
|
22
|
+
* Everything here is pure so it can be unit-tested — the one piece that
|
|
23
|
+
* talks to Postgres lives in its own module.
|
|
24
|
+
*/
|
|
25
|
+
/** Local Postgres defaults used by `vk dev`'s generated docker-compose stack. */
|
|
26
|
+
export const LOCAL_PG = {
|
|
27
|
+
host: 'localhost',
|
|
28
|
+
port: 5432,
|
|
29
|
+
user: 'postgres',
|
|
30
|
+
password: 'postgres',
|
|
31
|
+
/** Maintenance database — `CREATE DATABASE` cannot run inside the target. */
|
|
32
|
+
maintenanceDatabase: 'postgres',
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Derive the local Postgres database name for a declared database + stage.
|
|
36
|
+
*
|
|
37
|
+
* Mirrors the CLI's `pgName()` exactly — keep the two in step.
|
|
38
|
+
*/
|
|
39
|
+
export function stageDatabaseName(database, stage) {
|
|
40
|
+
return `${database.replace(/-/g, '_')}_${stage.replace(/-/g, '_')}`;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* True when `name` is a safe unquoted Postgres identifier. Database names
|
|
44
|
+
* reach `CREATE DATABASE` as literal DDL (they cannot be parameterized), so
|
|
45
|
+
* anything else is refused rather than escaped.
|
|
46
|
+
*/
|
|
47
|
+
export function isSafeDatabaseName(name) {
|
|
48
|
+
return /^[A-Za-z0-9_]+$/.test(name);
|
|
49
|
+
}
|
|
50
|
+
/** Build a Postgres URL for an arbitrary database, filling in local defaults. */
|
|
51
|
+
export function pgConnectionString(conn, database) {
|
|
52
|
+
const host = conn.host ?? LOCAL_PG.host;
|
|
53
|
+
const port = conn.port ?? LOCAL_PG.port;
|
|
54
|
+
const user = conn.user ?? LOCAL_PG.user;
|
|
55
|
+
const password = conn.password ?? LOCAL_PG.password;
|
|
56
|
+
return `postgresql://${user}:${password}@${host}:${port}/${database}`;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Connection string for the stage database — the one `vk dev` will serve.
|
|
60
|
+
* Point `vk migrate` and any harness-side pool at this exact URL.
|
|
61
|
+
*/
|
|
62
|
+
export function stageDatabaseUrl(target) {
|
|
63
|
+
return pgConnectionString(target, stageDatabaseName(target.database, target.stage));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Connection string for the maintenance database, used to issue
|
|
67
|
+
* `CREATE DATABASE`.
|
|
68
|
+
*/
|
|
69
|
+
export function adminDatabaseUrl(conn = {}) {
|
|
70
|
+
return pgConnectionString(conn, LOCAL_PG.maintenanceDatabase);
|
|
71
|
+
}
|
|
72
|
+
/** Hide the password before a connection string reaches a log. */
|
|
73
|
+
export function redactUrl(url) {
|
|
74
|
+
return url.replace(/\/\/([^:/@]+):[^@]*@/, '//$1:***@');
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Resolve the database name from either an explicit `name` or a
|
|
78
|
+
* `database` + `stage` pair, and refuse anything unsafe as DDL.
|
|
79
|
+
*
|
|
80
|
+
* Shared by `ensureStageDatabase` so its validation is unit-testable
|
|
81
|
+
* without a live Postgres.
|
|
82
|
+
*/
|
|
83
|
+
export function resolveStageDatabaseName(options) {
|
|
84
|
+
const name = options.name ??
|
|
85
|
+
(options.database && options.stage
|
|
86
|
+
? stageDatabaseName(options.database, options.stage)
|
|
87
|
+
: undefined);
|
|
88
|
+
if (!name) {
|
|
89
|
+
throw new Error('@venturekit/testing: needs either `name`, or both `database` and `stage`, to resolve the stage database.');
|
|
90
|
+
}
|
|
91
|
+
if (!isSafeDatabaseName(name)) {
|
|
92
|
+
throw new Error(`@venturekit/testing: refusing to use an unsafe database name: ${name}`);
|
|
93
|
+
}
|
|
94
|
+
return name;
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=stage-db.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage-db.js","sourceRoot":"","sources":["../src/stage-db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,iFAAiF;AACjF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,UAAU;IACpB,6EAA6E;IAC7E,mBAAmB,EAAE,UAAU;CACvB,CAAC;AAoBX;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB,EAAE,KAAa;IAC/D,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;AACtE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACtC,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,kBAAkB,CAAC,IAAkB,EAAE,QAAgB;IACrE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,QA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M,IAAI,KAAK,CAAC,iEAAiE,IAAI,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit/testing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "Integration & end-to-end test harness for VentureKit apps — launch the local API stack, mint cognito-local users, reset the database, and drive a typed API client.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"bin"
|
|
10
11
|
],
|
|
12
|
+
"bin": {
|
|
13
|
+
"vk-ensure-db": "./bin/ensure-db.mjs"
|
|
14
|
+
},
|
|
11
15
|
"repository": {
|
|
12
16
|
"type": "git",
|
|
13
17
|
"url": "https://github.com/venturekit-dev/venturekit.private.git",
|
|
@@ -22,6 +26,10 @@
|
|
|
22
26
|
".": {
|
|
23
27
|
"types": "./dist/index.d.ts",
|
|
24
28
|
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./playwright": {
|
|
31
|
+
"types": "./dist/playwright/index.d.ts",
|
|
32
|
+
"import": "./dist/playwright/index.js"
|
|
25
33
|
}
|
|
26
34
|
},
|
|
27
35
|
"keywords": [
|
|
@@ -33,8 +41,10 @@
|
|
|
33
41
|
],
|
|
34
42
|
"dependencies": {},
|
|
35
43
|
"peerDependencies": {
|
|
36
|
-
"@venturekit/data": "0.0.
|
|
37
|
-
"@aws-sdk/client-cognito-identity-provider": "^3.1091.0"
|
|
44
|
+
"@venturekit/data": "0.0.21",
|
|
45
|
+
"@aws-sdk/client-cognito-identity-provider": "^3.1091.0",
|
|
46
|
+
"@playwright/test": ">=1.40.0",
|
|
47
|
+
"pg": "^8.11.0"
|
|
38
48
|
},
|
|
39
49
|
"peerDependenciesMeta": {
|
|
40
50
|
"@venturekit/data": {
|
|
@@ -42,12 +52,21 @@
|
|
|
42
52
|
},
|
|
43
53
|
"@aws-sdk/client-cognito-identity-provider": {
|
|
44
54
|
"optional": true
|
|
55
|
+
},
|
|
56
|
+
"@playwright/test": {
|
|
57
|
+
"optional": true
|
|
58
|
+
},
|
|
59
|
+
"pg": {
|
|
60
|
+
"optional": true
|
|
45
61
|
}
|
|
46
62
|
},
|
|
47
63
|
"devDependencies": {
|
|
48
|
-
"@venturekit/data": "0.0.
|
|
64
|
+
"@venturekit/data": "0.0.21",
|
|
49
65
|
"@aws-sdk/client-cognito-identity-provider": "^3.1091.0",
|
|
50
|
-
"@
|
|
66
|
+
"@playwright/test": "^1.49.0",
|
|
67
|
+
"pg": "^8.13.0",
|
|
68
|
+
"@types/pg": "^8.11.10",
|
|
69
|
+
"@types/node": "^26.1.2",
|
|
51
70
|
"typescript": "^5.3.0"
|
|
52
71
|
},
|
|
53
72
|
"scripts": {
|