@elench/testkit 0.1.17 → 0.1.19
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 +76 -16
- package/bin/testkit.mjs +1 -1
- package/lib/bundler/index.mjs +95 -0
- package/lib/bundler/index.test.mjs +79 -0
- package/lib/cli/args.mjs +57 -0
- package/lib/cli/args.test.mjs +62 -0
- package/lib/cli/index.mjs +114 -0
- package/lib/config/index.mjs +294 -0
- package/lib/config/index.test.mjs +12 -0
- package/lib/config/model.mjs +422 -0
- package/lib/config/model.test.mjs +193 -0
- package/lib/database/fingerprint.mjs +61 -0
- package/lib/database/fingerprint.test.mjs +93 -0
- package/lib/{database.mjs → database/index.mjs} +45 -160
- package/lib/database/naming.mjs +47 -0
- package/lib/database/naming.test.mjs +39 -0
- package/lib/database/state.mjs +52 -0
- package/lib/database/state.test.mjs +66 -0
- package/lib/index.mjs +1 -0
- package/lib/k6/checks.mjs +1 -0
- package/lib/k6/dal-suite.mjs +1 -0
- package/lib/k6/dal.mjs +1 -0
- package/lib/k6/http.mjs +1 -0
- package/lib/k6/index.mjs +30 -0
- package/lib/k6/suite.mjs +1 -0
- package/lib/reporters/playwright.mjs +125 -0
- package/lib/reporters/playwright.test.mjs +73 -0
- package/lib/{runner.mjs → runner/index.mjs} +252 -835
- package/lib/runner/metadata.mjs +55 -0
- package/lib/runner/metadata.test.mjs +52 -0
- package/lib/runner/planning.mjs +270 -0
- package/lib/runner/planning.test.mjs +127 -0
- package/lib/runner/results.mjs +285 -0
- package/lib/runner/results.test.mjs +144 -0
- package/lib/runner/state.mjs +71 -0
- package/lib/runner/state.test.mjs +64 -0
- package/lib/runner/template.mjs +320 -0
- package/lib/runner/template.test.mjs +150 -0
- package/lib/runtime/index.mjs +191 -0
- package/lib/runtime-src/k6/checks.js +39 -0
- package/lib/runtime-src/k6/dal-suite.js +33 -0
- package/lib/runtime-src/k6/dal.js +32 -0
- package/lib/runtime-src/k6/http.js +134 -0
- package/lib/runtime-src/k6/suite.js +55 -0
- package/lib/telemetry/index.mjs +43 -0
- package/lib/timing/index.mjs +73 -0
- package/lib/timing/index.test.mjs +64 -0
- package/package.json +18 -3
- package/infra/neon-down.sh +0 -18
- package/infra/neon-up.sh +0 -124
- package/lib/cli.mjs +0 -132
- package/lib/config.mjs +0 -666
- package/lib/exec.mjs +0 -20
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import {
|
|
5
|
+
getServiceEnvFiles as getServiceEnvFilesModel,
|
|
6
|
+
isDalSuiteType as isDalSuiteTypeModel,
|
|
7
|
+
isObject as isObjectModel,
|
|
8
|
+
normalizeTelemetryConfig as normalizeTelemetryConfigModel,
|
|
9
|
+
normalizeTemplateConfig as normalizeTemplateConfigModel,
|
|
10
|
+
parseDotenvString,
|
|
11
|
+
requireString as requireStringModel,
|
|
12
|
+
resolveLifecycleConfig as resolveLifecycleConfigModel,
|
|
13
|
+
resolveSelectedDatabase as resolveSelectedDatabaseModel,
|
|
14
|
+
validateConfigCoverage as validateConfigCoverageModel,
|
|
15
|
+
validateDatabaseProviderConfig as validateDatabaseProviderConfigModel,
|
|
16
|
+
validateHttpUrl as validateHttpUrlModel,
|
|
17
|
+
validateLifecycleConfig as validateLifecycleConfigModel,
|
|
18
|
+
validateRunnerManifest,
|
|
19
|
+
validateServiceConfig as validateServiceConfigModel,
|
|
20
|
+
validateTelemetryConfig as validateTelemetryConfigModel,
|
|
21
|
+
validateTemplateConfig as validateTemplateConfigModel,
|
|
22
|
+
} from "./model.mjs";
|
|
23
|
+
|
|
24
|
+
const RUNNER_MANIFEST = "runner.manifest.json";
|
|
25
|
+
const TESTKIT_CONFIG = "testkit.config.json";
|
|
26
|
+
export function parseDotenv(filePath) {
|
|
27
|
+
if (!fs.existsSync(filePath)) return {};
|
|
28
|
+
return parseDotenvString(fs.readFileSync(filePath, "utf8"));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getServiceNames(cwd) {
|
|
32
|
+
const dir = cwd || process.cwd();
|
|
33
|
+
const runnerPath = path.join(dir, RUNNER_MANIFEST);
|
|
34
|
+
if (!fs.existsSync(runnerPath)) return [];
|
|
35
|
+
const runner = JSON.parse(fs.readFileSync(runnerPath, "utf8"));
|
|
36
|
+
if (!isObject(runner.services)) return [];
|
|
37
|
+
return Object.keys(runner.services);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function loadConfigs(opts = {}) {
|
|
41
|
+
const productDir = resolveProductDir(process.cwd(), opts.dir);
|
|
42
|
+
const runner = loadRunnerManifest(productDir);
|
|
43
|
+
const config = loadTestkitConfig(productDir);
|
|
44
|
+
validateConfigCoverage(runner, config);
|
|
45
|
+
|
|
46
|
+
const serviceEntries = Object.entries(runner.services);
|
|
47
|
+
const filtered = opts.service
|
|
48
|
+
? serviceEntries.filter(([name]) => name === opts.service)
|
|
49
|
+
: serviceEntries;
|
|
50
|
+
|
|
51
|
+
if (opts.service && filtered.length === 0) {
|
|
52
|
+
const available = serviceEntries.map(([name]) => name).join(", ");
|
|
53
|
+
throw new Error(`Service "${opts.service}" not found. Available: ${available}`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return filtered.map(([name, runnerService]) => {
|
|
57
|
+
const serviceConfig = config.services[name];
|
|
58
|
+
if (!serviceConfig) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`Service "${name}" exists in ${RUNNER_MANIFEST} but is missing from ${TESTKIT_CONFIG}`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const resolvedDatabase = resolveSelectedDatabase(name, serviceConfig);
|
|
65
|
+
const serviceEnv = loadServiceEnv(productDir, serviceConfig);
|
|
66
|
+
const selectedBackend = resolvedDatabase?.selectedBackend;
|
|
67
|
+
const resolvedMigrate = resolveLifecycleConfig(serviceConfig.migrate, selectedBackend);
|
|
68
|
+
const resolvedSeed = resolveLifecycleConfig(serviceConfig.seed, selectedBackend);
|
|
69
|
+
validateMergedService(
|
|
70
|
+
name,
|
|
71
|
+
runnerService,
|
|
72
|
+
serviceConfig,
|
|
73
|
+
resolvedDatabase,
|
|
74
|
+
resolvedMigrate,
|
|
75
|
+
resolvedSeed,
|
|
76
|
+
productDir
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
name,
|
|
81
|
+
productDir,
|
|
82
|
+
stateDir: path.join(productDir, ".testkit", name),
|
|
83
|
+
telemetry: normalizeTelemetryConfig(config.telemetry),
|
|
84
|
+
suites: runnerService.suites,
|
|
85
|
+
testkit: {
|
|
86
|
+
...serviceConfig,
|
|
87
|
+
database: resolvedDatabase,
|
|
88
|
+
migrate: resolvedMigrate,
|
|
89
|
+
seed: resolvedSeed,
|
|
90
|
+
envFiles: getServiceEnvFiles(serviceConfig),
|
|
91
|
+
serviceEnv,
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function resolveDalBinary() {
|
|
98
|
+
const thisFile = fileURLToPath(import.meta.url);
|
|
99
|
+
const abs = path.resolve(path.dirname(thisFile), "..", "..", "vendor", "k6");
|
|
100
|
+
if (!fs.existsSync(abs)) {
|
|
101
|
+
throw new Error(`Bundled DAL k6 binary not found: ${abs}`);
|
|
102
|
+
}
|
|
103
|
+
return abs;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function resolveServiceCwd(productDir, maybeRelative) {
|
|
107
|
+
return path.resolve(productDir, maybeRelative || ".");
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function loadRunnerManifest(productDir) {
|
|
111
|
+
const manifestPath = path.join(productDir, RUNNER_MANIFEST);
|
|
112
|
+
const raw = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
113
|
+
validateRunnerManifest(raw, RUNNER_MANIFEST, manifestPath);
|
|
114
|
+
return raw;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function loadTestkitConfig(productDir) {
|
|
118
|
+
const configPath = path.join(productDir, TESTKIT_CONFIG);
|
|
119
|
+
const raw = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
120
|
+
|
|
121
|
+
if (!isObject(raw.services)) {
|
|
122
|
+
throw new Error(`${TESTKIT_CONFIG} must have a "services" object (${configPath})`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (raw.telemetry !== undefined) {
|
|
126
|
+
validateTelemetryConfigModel(raw.telemetry, configPath, TESTKIT_CONFIG);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
for (const [serviceName, service] of Object.entries(raw.services)) {
|
|
130
|
+
validateServiceConfigModel(serviceName, service, configPath);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return raw;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function validateConfigCoverage(runner, config) {
|
|
137
|
+
return validateConfigCoverageModel(runner, config, TESTKIT_CONFIG, RUNNER_MANIFEST);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function resolveProductDir(cwd, explicitDir) {
|
|
141
|
+
if (explicitDir) {
|
|
142
|
+
const dir = path.resolve(cwd, explicitDir);
|
|
143
|
+
ensureProductFiles(dir);
|
|
144
|
+
return dir;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
ensureProductFiles(cwd);
|
|
148
|
+
return cwd;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function ensureProductFiles(dir) {
|
|
152
|
+
const missing = [RUNNER_MANIFEST, TESTKIT_CONFIG].filter(
|
|
153
|
+
(file) => !fs.existsSync(path.join(dir, file))
|
|
154
|
+
);
|
|
155
|
+
if (missing.length > 0) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`Expected ${missing.join(" and ")} in ${dir}. Either cd into a product directory or use --dir.`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function validateMergedService(
|
|
163
|
+
name,
|
|
164
|
+
runnerService,
|
|
165
|
+
serviceConfig,
|
|
166
|
+
resolvedDatabase,
|
|
167
|
+
resolvedMigrate,
|
|
168
|
+
resolvedSeed,
|
|
169
|
+
productDir
|
|
170
|
+
) {
|
|
171
|
+
const usesLocalExecution = Object.values(runnerService.suites).some((suites) =>
|
|
172
|
+
suites.some(
|
|
173
|
+
(suite) =>
|
|
174
|
+
(suite.framework && suite.framework !== "k6") ||
|
|
175
|
+
!isDalSuiteType(suite, runnerService, suites)
|
|
176
|
+
)
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
if (usesLocalExecution && !isObject(serviceConfig.local)) {
|
|
180
|
+
throw new Error(
|
|
181
|
+
`Service "${name}" defines non-DAL suites but has no local runtime in ${TESTKIT_CONFIG}`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (serviceConfig.dependsOn) {
|
|
186
|
+
for (const dep of serviceConfig.dependsOn) {
|
|
187
|
+
if (dep === name) {
|
|
188
|
+
throw new Error(`Service "${name}" cannot depend on itself`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (
|
|
194
|
+
resolvedDatabase?.provider === "local" &&
|
|
195
|
+
(serviceConfig.migrate || serviceConfig.seed) &&
|
|
196
|
+
resolvedDatabase.template.inputs.length === 0
|
|
197
|
+
) {
|
|
198
|
+
throw new Error(
|
|
199
|
+
`Service "${name}" uses local database provisioning with migrations or seeds, so database.template.inputs must list the files/directories that define the template cache`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (serviceConfig.local?.cwd) {
|
|
204
|
+
const cwdPath = resolveServiceCwd(productDir, serviceConfig.local.cwd);
|
|
205
|
+
if (!fs.existsSync(cwdPath)) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
`Service "${name}" local.cwd does not exist: ${serviceConfig.local.cwd}`
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (resolvedMigrate?.cwd) {
|
|
213
|
+
const cwdPath = resolveServiceCwd(productDir, resolvedMigrate.cwd);
|
|
214
|
+
if (!fs.existsSync(cwdPath)) {
|
|
215
|
+
throw new Error(
|
|
216
|
+
`Service "${name}" migrate.cwd does not exist: ${resolvedMigrate.cwd}`
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (resolvedSeed?.cwd) {
|
|
222
|
+
const cwdPath = resolveServiceCwd(productDir, resolvedSeed.cwd);
|
|
223
|
+
if (!fs.existsSync(cwdPath)) {
|
|
224
|
+
throw new Error(
|
|
225
|
+
`Service "${name}" seed.cwd does not exist: ${resolvedSeed.cwd}`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function validateServiceConfig(name, service, configPath) {
|
|
233
|
+
return validateServiceConfigModel(name, service, configPath);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function validateTelemetryConfig(telemetry, configPath) {
|
|
237
|
+
return validateTelemetryConfigModel(telemetry, configPath, TESTKIT_CONFIG);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function loadServiceEnv(productDir, serviceConfig) {
|
|
241
|
+
const env = {};
|
|
242
|
+
for (const envFile of getServiceEnvFiles(serviceConfig)) {
|
|
243
|
+
Object.assign(env, parseDotenv(resolveServiceCwd(productDir, envFile)));
|
|
244
|
+
}
|
|
245
|
+
return env;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function getServiceEnvFiles(serviceConfig) {
|
|
249
|
+
return getServiceEnvFilesModel(serviceConfig);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function resolveSelectedDatabase(name, serviceConfig) {
|
|
253
|
+
return resolveSelectedDatabaseModel(name, serviceConfig);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function validateDatabaseProviderConfig(name, db, label) {
|
|
257
|
+
return validateDatabaseProviderConfigModel(name, db, label);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function validateTemplateConfig(name, template, label) {
|
|
261
|
+
return validateTemplateConfigModel(name, template, label);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function normalizeTemplateConfig(template) {
|
|
265
|
+
return normalizeTemplateConfigModel(template);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function validateLifecycleConfig(name, value, label) {
|
|
269
|
+
return validateLifecycleConfigModel(name, value, label);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function resolveLifecycleConfig(value, selectedBackend) {
|
|
273
|
+
return resolveLifecycleConfigModel(value, selectedBackend);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function requireString(obj, key, label) {
|
|
277
|
+
return requireStringModel(obj, key, label);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function isDalSuiteType(suite, runnerService, suitesForType) {
|
|
281
|
+
return isDalSuiteTypeModel(suite, runnerService, suitesForType);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function isObject(value) {
|
|
285
|
+
return isObjectModel(value);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function normalizeTelemetryConfig(telemetry) {
|
|
289
|
+
return normalizeTelemetryConfigModel(telemetry);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function validateHttpUrl(value, label) {
|
|
293
|
+
return validateHttpUrlModel(value, label);
|
|
294
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { resolveDalBinary } from "./index.mjs";
|
|
5
|
+
|
|
6
|
+
describe("config-index", () => {
|
|
7
|
+
it("resolves the bundled DAL k6 binary from the package root", () => {
|
|
8
|
+
const binaryPath = resolveDalBinary();
|
|
9
|
+
expect(path.basename(binaryPath)).toBe("k6");
|
|
10
|
+
expect(fs.existsSync(binaryPath)).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
});
|