@elench/testkit 0.1.118 → 0.1.119

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.
Files changed (30) hide show
  1. package/lib/app/doctor.mjs +11 -113
  2. package/lib/cli/assistant/command-observer.mjs +1 -1
  3. package/lib/cli/assistant/state.mjs +2 -0
  4. package/lib/cli/commands/lint.mjs +37 -0
  5. package/lib/cli/entrypoint.mjs +1 -0
  6. package/lib/cli/operations/lint/operation.mjs +12 -0
  7. package/lib/cli/renderers/doctor/text.mjs +5 -0
  8. package/lib/cli/renderers/lint/text.mjs +20 -0
  9. package/lib/config-api/database-steps.mjs +132 -0
  10. package/lib/config-api/index.d.ts +36 -3
  11. package/lib/config-api/index.mjs +118 -12
  12. package/lib/lint/index.mjs +569 -0
  13. package/lib/runner/template-steps.mjs +8 -0
  14. package/lib/runtime/index.d.ts +43 -0
  15. package/lib/runtime/index.mjs +24 -0
  16. package/lib/runtime-src/k6/http-assertions.js +82 -0
  17. package/lib/shared/configured-steps.mjs +16 -0
  18. package/lib/ui/index.d.ts +46 -0
  19. package/lib/ui/index.mjs +11 -0
  20. package/lib/ui/sandbox.mjs +115 -0
  21. package/node_modules/@elench/next-analysis/package.json +1 -1
  22. package/node_modules/@elench/testkit-bridge/package.json +2 -2
  23. package/node_modules/@elench/testkit-protocol/package.json +1 -1
  24. package/node_modules/@elench/ts-analysis/package.json +1 -1
  25. package/package.json +5 -5
  26. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.d.ts +188 -0
  27. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.d.ts.map +1 -0
  28. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.js +293 -0
  29. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/dist/index.js.map +1 -0
  30. package/packages/testkit-bridge/node_modules/@elench/testkit-protocol/package.json +25 -0
@@ -53,6 +53,38 @@ function buildDatabaseTemplateConfig(options = {}) {
53
53
  };
54
54
  }
55
55
 
