momentic 0.0.15 → 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 +148 -66
- package/dist/index.js +1 -1
- 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";
|
|
@@ -750,7 +763,7 @@ var SplitGoalBodySchema = DynamicContextSchema.pick({
|
|
|
750
763
|
url: true
|
|
751
764
|
}).merge(GeneratorOptionsSchema);
|
|
752
765
|
var SplitGoalResponseSchema = z15.string().array();
|
|
753
|
-
var
|
|
766
|
+
var QueueTestsBodySchema = z15.object({
|
|
754
767
|
testIds: z15.string().array()
|
|
755
768
|
});
|
|
756
769
|
var GetTestResponseSchema = ResolvedTestSchema;
|
|
@@ -2495,9 +2508,6 @@ var APIGenerator = class {
|
|
|
2495
2508
|
}
|
|
2496
2509
|
};
|
|
2497
2510
|
|
|
2498
|
-
// package.json
|
|
2499
|
-
var version = "1.0.0";
|
|
2500
|
-
|
|
2501
2511
|
// src/api-client.ts
|
|
2502
2512
|
var API_VERSION2 = "v1";
|
|
2503
2513
|
var APIClient = class {
|
|
@@ -2538,6 +2548,14 @@ var APIClient = class {
|
|
|
2538
2548
|
return GetTestResponseSchema.parse(result);
|
|
2539
2549
|
});
|
|
2540
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
|
+
}
|
|
2541
2559
|
uploadScreenshot(body) {
|
|
2542
2560
|
return __async(this, null, function* () {
|
|
2543
2561
|
const result = yield this.sendRequest(`/${API_VERSION2}/screenshots`, {
|
|
@@ -3156,6 +3174,91 @@ function runTest(_0) {
|
|
|
3156
3174
|
});
|
|
3157
3175
|
}
|
|
3158
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
|
+
|
|
3159
3262
|
// src/cli.ts
|
|
3160
3263
|
var program = new Command4();
|
|
3161
3264
|
program.name("momentic").description("Momentic CLI").version(version);
|
|
@@ -3168,76 +3271,55 @@ program.command("run-tests").addOption(
|
|
|
3168
3271
|
"specify tests to run"
|
|
3169
3272
|
).makeOptionMandatory(true)
|
|
3170
3273
|
).addOption(
|
|
3171
|
-
new Option(
|
|
3172
|
-
"--start <command>",
|
|
3173
|
-
"specify start command"
|
|
3174
|
-
).makeOptionMandatory(true)
|
|
3274
|
+
new Option("--api-key <key>", "API key for authenticating").env("MOMENTIC_API_KEY").makeOptionMandatory(true)
|
|
3175
3275
|
).addOption(
|
|
3176
|
-
new Option("--
|
|
3177
|
-
|
|
3276
|
+
new Option("--server <server>", "Momentic server to use").default(
|
|
3277
|
+
"https://api.momentic.ai"
|
|
3178
3278
|
)
|
|
3179
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(
|
|
3180
3287
|
new Option(
|
|
3181
3288
|
"--wait-on-timeout <timeout>",
|
|
3182
3289
|
"specify how long to wait on url"
|
|
3183
3290
|
).default(60, "one minute")
|
|
3184
|
-
).addOption(
|
|
3185
|
-
new Option("--api-key <key>", "API key for authenticating").env("MOMENTIC_API_KEY").makeOptionMandatory(true)
|
|
3186
3291
|
).action((options) => __async(void 0, null, function* () {
|
|
3187
|
-
const {
|
|
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
|
-
|
|
3216
|
-
)
|
|
3217
|
-
);
|
|
3218
|
-
failedResults.forEach((result) => {
|
|
3219
|
-
console.log(chalk.red(`- ${result.testId}`));
|
|
3220
|
-
});
|
|
3221
|
-
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;
|
|
3222
3321
|
}
|
|
3223
|
-
console.log(chalk.green(`All ${results.length} tests passed!`));
|
|
3224
|
-
process.exit(0);
|
|
3225
3322
|
}));
|
|
3226
|
-
var execCommand = (fullCommand, waitToFinish = true) => __async(void 0, null, function* () {
|
|
3227
|
-
const args = parseArgsStringToArgv2(fullCommand);
|
|
3228
|
-
const toolPath = yield io.which(args[0], true);
|
|
3229
|
-
const toolArguments = args.slice(1);
|
|
3230
|
-
const promise = exec.exec(quote(toolPath), toolArguments);
|
|
3231
|
-
if (waitToFinish) {
|
|
3232
|
-
return promise;
|
|
3233
|
-
}
|
|
3234
|
-
});
|
|
3235
|
-
function installBrowsers() {
|
|
3236
|
-
return __async(this, null, function* () {
|
|
3237
|
-
const executables = registry.defaultExecutables();
|
|
3238
|
-
yield registry.install(executables, false);
|
|
3239
|
-
});
|
|
3240
|
-
}
|
|
3241
3323
|
function main() {
|
|
3242
3324
|
return __async(this, null, function* () {
|
|
3243
3325
|
yield program.parseAsync(process.argv);
|
package/dist/index.js
CHANGED
|
@@ -727,7 +727,7 @@ var SplitGoalBodySchema = DynamicContextSchema.pick({
|
|
|
727
727
|
url: true
|
|
728
728
|
}).merge(GeneratorOptionsSchema);
|
|
729
729
|
var SplitGoalResponseSchema = z15.string().array();
|
|
730
|
-
var
|
|
730
|
+
var QueueTestsBodySchema = z15.object({
|
|
731
731
|
testIds: z15.string().array()
|
|
732
732
|
});
|
|
733
733
|
var CreateRunBodySchema = z15.object({
|