momentic 0.0.14 → 0.0.16
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/bin/cli.js +156 -71
- package/dist/index.js +7 -5
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -67,11 +67,24 @@ var __async = (__this, __arguments, generator) => {
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
// src/cli.ts
|
|
70
|
+
import { Command as Command4, Option } from "commander";
|
|
71
|
+
|
|
72
|
+
// package.json
|
|
73
|
+
var version = "1.0.0";
|
|
74
|
+
|
|
75
|
+
// src/install-browsers.ts
|
|
76
|
+
import { registry } from "playwright-core/lib/server";
|
|
77
|
+
function installBrowsers() {
|
|
78
|
+
return __async(this, null, function* () {
|
|
79
|
+
const executables = registry.defaultExecutables();
|
|
80
|
+
yield registry.install(executables, false);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/run-tests-locally.ts
|
|
70
85
|
import exec from "@actions/exec";
|
|
71
86
|
import io from "@actions/io";
|
|
72
87
|
import chalk from "chalk";
|
|
73
|
-
import { Command as Command4, Option } from "commander";
|
|
74
|
-
import { registry } from "playwright-core/lib/server";
|
|
75
88
|
import quote from "quote";
|
|
76
89
|
import parseArgsStringToArgv2 from "string-argv";
|
|
77
90
|
import waitOnFn from "wait-on";
|
|
@@ -506,10 +519,11 @@ var ModuleSchema = z10.object({
|
|
|
506
519
|
|
|
507
520
|
// ../../packages/types/src/runs.ts
|
|
508
521
|
import { z as z11 } from "zod";
|
|
509
|
-
var
|
|
522
|
+
var RunTriggerEnum = {
|
|
510
523
|
WEBHOOK: "WEBHOOK",
|
|
511
524
|
CRON: "CRON",
|
|
512
|
-
MANUAL: "MANUAL"
|
|
525
|
+
MANUAL: "MANUAL",
|
|
526
|
+
CLI: "CLI"
|
|
513
527
|
};
|
|
514
528
|
var RunStatusEnum = {
|
|
515
529
|
PENDING: "PENDING",
|
|
@@ -529,7 +543,7 @@ var RunMetadataSchema = z11.object({
|
|
|
529
543
|
finishedAt: DateOrStringSchema.or(z11.null()),
|
|
530
544
|
testId: z11.string().or(z11.null()),
|
|
531
545
|
status: z11.nativeEnum(RunStatusEnum),
|
|
532
|
-
trigger: z11.nativeEnum(
|
|
546
|
+
trigger: z11.nativeEnum(RunTriggerEnum),
|
|
533
547
|
test: z11.object({
|
|
534
548
|
name: z11.string(),
|
|
535
549
|
id: z11.string()
|
|
@@ -749,12 +763,13 @@ var SplitGoalBodySchema = DynamicContextSchema.pick({
|
|
|
749
763
|
url: true
|
|
750
764
|
}).merge(GeneratorOptionsSchema);
|
|
751
765
|
var SplitGoalResponseSchema = z15.string().array();
|
|
752
|
-
var
|
|
766
|
+
var QueueTestsBodySchema = z15.object({
|
|
753
767
|
testIds: z15.string().array()
|
|
754
768
|
});
|
|
755
769
|
var GetTestResponseSchema = ResolvedTestSchema;
|
|
756
770
|
var CreateRunBodySchema = z15.object({
|
|
757
|
-
testId: z15.string()
|
|
771
|
+
testId: z15.string(),
|
|
772
|
+
trigger: z15.nativeEnum(RunTriggerEnum)
|
|
758
773
|
});
|
|
759
774
|
var CreateRunResponseSchema = RunWithTestSchema;
|
|
760
775
|
var GetRunResponseSchema = RunWithTestSchema;
|
|
@@ -2493,9 +2508,6 @@ var APIGenerator = class {
|
|
|
2493
2508
|
}
|
|
2494
2509
|
};
|
|
2495
2510
|
|
|
2496
|
-
// package.json
|
|
2497
|
-
var version = "1.0.0";
|
|
2498
|
-
|
|
2499
2511
|
// src/api-client.ts
|
|
2500
2512
|
var API_VERSION2 = "v1";
|
|
2501
2513
|
var APIClient = class {
|
|
@@ -2536,6 +2548,14 @@ var APIClient = class {
|
|
|
2536
2548
|
return GetTestResponseSchema.parse(result);
|
|
2537
2549
|
});
|
|
2538
2550
|
}
|
|
2551
|
+
queueTests(body) {
|
|
2552
|
+
return __async(this, null, function* () {
|
|
2553
|
+
yield this.sendRequest(`/${API_VERSION2}/tests/queue`, {
|
|
2554
|
+
method: "POST",
|
|
2555
|
+
body
|
|
2556
|
+
});
|
|
2557
|
+
});
|
|
2558
|
+
}
|
|
2539
2559
|
uploadScreenshot(body) {
|
|
2540
2560
|
return __async(this, null, function* () {
|
|
2541
2561
|
const result = yield this.sendRequest(`/${API_VERSION2}/screenshots`, {
|
|
@@ -3123,7 +3143,8 @@ function runTest(_0) {
|
|
|
3123
3143
|
logger: consoleLogger
|
|
3124
3144
|
});
|
|
3125
3145
|
const run = yield apiClient.createRun({
|
|
3126
|
-
testId
|
|
3146
|
+
testId,
|
|
3147
|
+
trigger: "CLI"
|
|
3127
3148
|
});
|
|
3128
3149
|
let failed = true;
|
|
3129
3150
|
try {
|
|
@@ -3153,6 +3174,91 @@ function runTest(_0) {
|
|
|
3153
3174
|
});
|
|
3154
3175
|
}
|
|
3155
3176
|
|
|
3177
|
+
// src/run-tests-locally.ts
|
|
3178
|
+
function runTestsLocally(_0) {
|
|
3179
|
+
return __async(this, arguments, function* ({
|
|
3180
|
+
tests,
|
|
3181
|
+
start,
|
|
3182
|
+
waitOn,
|
|
3183
|
+
waitOnTimeout,
|
|
3184
|
+
server,
|
|
3185
|
+
apiKey
|
|
3186
|
+
}) {
|
|
3187
|
+
yield execCommand(start, false);
|
|
3188
|
+
yield waitOnFn({
|
|
3189
|
+
resources: [waitOn],
|
|
3190
|
+
timeout: waitOnTimeout * 1e3
|
|
3191
|
+
});
|
|
3192
|
+
const apiClient = new APIClient({
|
|
3193
|
+
baseURL: server,
|
|
3194
|
+
apiKey
|
|
3195
|
+
});
|
|
3196
|
+
const apiGenerator = new APIGenerator({
|
|
3197
|
+
baseURL: server,
|
|
3198
|
+
apiKey
|
|
3199
|
+
});
|
|
3200
|
+
const promises = tests.map((testId) => __async(this, null, function* () {
|
|
3201
|
+
let failed = true;
|
|
3202
|
+
try {
|
|
3203
|
+
failed = yield runTest({
|
|
3204
|
+
testId,
|
|
3205
|
+
apiClient,
|
|
3206
|
+
generator: apiGenerator,
|
|
3207
|
+
newBaseURL: waitOn
|
|
3208
|
+
});
|
|
3209
|
+
} catch (e) {
|
|
3210
|
+
console.error(e);
|
|
3211
|
+
}
|
|
3212
|
+
return { failed, testId };
|
|
3213
|
+
}));
|
|
3214
|
+
const results = yield Promise.all(promises);
|
|
3215
|
+
const failedResults = results.filter((result) => result.failed);
|
|
3216
|
+
if (failedResults.length > 0) {
|
|
3217
|
+
console.log(
|
|
3218
|
+
chalk.red(
|
|
3219
|
+
`Failed ${failedResults.length} out of ${results.length} tests:`
|
|
3220
|
+
)
|
|
3221
|
+
);
|
|
3222
|
+
failedResults.forEach((result) => {
|
|
3223
|
+
console.log(chalk.red(`- ${result.testId}`));
|
|
3224
|
+
});
|
|
3225
|
+
process.exit(1);
|
|
3226
|
+
}
|
|
3227
|
+
console.log(chalk.green(`All ${results.length} tests passed!`));
|
|
3228
|
+
process.exit(0);
|
|
3229
|
+
});
|
|
3230
|
+
}
|
|
3231
|
+
function execCommand(fullCommand, waitToFinish = true) {
|
|
3232
|
+
return __async(this, null, function* () {
|
|
3233
|
+
const args = parseArgsStringToArgv2(fullCommand);
|
|
3234
|
+
const toolPath = yield io.which(args[0], true);
|
|
3235
|
+
const toolArguments = args.slice(1);
|
|
3236
|
+
const promise = exec.exec(quote(toolPath), toolArguments);
|
|
3237
|
+
if (waitToFinish) {
|
|
3238
|
+
return promise;
|
|
3239
|
+
}
|
|
3240
|
+
});
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
// src/run-tests-remotely.ts
|
|
3244
|
+
import chalk2 from "chalk";
|
|
3245
|
+
function runTestsRemotely(_0) {
|
|
3246
|
+
return __async(this, arguments, function* ({
|
|
3247
|
+
tests,
|
|
3248
|
+
apiKey,
|
|
3249
|
+
server
|
|
3250
|
+
}) {
|
|
3251
|
+
const apiClient = new APIClient({
|
|
3252
|
+
baseURL: server,
|
|
3253
|
+
apiKey
|
|
3254
|
+
});
|
|
3255
|
+
yield apiClient.queueTests({
|
|
3256
|
+
testIds: tests
|
|
3257
|
+
});
|
|
3258
|
+
console.log(chalk2.green(`Successfully queued ${tests.length} tests!`));
|
|
3259
|
+
});
|
|
3260
|
+
}
|
|
3261
|
+
|
|
3156
3262
|
// src/cli.ts
|
|
3157
3263
|
var program = new Command4();
|
|
3158
3264
|
program.name("momentic").description("Momentic CLI").version(version);
|
|
@@ -3165,76 +3271,55 @@ program.command("run-tests").addOption(
|
|
|
3165
3271
|
"specify tests to run"
|
|
3166
3272
|
).makeOptionMandatory(true)
|
|
3167
3273
|
).addOption(
|
|
3168
|
-
new Option(
|
|
3169
|
-
"--start <command>",
|
|
3170
|
-
"specify start command"
|
|
3171
|
-
).makeOptionMandatory(true)
|
|
3274
|
+
new Option("--api-key <key>", "API key for authenticating").env("MOMENTIC_API_KEY").makeOptionMandatory(true)
|
|
3172
3275
|
).addOption(
|
|
3173
|
-
new Option("--
|
|
3174
|
-
|
|
3276
|
+
new Option("--server <server>", "Momentic server to use").default(
|
|
3277
|
+
"https://api.momentic.ai"
|
|
3175
3278
|
)
|
|
3176
3279
|
).addOption(
|
|
3280
|
+
new Option("--remote", "run tests remotely").default(true).conflicts(["local", "start, waitOn, waitOnTimeout"])
|
|
3281
|
+
).addOption(
|
|
3282
|
+
new Option("--local", "run tests locally").implies({
|
|
3283
|
+
start: "npm run start",
|
|
3284
|
+
waitOn: "http://localhost:3000"
|
|
3285
|
+
})
|
|
3286
|
+
).addOption(new Option("--start <command>", "specify start command")).addOption(new Option("--wait-on <url>", "specify URL to wait on")).addOption(
|
|
3177
3287
|
new Option(
|
|
3178
3288
|
"--wait-on-timeout <timeout>",
|
|
3179
3289
|
"specify how long to wait on url"
|
|
3180
3290
|
).default(60, "one minute")
|
|
3181
|
-
).addOption(
|
|
3182
|
-
new Option("--api-key <key>", "API key for authenticating").env("MOMENTIC_API_KEY").makeOptionMandatory(true)
|
|
3183
3291
|
).action((options) => __async(void 0, null, function* () {
|
|
3184
|
-
const {
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
}
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
}
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
)
|
|
3214
|
-
);
|
|
3215
|
-
failedResults.forEach((result) => {
|
|
3216
|
-
console.log(chalk.red(`- ${result.testId}`));
|
|
3217
|
-
});
|
|
3218
|
-
process.exit(1);
|
|
3292
|
+
const {
|
|
3293
|
+
tests,
|
|
3294
|
+
apiKey,
|
|
3295
|
+
server,
|
|
3296
|
+
remote,
|
|
3297
|
+
local,
|
|
3298
|
+
start,
|
|
3299
|
+
waitOn,
|
|
3300
|
+
waitOnTimeout
|
|
3301
|
+
} = options;
|
|
3302
|
+
if (remote) {
|
|
3303
|
+
yield runTestsRemotely({ tests, apiKey, server });
|
|
3304
|
+
return;
|
|
3305
|
+
}
|
|
3306
|
+
if (local) {
|
|
3307
|
+
try {
|
|
3308
|
+
yield runTestsLocally({
|
|
3309
|
+
tests,
|
|
3310
|
+
start,
|
|
3311
|
+
waitOn,
|
|
3312
|
+
waitOnTimeout,
|
|
3313
|
+
server,
|
|
3314
|
+
apiKey
|
|
3315
|
+
});
|
|
3316
|
+
} catch (e) {
|
|
3317
|
+
console.error(e);
|
|
3318
|
+
process.exit(1);
|
|
3319
|
+
}
|
|
3320
|
+
return;
|
|
3219
3321
|
}
|
|
3220
|
-
console.log(chalk.green(`All ${results.length} tests passed!`));
|
|
3221
|
-
process.exit(0);
|
|
3222
3322
|
}));
|
|
3223
|
-
var execCommand = (fullCommand, waitToFinish = true) => __async(void 0, null, function* () {
|
|
3224
|
-
const args = parseArgsStringToArgv2(fullCommand);
|
|
3225
|
-
const toolPath = yield io.which(args[0], true);
|
|
3226
|
-
const toolArguments = args.slice(1);
|
|
3227
|
-
const promise = exec.exec(quote(toolPath), toolArguments);
|
|
3228
|
-
if (waitToFinish) {
|
|
3229
|
-
return promise;
|
|
3230
|
-
}
|
|
3231
|
-
});
|
|
3232
|
-
function installBrowsers() {
|
|
3233
|
-
return __async(this, null, function* () {
|
|
3234
|
-
const executables = registry.defaultExecutables();
|
|
3235
|
-
yield registry.install(executables, false);
|
|
3236
|
-
});
|
|
3237
|
-
}
|
|
3238
3323
|
function main() {
|
|
3239
3324
|
return __async(this, null, function* () {
|
|
3240
3325
|
yield program.parseAsync(process.argv);
|
package/dist/index.js
CHANGED
|
@@ -483,10 +483,11 @@ var ModuleSchema = z10.object({
|
|
|
483
483
|
|
|
484
484
|
// ../../packages/types/src/runs.ts
|
|
485
485
|
import { z as z11 } from "zod";
|
|
486
|
-
var
|
|
486
|
+
var RunTriggerEnum = {
|
|
487
487
|
WEBHOOK: "WEBHOOK",
|
|
488
488
|
CRON: "CRON",
|
|
489
|
-
MANUAL: "MANUAL"
|
|
489
|
+
MANUAL: "MANUAL",
|
|
490
|
+
CLI: "CLI"
|
|
490
491
|
};
|
|
491
492
|
var RunStatusEnum = {
|
|
492
493
|
PENDING: "PENDING",
|
|
@@ -506,7 +507,7 @@ var RunMetadataSchema = z11.object({
|
|
|
506
507
|
finishedAt: DateOrStringSchema.or(z11.null()),
|
|
507
508
|
testId: z11.string().or(z11.null()),
|
|
508
509
|
status: z11.nativeEnum(RunStatusEnum),
|
|
509
|
-
trigger: z11.nativeEnum(
|
|
510
|
+
trigger: z11.nativeEnum(RunTriggerEnum),
|
|
510
511
|
test: z11.object({
|
|
511
512
|
name: z11.string(),
|
|
512
513
|
id: z11.string()
|
|
@@ -726,11 +727,12 @@ var SplitGoalBodySchema = DynamicContextSchema.pick({
|
|
|
726
727
|
url: true
|
|
727
728
|
}).merge(GeneratorOptionsSchema);
|
|
728
729
|
var SplitGoalResponseSchema = z15.string().array();
|
|
729
|
-
var
|
|
730
|
+
var QueueTestsBodySchema = z15.object({
|
|
730
731
|
testIds: z15.string().array()
|
|
731
732
|
});
|
|
732
733
|
var CreateRunBodySchema = z15.object({
|
|
733
|
-
testId: z15.string()
|
|
734
|
+
testId: z15.string(),
|
|
735
|
+
trigger: z15.nativeEnum(RunTriggerEnum)
|
|
734
736
|
});
|
|
735
737
|
var UpdateRunBodySchema = z15.object({
|
|
736
738
|
startedAt: z15.coerce.date(),
|