56
+ function commandStep(run, options = {}) {
57
+ return {
58
+ kind: "command",
59
+ run,
60
+ ...copyStepOptions(options),
61
+ };
62
+ }
63
+
64
+ function sqlFileStep(filePath, options = {}) {
65
+ return {
66
+ kind: "sql-file",
67
+ path: filePath,
68
+ ...copyStepOptions(options),
69
+ };
70
+ }
71
+
72
+ function moduleStep(target, options = {}) {
73
+ return {
74
+ kind: "module",
75
+ target,
76
+ ...copyStepOptions(options),
77
+ };
78
+ }
79
+
80
+ function copyStepOptions(options = {}) {
81
+ return {
82
+ ...(options.cwd !== undefined ? { cwd: options.cwd } : {}),
83
+ ...(options.inputs !== undefined ? { inputs: [...options.inputs] } : {}),
84
+ ...(options.args !== undefined ? { args: options.args } : {}),
85
+ };
86
+ }
87
+
56
88
  function sourceSchemaFromEnv(envName, options = {}) {
57
89
  if (typeof envName !== "string" || envName.trim().length === 0) {
58
90
  throw new Error("database.schema.fromEnv(...) requires a non-empty env var name");
@@ -69,15 +101,30 @@ function sourceSchemaFromEnv(envName, options = {}) {
69
101
  };
70
102
  }
71
103
 
104
+ function databaseStepTarget(exportName) {
105
+ return `@elench/testkit/config/database-steps#${exportName}`;
106
+ }
107
+
108
+ function verifySeedStep(options = {}) {
109
+ return moduleStep(databaseStepTarget("verifySeed"), { args: options });
110
+ }
111
+
112
+ function materializePostgresBindingStep(options = {}) {
113
+ return moduleStep(databaseStepTarget("materializePostgresBinding"), { args: options });
114
+ }
115
+
72
116
  function postgresFixture(options = {}) {
73
- const { discovery, envFiles, template, ...databaseOptions } = options;
74
- for (const legacyKey of ["inputs", "schema", "migrate", "seed", "verify"]) {
117
+ const { discovery, envFiles, template, inputs, migrate, seed, verify, ...databaseOptions } = options;
118
+ for (const legacyKey of ["schema"]) {
75
119
  if (Object.prototype.hasOwnProperty.call(options, legacyKey)) {
76
120
  throw new Error(
77
- `database.fixture(...) no longer accepts top-level "${legacyKey}". Move lifecycle config under database.fixture({ template: { ... } }).`
121
+ `database.fixture(...) no longer accepts "${legacyKey}". Configure database.sourceSchema instead.`
78
122
  );
79
123
  }
80
124
  }
125
+ const resolvedTemplate = template || hasTemplateLifecycle(options)
126
+ ? buildDatabaseTemplateConfig({ inputs, migrate, seed, verify, ...(template || {}) })
127
+ : undefined;
81
128
  return {
82
129
  discovery: discovery || {
83
130
  roots: [".testkit-fixture"],
@@ -85,16 +132,22 @@ function postgresFixture(options = {}) {
85
132
  envFiles,
86
133
  local: false,
87
134
  database: postgresDatabase(
88
- template
135
+ resolvedTemplate
89
136
  ? {
90
137
  ...databaseOptions,
91
- template: buildDatabaseTemplateConfig(template),
138
+ template: resolvedTemplate,
92
139
  }
93
140
  : databaseOptions
94
141
  ),
95
142
  };
96
143
  }
97
144
 
145
+ function hasTemplateLifecycle(options = {}) {
146
+ return ["inputs", "migrate", "seed", "verify"].some((key) =>
147
+ Object.prototype.hasOwnProperty.call(options, key)
148
+ );
149
+ }
150
+
98
151
  function nodeToolchain(options = {}) {
99
152
  return {
100
153
  kind: "node",
@@ -195,6 +248,8 @@ function nodeApp(options = {}) {
195
248
 
196
249
  function nextApp(options = {}) {
197
250
  const {
251
+ api,
252
+ auth: authMode,
198
253
  baseUrl: explicitBaseUrl,
199
254
  browser,
200
255
  build: explicitBuild,
@@ -214,7 +269,10 @@ function nextApp(options = {}) {
214
269
  } = options;
215
270
 
216
271
  const normalizedPort = requiredNumber(port, "app.next port");
217
- const normalizedEnv = normalizePresetEnv(env);
272
+ const normalizedEnv = {
273
+ ...normalizeNextPresetEnv({ api, authMode }),
274
+ ...normalizePresetEnv(env),
275
+ };
218
276
  const baseUrl = explicitBaseUrl || "http://127.0.0.1:{port}";
219
277
  const build =
220
278
  explicitBuild === undefined
@@ -266,12 +324,16 @@ export const database = {
266
324
  schema: {
267
325
  fromEnv: sourceSchemaFromEnv,
268
326
  },
327
+ steps: {
328
+ materializePostgresBinding: materializePostgresBindingStep,
329
+ verifySeed: verifySeedStep,
330
+ },
269
331
  postgres(options = {}) {
270
- const { template, sourceSchema, ...databaseOptions } = options;
271
- for (const legacyKey of ["inputs", "schema", "migrate", "seed", "verify"]) {
332
+ const { template, sourceSchema, inputs, migrate, seed, verify, ...databaseOptions } = options;
333
+ for (const legacyKey of ["schema"]) {
272
334
  if (Object.prototype.hasOwnProperty.call(options, legacyKey)) {
273
335
  throw new Error(
274
- `database.postgres(...) no longer accepts top-level "${legacyKey}". Move lifecycle config under database.postgres({ template: { ... } }).`
336
+ `database.postgres(...) no longer accepts "${legacyKey}". Use database.postgres({ sourceSchema: database.schema.fromEnv(...) }) instead.`
275
337
  );
276
338
  }
277
339
  }
@@ -281,11 +343,14 @@ export const database = {
281
343
  ...databaseOptions,
282
344
  sourceSchema,
283
345
  };
346
+ const resolvedTemplate = template || hasTemplateLifecycle(options)
347
+ ? buildDatabaseTemplateConfig({ inputs, migrate, seed, verify, ...(template || {}) })
348
+ : undefined;
284
349
  return postgresDatabase(
285
- template
350
+ resolvedTemplate
286
351
  ? {
287
352
  ...normalizedDatabaseOptions,
288
- template: buildDatabaseTemplateConfig(template),
353
+ template: resolvedTemplate,
289
354
  }
290
355
  : normalizedDatabaseOptions
291
356
  );
@@ -293,6 +358,30 @@ export const database = {
293
358
  fixture: postgresFixture,
294
359
  };
295
360
 
361
+ export const step = {
362
+ command: commandStep,
363
+ module: moduleStep,
364
+ sqlFile: sqlFileStep,
365
+ };
366
+
367
+ export const presets = {
368
+ nodeNext(options = {}) {
369
+ return {
370
+ execution: {
371
+ workers: options.workers ?? 1,
372
+ fileTimeoutSeconds: options.fileTimeoutSeconds ?? 120,
373
+ },
374
+ toolchains: {
375
+ node: nodeToolchain({
376
+ install: options.install ?? "download",
377
+ ...(options.node ? { node: options.node } : {}),
378
+ ...(options.npm ? { npm: options.npm } : {}),
379
+ }),
380
+ },
381
+ };
382
+ },
383
+ };
384
+
296
385
  export const toolchain = {
297
386
  node: nodeToolchain,
298
387
  };
@@ -383,6 +472,22 @@ function normalizeDatabaseEnvToken(value, label, sanitize = true) {
383
472
  return normalized;
384
473
  }
385
474
 
475
+ function normalizeNextPresetEnv({ api, authMode } = {}) {
476
+ const env = {};
477
+ if (api) {
478
+ const baseUrlToken = typeof api === "string" ? api : api.baseUrl;
479
+ if (baseUrlToken) {
480
+ env.NEXT_PUBLIC_API_URL = baseUrlToken;
481
+ }
482
+ }
483
+ if (authMode === "disabled-clerk" || authMode?.kind === "disabled-clerk") {
484
+ env.NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY = "testkit_disabled";
485
+ env.CLERK_SECRET_KEY = "testkit_disabled";
486
+ env.CLERK_WEBHOOK_SECRET = "testkit_disabled";
487
+ }
488
+ return env;
489
+ }
490
+
386
491
  function resolveNodeAppStart(build, entry) {
387
492
  if (build?.kind === "tsc") {
388
493
  const compiled = compiledEntryFromSource(entry || build.entry || "src/index.ts", build.outDir || "dist");
@@ -393,7 +498,8 @@ function resolveNodeAppStart(build, entry) {
393
498
 
394
499
  function normalizeTemplateStepList(value) {
395
500
  if (value == null) return [];
396
- return Array.isArray(value) ? [...value] : [value];
501
+ const values = Array.isArray(value) ? value : [value];
502
+ return values.map((entry) => typeof entry === "string" ? commandStep(entry) : entry);
397
503
  }
398
504
 
399
505
  function compiledEntryFromSource(entry, outDir) {