@venturekit/testing 0.0.20 → 0.0.22
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/cognito.d.ts +5 -2
- package/dist/cognito.d.ts.map +1 -1
- package/dist/cognito.js +14 -2
- package/dist/cognito.js.map +1 -1
- package/dist/ensure-database.d.ts +52 -0
- package/dist/ensure-database.d.ts.map +1 -0
- package/dist/ensure-database.js +82 -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 +139 -0
- package/dist/playwright/web-servers.d.ts.map +1 -0
- package/dist/playwright/web-servers.js +128 -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/stack.js
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
import { spawn } from 'node:child_process';
|
|
18
18
|
import { existsSync } from 'node:fs';
|
|
19
19
|
import { join } from 'node:path';
|
|
20
|
+
import { ensureStageDatabase } from './ensure-database.js';
|
|
20
21
|
import { waitForReady, vkDevServerReady } from './ready.js';
|
|
22
|
+
import { stageDatabaseUrl } from './stage-db.js';
|
|
21
23
|
/** Resolve the `vk` binary from the nearest `node_modules/.bin`, else PATH. */
|
|
22
24
|
function resolveVkBin(cwd, override) {
|
|
23
25
|
if (override)
|
|
@@ -98,6 +100,14 @@ export async function startTestStack(options = {}) {
|
|
|
98
100
|
const stdio = options.stdio ?? 'inherit';
|
|
99
101
|
const vk = resolveVkBin(cwd, options.vkBin);
|
|
100
102
|
const env = { ...process.env, ...options.env, VENTURE_STAGE: stage };
|
|
103
|
+
// Nothing in the CLI creates the database, so do it here — before the
|
|
104
|
+
// migration that would otherwise fail on a cold machine. Pinning
|
|
105
|
+
// DATABASE_URL to the derived name keeps `vk migrate` on the database
|
|
106
|
+
// `vk dev` picks for itself.
|
|
107
|
+
if (options.database) {
|
|
108
|
+
await ensureStageDatabase({ database: options.database, stage });
|
|
109
|
+
env.DATABASE_URL = stageDatabaseUrl({ database: options.database, stage });
|
|
110
|
+
}
|
|
101
111
|
// `vk dev` does NOT auto-migrate — apply schema (and optionally seeds) first.
|
|
102
112
|
if (options.migrate !== false) {
|
|
103
113
|
const migrateArgs = ['migrate', '--env', stage];
|
|
@@ -108,6 +118,8 @@ export async function startTestStack(options = {}) {
|
|
|
108
118
|
const devArgs = ['dev', '--stage', stage, '--port', String(port)];
|
|
109
119
|
if (options.watch !== true)
|
|
110
120
|
devArgs.push('--no-watch');
|
|
121
|
+
if (options.crons !== true)
|
|
122
|
+
devArgs.push('--no-crons');
|
|
111
123
|
const child = spawn(vk, devArgs, {
|
|
112
124
|
cwd,
|
|
113
125
|
env,
|
package/dist/stack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../src/stack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../src/stack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,KAAK,EAAqB,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAuDjD,+EAA+E;AAC/E,SAAS,YAAY,CAAC,GAAW,EAAE,QAAiB;IAClD,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,MAAM,OAAO,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IAC/D,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,SAAS,CAAC;QACR,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC7D,IAAI,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,SAAS,CAAC;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAC/B,IAAI,MAAM,K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C,CAAC,CAAC;IAEH,IAAI,MAAM,GAAmC,IAAI,CAAC;IAClD,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QACxB,MAAM,GAAG,EAAE,IAAI,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,KAAK,IAAmB,EAAE;QACrC,MAAM,SAAS,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,YAAY,CAAC;YACjB,OAAO;YACP,SAAS,EAAE,OAAO,CAAC,cAAc,IAAI,OAAO;YAC5C,QAAQ,EAAE,gBAAgB;SAC3B,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,EAAE,CAAC;QACb,MAAM,KAAK,GAAG,MAAwC,CAAC;QACvD,IAAI,KAAK,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CACb,6BAA6B,KAAK,CAAC,IAAI,IAAI,MAAM,8BAA8B,OAAO,EAAE,CACzF,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
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 declare const LOCAL_PG: {
|
|
27
|
+
readonly host: "localhost";
|
|
28
|
+
readonly port: 5432;
|
|
29
|
+
readonly user: "postgres";
|
|
30
|
+
readonly password: "postgres";
|
|
31
|
+
/** Maintenance database — `CREATE DATABASE` cannot run inside the target. */
|
|
32
|
+
readonly maintenanceDatabase: "postgres";
|
|
33
|
+
};
|
|
34
|
+
export interface StageDatabaseTarget {
|
|
35
|
+
/**
|
|
36
|
+
* The declared database name — `infrastructure.databases[].name` (falling
|
|
37
|
+
* back to its `id`) from `vk.config.ts`. NOT the project name: the CLI
|
|
38
|
+
* deliberately does not prefix it.
|
|
39
|
+
*/
|
|
40
|
+
database: string;
|
|
41
|
+
/** Stage label, e.g. `test`. Matches `vk dev --stage` / `vk migrate --env`. */
|
|
42
|
+
stage: string;
|
|
43
|
+
}
|
|
44
|
+
export interface PgConnection {
|
|
45
|
+
host?: string;
|
|
46
|
+
port?: number;
|
|
47
|
+
user?: string;
|
|
48
|
+
password?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Derive the local Postgres database name for a declared database + stage.
|
|
52
|
+
*
|
|
53
|
+
* Mirrors the CLI's `pgName()` exactly — keep the two in step.
|
|
54
|
+
*/
|
|
55
|
+
export declare function stageDatabaseName(database: string, stage: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* True when `name` is a safe unquoted Postgres identifier. Database names
|
|
58
|
+
* reach `CREATE DATABASE` as literal DDL (they cannot be parameterized), so
|
|
59
|
+
* anything else is refused rather than escaped.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isSafeDatabaseName(name: string): boolean;
|
|
62
|
+
/** Build a Postgres URL for an arbitrary database, filling in local defaults. */
|
|
63
|
+
export declare function pgConnectionString(conn: PgConnection, database: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Connection string for the stage database — the one `vk dev` will serve.
|
|
66
|
+
* Point `vk migrate` and any harness-side pool at this exact URL.
|
|
67
|
+
*/
|
|
68
|
+
export declare function stageDatabaseUrl(target: StageDatabaseTarget & PgConnection): string;
|
|
69
|
+
/**
|
|
70
|
+
* Connection string for the maintenance database, used to issue
|
|
71
|
+
* `CREATE DATABASE`.
|
|
72
|
+
*/
|
|
73
|
+
export declare function adminDatabaseUrl(conn?: PgConnection): string;
|
|
74
|
+
/** Hide the password before a connection string reaches a log. */
|
|
75
|
+
export declare function redactUrl(url: string): string;
|
|
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 declare function resolveStageDatabaseName(options: {
|
|
84
|
+
name?: string;
|
|
85
|
+
database?: string;
|
|
86
|
+
stage?: string;
|
|
87
|
+
}): string;
|
|
88
|
+
//# sourceMappingURL=stage-db.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stage-db.d.ts","sourceRoot":"","sources":["../src/stage-db.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,iFAAiF;AACjF,eAAO,MAAM,QAAQ;;;;;IAKnB,6EAA6E;;CAErE,CAAC;AAEX,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED,iFAAiF;AACjF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM/E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,mBAAmB,GAAG,YAAY,GAAG,MAAM,CAEnF;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,GAAE,YAAiB,GAAG,MAAM,CAEhE;AAED,kEAAkE;AAClE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,GAAG,MAAM,CAgBT"}
|
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,QAAQ,CAAC,IAAI,CAAC;IACxC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,IAAI,QAAQ,CAAC,IAAI,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ACd,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venturekit/testing",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
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.22",
|
|
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.22",
|
|
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": {
|