@elench/testkit 0.1.51 → 0.1.52

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 CHANGED
@@ -65,12 +65,14 @@ import {
65
65
  commandStep,
66
66
  defineTestkitSetup,
67
67
  localDatabase,
68
- moduleStep,
69
68
  nextService,
70
69
  nodeToolchain,
70
+ schemaSql,
71
+ seedCommand,
72
+ seededDatabaseTemplate,
71
73
  service,
72
- sqlFileStep,
73
74
  tsxService,
75
+ verifyModule,
74
76
  } from "@elench/testkit/setup";
75
77
 
76
78
  export default defineTestkitSetup({
@@ -103,12 +105,12 @@ export default defineTestkitSetup({
103
105
  }),
104
106
  envFiles: [".env.testkit"],
105
107
  database: localDatabase({
106
- template: {
108
+ template: seededDatabaseTemplate({
107
109
  inputs: ["db/schema.sql", "scripts/seed.ts"],
108
- migrate: [sqlFileStep("db/schema.sql")],
109
- seed: [commandStep("npm run db:seed")],
110
- verify: [moduleStep("src/testkit/verify-seed.ts#verifySeed")],
111
- },
110
+ schema: schemaSql("db/schema.sql"),
111
+ seed: seedCommand("npm run db:seed"),
112
+ verify: verifyModule("src/testkit/verify-seed.ts#verifySeed"),
113
+ }),
112
114
  }),
113
115
  runtime: {
114
116
  instances: 1,
@@ -191,6 +193,25 @@ inputs, and writes cache state under the service runtime directory. This is the
191
193
  right way to move expensive browser targets from `next dev` / watch mode to
192
194
  stable build-and-start flows.
193
195
 
196
+ `database.template` is the database-side equivalent for reusable template DB
197
+ state. It always executes in three explicit phases:
198
+
199
+ - `migrate`
200
+ - `seed`
201
+ - `verify`
202
+
203
+ For most repos, prefer the intent-focused helpers:
204
+
205
+ - `schemaSql(...)`
206
+ - `seedCommand(...)`
207
+ - `seedModule(...)`
208
+ - `verifyCommand(...)`
209
+ - `verifyModule(...)`
210
+ - `seededDatabaseTemplate(...)`
211
+
212
+ Use raw `commandStep(...)`, `sqlFileStep(...)`, and `moduleStep(...)` arrays when
213
+ you need lower-level control over the exact stage layout.
214
+
194
215
  `runtime.toolchain` is the first-class way to make those prepare/start commands
195
216
  run under the correct Node toolchain instead of whatever `node`/`npm` happened
196
217
  to launch `testkit`. Node toolchains support:
@@ -1,18 +1,18 @@
1
1
  import type { AuthAdapter, HeaderBuilder, HttpSuiteConfig } from "../index";
2
2
 
3
- export interface LocalDatabaseConfig {
4
- provider: "local";
5
- binding?: "shared" | "per-runtime";
6
- image?: string;
7
- password?: string;
8
- reset?: boolean;
9
- template?: {
10
- inputs?: string[];
11
- migrate?: TemplateLifecycleStepConfig[];
12
- seed?: TemplateLifecycleStepConfig[];
13
- verify?: TemplateLifecycleStepConfig[];
14
- };
15
- user?: string;
3
+ export interface DatabaseTemplateConfig {
4
+ inputs?: string[];
5
+ migrate?: TemplateLifecycleStepConfig[];
6
+ seed?: TemplateLifecycleStepConfig[];
7
+ verify?: TemplateLifecycleStepConfig[];
8
+ }
9
+
10
+ export interface SeededDatabaseTemplateOptions {
11
+ inputs?: string[];
12
+ schema?: string | TemplateSqlFileStepConfig;
13
+ migrate?: TemplateLifecycleStepConfig | TemplateLifecycleStepConfig[];
14
+ seed?: TemplateLifecycleStepConfig | TemplateLifecycleStepConfig[];
15
+ verify?: TemplateLifecycleStepConfig | TemplateLifecycleStepConfig[];
16
16
  }
17
17
 
18
18
  export interface TemplateStepBaseConfig {
@@ -40,6 +40,16 @@ export type TemplateLifecycleStepConfig =
40
40
  | TemplateSqlFileStepConfig
41
41
  | TemplateModuleStepConfig;
42
42
 
43
+ export interface LocalDatabaseConfig {
44
+ provider: "local";
45
+ binding?: "shared" | "per-runtime";
46
+ image?: string;
47
+ password?: string;
48
+ reset?: boolean;
49
+ template?: DatabaseTemplateConfig;
50
+ user?: string;
51
+ }
52
+
43
53
  export interface SkipFileRule {
44
54
  path: string;
45
55
  reason: string;
@@ -161,6 +171,29 @@ export declare function moduleStep(
161
171
  specifier: string,
162
172
  options?: Omit<TemplateModuleStepConfig, "kind" | "specifier">
163
173
  ): TemplateModuleStepConfig;
174
+ export declare function schemaSql(
175
+ filePath: string,
176
+ options?: Omit<TemplateSqlFileStepConfig, "kind" | "path">
177
+ ): TemplateSqlFileStepConfig;
178
+ export declare function seedCommand(
179
+ cmd: string,
180
+ options?: Omit<TemplateCommandStepConfig, "kind" | "cmd">
181
+ ): TemplateCommandStepConfig;
182
+ export declare function seedModule(
183
+ specifier: string,
184
+ options?: Omit<TemplateModuleStepConfig, "kind" | "specifier">
185
+ ): TemplateModuleStepConfig;
186
+ export declare function verifyCommand(
187
+ cmd: string,
188
+ options?: Omit<TemplateCommandStepConfig, "kind" | "cmd">
189
+ ): TemplateCommandStepConfig;
190
+ export declare function verifyModule(
191
+ specifier: string,
192
+ options?: Omit<TemplateModuleStepConfig, "kind" | "specifier">
193
+ ): TemplateModuleStepConfig;
194
+ export declare function seededDatabaseTemplate(
195
+ options?: SeededDatabaseTemplateOptions
196
+ ): DatabaseTemplateConfig;
164
197
  export declare function nodeToolchain(options?: NodeToolchainConfig): NodeToolchainConfig;
165
198
  export declare function goService(options: ServiceConfig["local"] & {
166
199
  command?: string;
@@ -56,6 +56,40 @@ export function moduleStep(specifier, options = {}) {
56
56
  };
57
57
  }
58
58
 
59
+ export function schemaSql(filePath, options = {}) {
60
+ return sqlFileStep(filePath, options);
61
+ }
62
+
63
+ export function seedCommand(cmd, options = {}) {
64
+ return commandStep(cmd, options);
65
+ }
66
+
67
+ export function seedModule(specifier, options = {}) {
68
+ return moduleStep(specifier, options);
69
+ }
70
+
71
+ export function verifyCommand(cmd, options = {}) {
72
+ return commandStep(cmd, options);
73
+ }
74
+
75
+ export function verifyModule(specifier, options = {}) {
76
+ return moduleStep(specifier, options);
77
+ }
78
+
79
+ export function seededDatabaseTemplate(options = {}) {
80
+ const migrate = normalizeTemplateStepList(options.migrate);
81
+ const seed = normalizeTemplateStepList(options.seed);
82
+ const verify = normalizeTemplateStepList(options.verify);
83
+ const schema = normalizeSchemaStep(options.schema);
84
+
85
+ return {
86
+ inputs: Array.isArray(options.inputs) ? [...options.inputs] : undefined,
87
+ migrate: schema ? [schema, ...migrate] : migrate,
88
+ seed,
89
+ verify,
90
+ };
91
+ }
92
+
59
93
  export function nodeToolchain(options = {}) {
60
94
  return {
61
95
  kind: "node",
@@ -218,6 +252,19 @@ function requiredNumber(value, label) {
218
252
  return value;
219
253
  }
220
254
 
255
+ function normalizeTemplateStepList(value) {
256
+ if (value == null) return [];
257
+ return Array.isArray(value) ? [...value] : [value];
258
+ }
259
+
260
+ function normalizeSchemaStep(value) {
261
+ if (value == null) return null;
262
+ if (typeof value === "string") {
263
+ return sqlFileStep(value);
264
+ }
265
+ return value;
266
+ }
267
+
221
268
  function envValue(name) {
222
269
  const env = getRuntimeEnv();
223
270
  const value = env?.rawEnv?.[name] || env?.[name];
@@ -1,5 +1,16 @@
1
1
  import { describe, expect, it } from "vitest";
2
- import { goService, nextService, nodeToolchain, tsxService } from "./index.mjs";
2
+ import {
3
+ goService,
4
+ nextService,
5
+ nodeToolchain,
6
+ schemaSql,
7
+ seedCommand,
8
+ seedModule,
9
+ seededDatabaseTemplate,
10
+ tsxService,
11
+ verifyCommand,
12
+ verifyModule,
13
+ } from "./index.mjs";
3
14
 
4
15
  describe("setup helpers", () => {
5
16
  it("emits plain next start commands without an exec prefix", () => {
@@ -31,4 +42,101 @@ describe("setup helpers", () => {
31
42
  install: "download",
32
43
  });
33
44
  });
45
+
46
+ it("emits semantic database template steps using the underlying step shapes", () => {
47
+ expect(schemaSql("db/schema.sql")).toEqual({
48
+ kind: "sql-file",
49
+ path: "db/schema.sql",
50
+ cwd: undefined,
51
+ inputs: undefined,
52
+ });
53
+ expect(seedCommand("npm run db:seed")).toEqual({
54
+ kind: "command",
55
+ cmd: "npm run db:seed",
56
+ cwd: undefined,
57
+ inputs: undefined,
58
+ });
59
+ expect(seedModule("scripts/seed.ts#seed")).toEqual({
60
+ kind: "module",
61
+ specifier: "scripts/seed.ts#seed",
62
+ cwd: undefined,
63
+ inputs: undefined,
64
+ });
65
+ expect(verifyCommand("npm run db:verify")).toEqual({
66
+ kind: "command",
67
+ cmd: "npm run db:verify",
68
+ cwd: undefined,
69
+ inputs: undefined,
70
+ });
71
+ expect(verifyModule("scripts/verify.ts#verify")).toEqual({
72
+ kind: "module",
73
+ specifier: "scripts/verify.ts#verify",
74
+ cwd: undefined,
75
+ inputs: undefined,
76
+ });
77
+ });
78
+
79
+ it("builds a seeded database template from schema, seed, and verify intents", () => {
80
+ expect(
81
+ seededDatabaseTemplate({
82
+ inputs: ["db/schema.sql", "scripts/seed.ts"],
83
+ schema: "db/schema.sql",
84
+ seed: seedCommand("npm run db:seed"),
85
+ verify: verifyModule("scripts/verify.ts#verifySeed"),
86
+ })
87
+ ).toEqual({
88
+ inputs: ["db/schema.sql", "scripts/seed.ts"],
89
+ migrate: [
90
+ {
91
+ kind: "sql-file",
92
+ path: "db/schema.sql",
93
+ cwd: undefined,
94
+ inputs: undefined,
95
+ },
96
+ ],
97
+ seed: [
98
+ {
99
+ kind: "command",
100
+ cmd: "npm run db:seed",
101
+ cwd: undefined,
102
+ inputs: undefined,
103
+ },
104
+ ],
105
+ verify: [
106
+ {
107
+ kind: "module",
108
+ specifier: "scripts/verify.ts#verifySeed",
109
+ cwd: undefined,
110
+ inputs: undefined,
111
+ },
112
+ ],
113
+ });
114
+ });
115
+
116
+ it("prepends schema before explicit migrate steps and normalizes singletons to arrays", () => {
117
+ expect(
118
+ seededDatabaseTemplate({
119
+ schema: schemaSql("db/schema.sql", { cwd: "db" }),
120
+ migrate: seedCommand("echo migrate"),
121
+ })
122
+ ).toEqual({
123
+ inputs: undefined,
124
+ migrate: [
125
+ {
126
+ kind: "sql-file",
127
+ path: "db/schema.sql",
128
+ cwd: "db",
129
+ inputs: undefined,
130
+ },
131
+ {
132
+ kind: "command",
133
+ cmd: "echo migrate",
134
+ cwd: undefined,
135
+ inputs: undefined,
136
+ },
137
+ ],
138
+ seed: [],
139
+ verify: [],
140
+ });
141
+ });
34
142
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elench/testkit",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "description": "CLI for discovering and running local HTTP, DAL, and Playwright test suites",
5
5
  "type": "module",
6
6
  "types": "./lib/index.d.ts",