@elench/testkit 0.1.46 → 0.1.47

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.
@@ -1,12 +1,10 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { execaCommand } from "execa";
4
- import { resolveServiceCwd } from "../config/index.mjs";
5
3
  import { prepareDatabaseRuntime } from "../database/index.mjs";
6
4
  import { taskNeedsLocalRuntime } from "./planning.mjs";
7
5
  import { writeGraphMetadata } from "./state.mjs";
8
6
  import { startLocalServices, stopLocalServices } from "./services.mjs";
9
- import { buildExecutionEnv, resolveRuntimeInstanceConfigs } from "./template.mjs";
7
+ import { resolveRuntimeInstanceConfigs } from "./template.mjs";
10
8
 
11
9
  export function createRuntimeInstanceContext(runtimeId, graph, productDir) {
12
10
  const graphDir = path.join(productDir, ".testkit", "_graphs", graph.dirName);
@@ -78,43 +76,6 @@ export async function cleanupRuntimeInstanceContext(context, lifecycle) {
78
76
 
79
77
  export async function prepareDatabases(runtimeConfigs) {
80
78
  for (const config of runtimeConfigs) {
81
- await prepareDatabaseRuntime(config, {
82
- runMigrate: config.testkit.migrate
83
- ? (databaseUrl) => runMigrate(config, databaseUrl)
84
- : null,
85
- runSeed: config.testkit.seed ? (databaseUrl) => runSeed(config, databaseUrl) : null,
86
- });
79
+ await prepareDatabaseRuntime(config);
87
80
  }
88
81
  }
89
-
90
- async function runMigrate(config, databaseUrl) {
91
- const migrate = config.testkit.migrate;
92
- if (!migrate) return;
93
-
94
- const env = buildExecutionEnv(config, {}, process.env);
95
- if (databaseUrl) env.DATABASE_URL = databaseUrl;
96
-
97
- console.log(`\n── migrate:${config.runtimeLabel}:${config.name} ──`);
98
- await execaCommand(migrate.cmd, {
99
- cwd: resolveServiceCwd(config.productDir, migrate.cwd),
100
- env,
101
- stdio: "inherit",
102
- shell: true,
103
- });
104
- }
105
-
106
- async function runSeed(config, databaseUrl) {
107
- const seed = config.testkit.seed;
108
- if (!seed) return;
109
-
110
- const env = buildExecutionEnv(config, {}, process.env);
111
- if (databaseUrl) env.DATABASE_URL = databaseUrl;
112
-
113
- console.log(`\n── seed:${config.runtimeLabel}:${config.name} ──`);
114
- await execaCommand(seed.cmd, {
115
- cwd: resolveServiceCwd(config.productDir, seed.cwd),
116
- env,
117
- stdio: "inherit",
118
- shell: true,
119
- });
120
- }
@@ -131,28 +131,7 @@ export function resolveRuntimeConfig(
131
131
  const database = config.testkit.database
132
132
  ? {
133
133
  ...config.testkit.database,
134
- }
135
- : undefined;
136
-
137
- const migrate = config.testkit.migrate
138
- ? {
139
- ...config.testkit.migrate,
140
- cmd: finalizeString(config.testkit.migrate.cmd, context),
141
- cwd:
142
- config.testkit.migrate.cwd !== undefined
143
- ? finalizeString(config.testkit.migrate.cwd, context)
144
- : config.testkit.migrate.cwd,
145
- }
146
- : undefined;
147
-
148
- const seed = config.testkit.seed
149
- ? {
150
- ...config.testkit.seed,
151
- cmd: finalizeString(config.testkit.seed.cmd, context),
152
- cwd:
153
- config.testkit.seed.cwd !== undefined
154
- ? finalizeString(config.testkit.seed.cwd, context)
155
- : config.testkit.seed.cwd,
134
+ template: finalizeDatabaseTemplate(config.testkit.database.template, context),
156
135
  }
157
136
  : undefined;
158
137
 
@@ -179,14 +158,41 @@ export function resolveRuntimeConfig(
179
158
  testkit: {
180
159
  ...config.testkit,
181
160
  database,
182
- migrate,
183
- seed,
184
161
  templateContext: context,
185
162
  local,
186
163
  },
187
164
  };
188
165
  }
189
166
 
167
+ function finalizeDatabaseTemplate(template, context) {
168
+ if (!template) {
169
+ return {
170
+ inputs: [],
171
+ migrate: [],
172
+ seed: [],
173
+ verify: [],
174
+ };
175
+ }
176
+
177
+ const finalizeStep = (step) => ({
178
+ ...step,
179
+ ...(typeof step.cmd === "string" ? { cmd: finalizeString(step.cmd, context) } : {}),
180
+ ...(typeof step.cwd === "string" ? { cwd: finalizeString(step.cwd, context) } : {}),
181
+ ...(typeof step.path === "string" ? { path: finalizeString(step.path, context) } : {}),
182
+ ...(typeof step.specifier === "string"
183
+ ? { specifier: finalizeString(step.specifier, context) }
184
+ : {}),
185
+ inputs: (step.inputs || []).map((input) => finalizeString(input, context)),
186
+ });
187
+
188
+ return {
189
+ inputs: (template.inputs || []).map((input) => finalizeString(input, context)),
190
+ migrate: (template.migrate || []).map(finalizeStep),
191
+ seed: (template.seed || []).map(finalizeStep),
192
+ verify: (template.verify || []).map(finalizeStep),
193
+ };
194
+ }
195
+
190
196
  export function resolveServiceStateDir(runtimeDir, config) {
191
197
  return path.join(runtimeDir, "services", config.name);
192
198
  }
@@ -26,8 +26,7 @@ function makeRuntimeConfig(name, local, extras = {}) {
26
26
  local,
27
27
  serviceEnv: extras.serviceEnv || {},
28
28
  databaseFrom: extras.databaseFrom,
29
- migrate: extras.migrate,
30
- seed: extras.seed,
29
+ database: extras.database,
31
30
  templateContext: extras.templateContext,
32
31
  },
33
32
  };
@@ -8,17 +8,38 @@ export interface LocalDatabaseConfig {
8
8
  reset?: boolean;
9
9
  template?: {
10
10
  inputs?: string[];
11
+ migrate?: TemplateLifecycleStepConfig[];
12
+ seed?: TemplateLifecycleStepConfig[];
13
+ verify?: TemplateLifecycleStepConfig[];
11
14
  };
12
15
  user?: string;
13
16
  }
14
17
 
15
- export interface LifecycleConfig {
16
- cmd: string;
18
+ export interface TemplateStepBaseConfig {
17
19
  cwd?: string;
18
- testkitCmd?: string;
19
- testkitCwd?: string;
20
+ inputs?: string[];
21
+ }
22
+
23
+ export interface TemplateCommandStepConfig extends TemplateStepBaseConfig {
24
+ kind: "command";
25
+ cmd: string;
26
+ }
27
+
28
+ export interface TemplateSqlFileStepConfig extends TemplateStepBaseConfig {
29
+ kind: "sql-file";
30
+ path: string;
20
31
  }
21
32
 
33
+ export interface TemplateModuleStepConfig extends TemplateStepBaseConfig {
34
+ kind: "module";
35
+ specifier: string;
36
+ }
37
+
38
+ export type TemplateLifecycleStepConfig =
39
+ | TemplateCommandStepConfig
40
+ | TemplateSqlFileStepConfig
41
+ | TemplateModuleStepConfig;
42
+
22
43
  export interface SkipFileRule {
23
44
  path: string;
24
45
  reason: string;
@@ -84,8 +105,6 @@ export interface ServiceConfig {
84
105
  readyUrl: string;
85
106
  start: string;
86
107
  };
87
- migrate?: LifecycleConfig;
88
- seed?: LifecycleConfig;
89
108
  runtime?: RuntimeConfig;
90
109
  requirements?: ServiceRequirementConfig;
91
110
  skip?: SkipConfig;
@@ -113,7 +132,18 @@ export declare function defineTestkitSetup<T extends TestkitSetup>(setup: T): T;
113
132
  export declare function defineHttpProfile<T extends HttpSuiteConfig>(profile: T): T;
114
133
  export declare function service<T extends ServiceConfig>(config: T): T;
115
134
  export declare function localDatabase(options?: Omit<LocalDatabaseConfig, "provider">): LocalDatabaseConfig;
116
- export declare function lifecycle(cmd: string, options?: Omit<LifecycleConfig, "cmd">): LifecycleConfig;
135
+ export declare function commandStep(
136
+ cmd: string,
137
+ options?: Omit<TemplateCommandStepConfig, "kind" | "cmd">
138
+ ): TemplateCommandStepConfig;
139
+ export declare function sqlFileStep(
140
+ filePath: string,
141
+ options?: Omit<TemplateSqlFileStepConfig, "kind" | "path">
142
+ ): TemplateSqlFileStepConfig;
143
+ export declare function moduleStep(
144
+ specifier: string,
145
+ options?: Omit<TemplateModuleStepConfig, "kind" | "specifier">
146
+ ): TemplateModuleStepConfig;
117
147
  export declare function goService(options: ServiceConfig["local"] & {
118
148
  command?: string;
119
149
  entrypoint?: string;
@@ -29,12 +29,30 @@ export function localDatabase(options = {}) {
29
29
  };
30
30
  }
31
31
 
32
- export function lifecycle(cmd, options = {}) {
32
+ export function commandStep(cmd, options = {}) {
33
33
  return {
34
+ kind: "command",
34
35
  cmd,
35
36
  cwd: options.cwd,
36
- testkitCmd: options.testkitCmd,
37
- testkitCwd: options.testkitCwd,
37
+ inputs: Array.isArray(options.inputs) ? [...options.inputs] : undefined,
38
+ };
39
+ }
40
+
41
+ export function sqlFileStep(filePath, options = {}) {
42
+ return {
43
+ kind: "sql-file",
44
+ path: filePath,
45
+ cwd: options.cwd,
46
+ inputs: Array.isArray(options.inputs) ? [...options.inputs] : undefined,
47
+ };
48
+ }
49
+
50
+ export function moduleStep(specifier, options = {}) {
51
+ return {
52
+ kind: "module",
53
+ specifier,
54
+ cwd: options.cwd,
55
+ inputs: Array.isArray(options.inputs) ? [...options.inputs] : undefined,
38
56
  };
39
57
  }
40
58
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elench/testkit",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
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",