@multiplatform.one/cli 7.90.3 → 7.90.4
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 +6 -2
- package/lib/bin/multiplatformOne.mjs +14 -225
- package/lib/commands/e2e.mjs +3 -3
- package/lib/commands/merge.mjs +1 -1
- package/lib/commands/scaffold.mjs +1 -1
- package/lib/commands/verbs.mjs +230 -0
- package/lib/source.json +2 -2
- package/package.json +2 -2
- package/src/bin/multiplatformOne.ts +28 -270
- package/src/commands/verbs.spec.ts +207 -0
- package/src/commands/verbs.ts +262 -0
- package/types/bin/multiplatformOne.d.ts.map +1 -1
- package/types/commands/verbs.d.ts +22 -0
- package/types/commands/verbs.d.ts.map +1 -0
- package/lib/types.mjs +0 -1
- package/src/types.ts +0 -5
- package/types/types.d.ts +0 -6
- package/types/types.d.ts.map +0 -1
|
@@ -3,95 +3,39 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
import {
|
|
6
|
+
type WaitService,
|
|
6
7
|
formatServiceList,
|
|
7
8
|
lookupProjectRoot,
|
|
8
|
-
waitForFrappe,
|
|
9
|
-
waitForKeycloak,
|
|
10
|
-
waitForPostgres,
|
|
11
9
|
waitServices,
|
|
12
10
|
} from "@multiplatform.one/utils/dev";
|
|
13
11
|
import { Command } from "commander";
|
|
14
12
|
import dotenv from "dotenv";
|
|
15
13
|
|
|
16
14
|
import spawn from "nano-spawn";
|
|
17
|
-
import YAML from "yaml";
|
|
18
15
|
import yoctoSpinner from "yocto-spinner";
|
|
19
16
|
import { addApp } from "../commands/addApp";
|
|
20
17
|
import { adoptApp } from "../commands/adoptApp";
|
|
21
18
|
import { generateDoctypeTypes, typesDrift } from "../commands/doctypeTypes";
|
|
22
|
-
import {
|
|
19
|
+
import { runE2ESession } from "../commands/e2e";
|
|
23
20
|
import { SINGLETON_APPS, init } from "../commands/init";
|
|
24
21
|
import { INIT_APP_PIECES } from "../commands/pieces";
|
|
25
22
|
import { runRuff } from "../commands/ruff";
|
|
26
23
|
import { updateApp } from "../commands/updateApp";
|
|
24
|
+
import {
|
|
25
|
+
availableServices,
|
|
26
|
+
parseTestTiers,
|
|
27
|
+
runBuild,
|
|
28
|
+
runFrappeBench,
|
|
29
|
+
runIntegrationTests,
|
|
30
|
+
runTurboLint,
|
|
31
|
+
runUnitTests,
|
|
32
|
+
testTiers,
|
|
33
|
+
waitFunctions,
|
|
34
|
+
} from "../commands/verbs";
|
|
27
35
|
|
|
28
36
|
const projectRoot = lookupProjectRoot();
|
|
29
|
-
const availableServices = ["api", "frappe", "solana", "ethereum", "sui"];
|
|
30
|
-
|
|
31
|
-
/** Map a service name to its relative directory from the project root. */
|
|
32
|
-
function serviceDir(name: string): string {
|
|
33
|
-
return `apps/${name}`;
|
|
34
|
-
}
|
|
35
37
|
const defaultDotenvPath = path.resolve(projectRoot, ".env");
|
|
36
38
|
|
|
37
|
-
/** Apps that exist under apps/ and have package.json (discovered from filesystem). */
|
|
38
|
-
async function getPresentApps(root: string): Promise<string[]> {
|
|
39
|
-
const appsDir = path.join(root, "apps");
|
|
40
|
-
try {
|
|
41
|
-
const entries = await fs.readdir(appsDir, { withFileTypes: true });
|
|
42
|
-
const names: string[] = [];
|
|
43
|
-
for (const e of entries) {
|
|
44
|
-
if (!e.isDirectory()) continue;
|
|
45
|
-
const pkgPath = path.join(appsDir, e.name, "package.json");
|
|
46
|
-
try {
|
|
47
|
-
await fs.access(pkgPath);
|
|
48
|
-
names.push(e.name);
|
|
49
|
-
} catch {
|
|
50
|
-
// no package.json
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return names;
|
|
54
|
-
} catch {
|
|
55
|
-
return [];
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Root-level services that exist and have package.json (discovered from filesystem). */
|
|
60
|
-
async function getPresentServices(root: string): Promise<string[]> {
|
|
61
|
-
const names: string[] = [];
|
|
62
|
-
for (const name of availableServices) {
|
|
63
|
-
const dir = path.join(root, serviceDir(name));
|
|
64
|
-
const pkgPath = path.join(dir, "package.json");
|
|
65
|
-
try {
|
|
66
|
-
const stat = await fs.stat(dir);
|
|
67
|
-
if (!stat.isDirectory()) continue;
|
|
68
|
-
await fs.access(pkgPath);
|
|
69
|
-
names.push(name);
|
|
70
|
-
} catch {
|
|
71
|
-
// dir or package.json missing
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return names;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Turbo --filter args to exclude root-level workspaces that are not present (so turbo only runs where they exist).
|
|
78
|
-
* Only generates exclude filters for directories that exist on disk (turbo errors on non-existent filter paths). */
|
|
79
|
-
async function getTurboExcludeFiltersForMissing(root: string): Promise<string[]> {
|
|
80
|
-
const present = await getPresentServices(root);
|
|
81
|
-
const filters: string[] = [];
|
|
82
|
-
for (const s of availableServices) {
|
|
83
|
-
if (present.includes(s)) continue;
|
|
84
|
-
const dir = serviceDir(s);
|
|
85
|
-
try {
|
|
86
|
-
const stat = await fs.stat(path.join(root, dir));
|
|
87
|
-
if (stat.isDirectory()) filters.push(`!./${dir}`);
|
|
88
|
-
} catch {
|
|
89
|
-
// directory doesn't exist; turbo won't find it, no filter needed
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return filters;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
39
|
/** Workspaces that have Storybook and can run visual regression (discovered from filesystem + package.json). */
|
|
96
40
|
export type StorybookVisualWorkspace = {
|
|
97
41
|
dirName: string;
|
|
@@ -179,35 +123,6 @@ async function getStorybookVisualWorkspaces(root: string): Promise<StorybookVisu
|
|
|
179
123
|
return out;
|
|
180
124
|
}
|
|
181
125
|
|
|
182
|
-
/** Discover frappe apps from frappe.yaml that have local source paths.
|
|
183
|
-
* Supports both string entries (`- ./apps/core`) and object entries (`- name: core\n source: ./apps/core`). */
|
|
184
|
-
async function getFrappeApps(root: string): Promise<{ name: string; absolutePath: string }[]> {
|
|
185
|
-
const frappeDir = path.join(root, "apps", "frappe");
|
|
186
|
-
const frappeYamlPath = path.join(frappeDir, "frappe.yaml");
|
|
187
|
-
if (!fsSync.existsSync(frappeYamlPath)) return [];
|
|
188
|
-
const raw = await fs.readFile(frappeYamlPath, "utf8");
|
|
189
|
-
const config = YAML.parse(raw) as { apps?: (string | { name?: string; source?: string })[] };
|
|
190
|
-
const out: { name: string; absolutePath: string }[] = [];
|
|
191
|
-
for (const app of config?.apps ?? []) {
|
|
192
|
-
let src: string;
|
|
193
|
-
let name: string;
|
|
194
|
-
if (typeof app === "string") {
|
|
195
|
-
src = app;
|
|
196
|
-
name = path.basename(app);
|
|
197
|
-
} else {
|
|
198
|
-
if (!app.source || !app.name) continue;
|
|
199
|
-
src = app.source;
|
|
200
|
-
name = app.name;
|
|
201
|
-
}
|
|
202
|
-
src = src.startsWith("file://") ? src.slice(7) : src;
|
|
203
|
-
if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) continue;
|
|
204
|
-
const absPath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
|
|
205
|
-
if (!fsSync.existsSync(absPath)) continue;
|
|
206
|
-
out.push({ name, absolutePath: absPath });
|
|
207
|
-
}
|
|
208
|
-
return out;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
126
|
const program = new Command();
|
|
212
127
|
program.name("mpo");
|
|
213
128
|
program.version(
|
|
@@ -434,20 +349,14 @@ frappe
|
|
|
434
349
|
frappe
|
|
435
350
|
.command("bench")
|
|
436
351
|
.description("run bench command")
|
|
437
|
-
.
|
|
352
|
+
.argument("[args...]", "arguments for bench, after --")
|
|
353
|
+
.action(async (args: string[]) => {
|
|
438
354
|
const parentOptions = frappe.opts();
|
|
439
355
|
dotenv.config({ path: parentOptions.dotenv || defaultDotenvPath });
|
|
440
|
-
await
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
"bench",
|
|
445
|
-
],
|
|
446
|
-
{
|
|
447
|
-
stdio: "inherit",
|
|
448
|
-
shell: true,
|
|
449
|
-
cwd: projectRoot,
|
|
450
|
-
},
|
|
356
|
+
await runFrappeBench(
|
|
357
|
+
args,
|
|
358
|
+
path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../scripts/frappe.sh"),
|
|
359
|
+
projectRoot,
|
|
451
360
|
);
|
|
452
361
|
});
|
|
453
362
|
|
|
@@ -497,77 +406,12 @@ program
|
|
|
497
406
|
)
|
|
498
407
|
.description("run build command")
|
|
499
408
|
.action(async (args: string[]) => {
|
|
500
|
-
|
|
501
|
-
const packages = parsed.includes("packages");
|
|
502
|
-
const projects = parsed.filter((arg) => arg !== "packages");
|
|
503
|
-
const presentApps = await getPresentApps(projectRoot);
|
|
504
|
-
const presentServices = await getPresentServices(projectRoot);
|
|
505
|
-
if ((!projects.length && !packages) || packages) {
|
|
506
|
-
await spawn(
|
|
507
|
-
"pnpm",
|
|
508
|
-
[
|
|
509
|
-
"turbo",
|
|
510
|
-
"run",
|
|
511
|
-
"build",
|
|
512
|
-
"--filter",
|
|
513
|
-
"'!./apps/*'",
|
|
514
|
-
...presentServices.flatMap((s) => ["--filter", `'!./${serviceDir(s)}'`]),
|
|
515
|
-
],
|
|
516
|
-
{
|
|
517
|
-
stdio: "inherit",
|
|
518
|
-
shell: true,
|
|
519
|
-
cwd: projectRoot,
|
|
520
|
-
},
|
|
521
|
-
);
|
|
522
|
-
}
|
|
523
|
-
for (const platform of presentApps) {
|
|
524
|
-
if ((!projects.length && !packages) || projects.includes(platform)) {
|
|
525
|
-
const hasBuild = await fs
|
|
526
|
-
.access(path.join(projectRoot, "apps", platform, "package.json"))
|
|
527
|
-
.then(
|
|
528
|
-
() =>
|
|
529
|
-
JSON.parse(
|
|
530
|
-
fsSync.readFileSync(
|
|
531
|
-
path.join(projectRoot, "apps", platform, "package.json"),
|
|
532
|
-
"utf8",
|
|
533
|
-
),
|
|
534
|
-
).scripts?.build,
|
|
535
|
-
)
|
|
536
|
-
.catch(() => false);
|
|
537
|
-
if (hasBuild) {
|
|
538
|
-
await spawn("pnpm", ["turbo", "run", "build", `--filter=./apps/${platform}`], {
|
|
539
|
-
stdio: "inherit",
|
|
540
|
-
shell: true,
|
|
541
|
-
cwd: projectRoot,
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
for (const service of presentServices) {
|
|
547
|
-
if ((!projects.length && !packages) || projects.includes(service)) {
|
|
548
|
-
const dir = serviceDir(service);
|
|
549
|
-
const hasBuild = await fs
|
|
550
|
-
.access(path.join(projectRoot, dir, "package.json"))
|
|
551
|
-
.then(
|
|
552
|
-
() =>
|
|
553
|
-
JSON.parse(fsSync.readFileSync(path.join(projectRoot, dir, "package.json"), "utf8"))
|
|
554
|
-
.scripts?.build,
|
|
555
|
-
)
|
|
556
|
-
.catch(() => false);
|
|
557
|
-
if (hasBuild) {
|
|
558
|
-
await spawn("pnpm", ["turbo", "run", "build", `--filter=./${dir}`], {
|
|
559
|
-
stdio: "inherit",
|
|
560
|
-
shell: true,
|
|
561
|
-
cwd: projectRoot,
|
|
562
|
-
});
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
409
|
+
await runBuild(args, projectRoot);
|
|
566
410
|
});
|
|
567
411
|
|
|
568
412
|
program
|
|
569
413
|
.command("test")
|
|
570
|
-
.argument("[args...]",
|
|
414
|
+
.argument("[args...]", `test to run: ${testTiers.join(", ")} (default: unit)`)
|
|
571
415
|
.option("--up-only", "start E2E environment and exit (for agent/manual testing)")
|
|
572
416
|
.option("--down", "tear down E2E test environment")
|
|
573
417
|
.option("--port-offset <number>", "port offset from defaults", "1000")
|
|
@@ -576,79 +420,17 @@ program
|
|
|
576
420
|
.option("--filter <pattern>", "run specific Playwright test files")
|
|
577
421
|
.description("run test command")
|
|
578
422
|
.action(async (args: string[], options) => {
|
|
579
|
-
const parsed = args
|
|
423
|
+
const parsed = parseTestTiers(args);
|
|
580
424
|
|
|
581
425
|
// Handle unit tests (turbo test with dynamic excludes: missing services + E2E app, plus frappe app unit tests)
|
|
582
426
|
if (parsed.includes("unit")) {
|
|
583
|
-
|
|
584
|
-
const e2eApp = await discoverE2EApp(projectRoot);
|
|
585
|
-
const filters = [
|
|
586
|
-
...excludeFilters.flatMap((f) => ["--filter", f]),
|
|
587
|
-
...(e2eApp ? ["--filter", `'!./apps/${e2eApp}'`] : []),
|
|
588
|
-
];
|
|
589
|
-
await spawn("pnpm", ["turbo", "run", "test", ...filters], {
|
|
590
|
-
stdio: "inherit",
|
|
591
|
-
shell: true,
|
|
592
|
-
cwd: projectRoot,
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
// Run frappe app unit tests (exclude integration-marked tests)
|
|
596
|
-
const frappeApps = await getFrappeApps(projectRoot);
|
|
597
|
-
for (const app of frappeApps) {
|
|
598
|
-
const hasPytest = await fs
|
|
599
|
-
.access(path.join(app.absolutePath, "pyproject.toml"))
|
|
600
|
-
.then(() => true)
|
|
601
|
-
.catch(() => false);
|
|
602
|
-
if (hasPytest) {
|
|
603
|
-
try {
|
|
604
|
-
await spawn("bench", ["run-tests", "--app", app.name, "--", "-m", "not integration"], {
|
|
605
|
-
stdio: "inherit",
|
|
606
|
-
cwd: path.join(projectRoot, "apps", "frappe"),
|
|
607
|
-
});
|
|
608
|
-
} catch {
|
|
609
|
-
console.warn(`frappe app ${app.name} unit tests failed (bench may not be available)`);
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
427
|
+
await runUnitTests(projectRoot);
|
|
614
428
|
if (parsed.length === 1) return;
|
|
615
429
|
}
|
|
616
430
|
|
|
617
|
-
// Handle integration tests (
|
|
431
|
+
// Handle integration tests (frappe app integration tests)
|
|
618
432
|
if (parsed.includes("integration")) {
|
|
619
|
-
|
|
620
|
-
const e2eApp = await discoverE2EApp(projectRoot);
|
|
621
|
-
const filters = [
|
|
622
|
-
...excludeFilters.flatMap((f) => ["--filter", f]),
|
|
623
|
-
...(e2eApp ? ["--filter", `'!./apps/${e2eApp}'`] : []),
|
|
624
|
-
];
|
|
625
|
-
await spawn("pnpm", ["turbo", "run", "test", ...filters], {
|
|
626
|
-
stdio: "inherit",
|
|
627
|
-
shell: true,
|
|
628
|
-
cwd: projectRoot,
|
|
629
|
-
});
|
|
630
|
-
|
|
631
|
-
// Run frappe app integration tests (only integration-marked tests)
|
|
632
|
-
const frappeApps = await getFrappeApps(projectRoot);
|
|
633
|
-
for (const app of frappeApps) {
|
|
634
|
-
const hasPytest = await fs
|
|
635
|
-
.access(path.join(app.absolutePath, "pyproject.toml"))
|
|
636
|
-
.then(() => true)
|
|
637
|
-
.catch(() => false);
|
|
638
|
-
if (hasPytest) {
|
|
639
|
-
try {
|
|
640
|
-
await spawn("bench", ["run-tests", "--app", app.name, "--", "-m", "integration"], {
|
|
641
|
-
stdio: "inherit",
|
|
642
|
-
cwd: path.join(projectRoot, "apps", "frappe"),
|
|
643
|
-
});
|
|
644
|
-
} catch {
|
|
645
|
-
console.warn(
|
|
646
|
-
`frappe app ${app.name} integration tests failed (bench may not be available)`,
|
|
647
|
-
);
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
|
|
433
|
+
await runIntegrationTests(projectRoot);
|
|
652
434
|
if (parsed.length === 1) return;
|
|
653
435
|
}
|
|
654
436
|
|
|
@@ -735,28 +517,9 @@ program
|
|
|
735
517
|
|
|
736
518
|
program
|
|
737
519
|
.command("lint")
|
|
738
|
-
.description("lint
|
|
520
|
+
.description("lint all supported files (TS, Python, etc.) via turbo")
|
|
739
521
|
.action(async () => {
|
|
740
|
-
const
|
|
741
|
-
let turboFailed = false;
|
|
742
|
-
try {
|
|
743
|
-
await spawn(
|
|
744
|
-
"turbo",
|
|
745
|
-
[
|
|
746
|
-
"run",
|
|
747
|
-
"lint",
|
|
748
|
-
"typecheck",
|
|
749
|
-
"--filter=//",
|
|
750
|
-
"--continue",
|
|
751
|
-
"--filter",
|
|
752
|
-
"!@package/features",
|
|
753
|
-
...excludeFilters.flatMap((f) => ["--filter", f]),
|
|
754
|
-
],
|
|
755
|
-
{ stdio: "inherit", cwd: projectRoot },
|
|
756
|
-
);
|
|
757
|
-
} catch {
|
|
758
|
-
turboFailed = true;
|
|
759
|
-
}
|
|
522
|
+
const turboFailed = await runTurboLint(projectRoot);
|
|
760
523
|
const ruffFailed = await ruffStep("check");
|
|
761
524
|
if (turboFailed || ruffFailed) process.exit(1);
|
|
762
525
|
});
|
|
@@ -801,11 +564,6 @@ async function waitWithSpinner(
|
|
|
801
564
|
options: { interval?: number; timeout?: number } = {},
|
|
802
565
|
) {
|
|
803
566
|
const { interval = 1000, timeout = 600000 } = options;
|
|
804
|
-
const waitFunctions = {
|
|
805
|
-
frappe: waitForFrappe,
|
|
806
|
-
postgres: waitForPostgres,
|
|
807
|
-
keycloak: waitForKeycloak,
|
|
808
|
-
};
|
|
809
567
|
const unreadyServices = [...services];
|
|
810
568
|
const spinner = yoctoSpinner({
|
|
811
569
|
text: `waiting for ${formatServiceList(unreadyServices)}`,
|
|
@@ -822,7 +580,7 @@ async function waitWithSpinner(
|
|
|
822
580
|
await Promise.race([
|
|
823
581
|
Promise.all(
|
|
824
582
|
services.map(async (service) => {
|
|
825
|
-
const waitFn = waitFunctions[service];
|
|
583
|
+
const waitFn = waitFunctions[service as WaitService];
|
|
826
584
|
if (!waitFn) throw new Error(`Unknown service: ${service}`);
|
|
827
585
|
await waitFn(interval);
|
|
828
586
|
updateSpinner(service);
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { waitForMariaDB, waitServices } from "@multiplatform.one/utils/dev";
|
|
5
|
+
import nanoSpawn from "nano-spawn";
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
7
|
+
import {
|
|
8
|
+
availableServices,
|
|
9
|
+
parseTestTiers,
|
|
10
|
+
runBuild,
|
|
11
|
+
runFrappeBench,
|
|
12
|
+
runIntegrationTests,
|
|
13
|
+
runTurboLint,
|
|
14
|
+
runUnitTests,
|
|
15
|
+
waitFunctions,
|
|
16
|
+
} from "./verbs";
|
|
17
|
+
|
|
18
|
+
type Spawn = typeof nanoSpawn;
|
|
19
|
+
|
|
20
|
+
type Call = { file: string; args: string[]; cwd?: string };
|
|
21
|
+
|
|
22
|
+
// Records every spawn and stands a real `sh -c` in for it, so a failure is
|
|
23
|
+
// nano-spawn's own error. `fail` picks the calls that exit 1.
|
|
24
|
+
function recorder(fail: (call: Call) => boolean = () => false) {
|
|
25
|
+
const calls: Call[] = [];
|
|
26
|
+
const spawn = ((file: string, args: readonly string[] = [], options: { cwd?: string } = {}) => {
|
|
27
|
+
const call = { file, args: [...args], cwd: options.cwd };
|
|
28
|
+
calls.push(call);
|
|
29
|
+
return nanoSpawn("sh", ["-c", fail(call) ? "exit 1" : "true"]);
|
|
30
|
+
}) as Spawn;
|
|
31
|
+
return { calls, spawn };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function write(root: string, file: string, body: string) {
|
|
35
|
+
mkdirSync(dirname(join(root, file)), { recursive: true });
|
|
36
|
+
writeFileSync(join(root, file), body);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function plantBench(root: string, { bootstrapped }: { bootstrapped: boolean }) {
|
|
40
|
+
write(root, "apps/frappe/package.json", JSON.stringify({ name: "@service/frappe" }));
|
|
41
|
+
write(root, "apps/frappe/frappe.yaml", "apps:\n - ./apps/core\n - ./apps/live\n");
|
|
42
|
+
write(root, "apps/frappe/apps/core/pyproject.toml", "[tool.pytest.ini_options]\n");
|
|
43
|
+
write(root, "apps/frappe/apps/live/pyproject.toml", "[tool.pytest.ini_options]\n");
|
|
44
|
+
if (bootstrapped) mkdirSync(join(root, "apps/frappe/sites"), { recursive: true });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const isTurboTest = (call: Call) =>
|
|
48
|
+
call.file === "pnpm" && call.args.slice(0, 3).join(" ") === "turbo run test";
|
|
49
|
+
|
|
50
|
+
const benchCalls = (calls: Call[]) => calls.filter((call) => call.file === "bench");
|
|
51
|
+
|
|
52
|
+
describe("mpo test tiers (FZ-10496)", () => {
|
|
53
|
+
let root: string;
|
|
54
|
+
|
|
55
|
+
beforeEach(() => {
|
|
56
|
+
root = mkdtempSync(join(tmpdir(), "mpo-verbs-spec-"));
|
|
57
|
+
write(root, "apps/one/package.json", JSON.stringify({ name: "@platform/one" }));
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(() => {
|
|
61
|
+
rmSync(root, { recursive: true, force: true });
|
|
62
|
+
vi.restoreAllMocks();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("runs the unit tier when no tier is named", () => {
|
|
66
|
+
expect(parseTestTiers([])).toEqual(["unit"]);
|
|
67
|
+
expect(parseTestTiers(["unit,integration"])).toEqual(["unit", "integration"]);
|
|
68
|
+
expect(parseTestTiers(["e2e"])).toEqual(["e2e"]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("refuses a tier it does not have instead of running nothing", () => {
|
|
72
|
+
expect(() => parseTestTiers(["storybook"])).toThrow(
|
|
73
|
+
"unknown test tier storybook (unit, integration, e2e, visual)",
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("unit runs turbo test, then the bench's non-integration tests", async () => {
|
|
78
|
+
plantBench(root, { bootstrapped: true });
|
|
79
|
+
const { calls, spawn } = recorder();
|
|
80
|
+
await runUnitTests(root, spawn);
|
|
81
|
+
expect(calls[0]).toMatchObject({ file: "pnpm", args: ["turbo", "run", "test"], cwd: root });
|
|
82
|
+
expect(benchCalls(calls).map((call) => call.args)).toEqual([
|
|
83
|
+
["run-tests", "--app", "core", "--", "-m", "not integration"],
|
|
84
|
+
["run-tests", "--app", "live", "--", "-m", "not integration"],
|
|
85
|
+
]);
|
|
86
|
+
expect(benchCalls(calls)[0].cwd).toBe(join(root, "apps/frappe"));
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("integration never runs the turbo test task unit already ran", async () => {
|
|
90
|
+
plantBench(root, { bootstrapped: true });
|
|
91
|
+
const { calls, spawn } = recorder();
|
|
92
|
+
await runIntegrationTests(root, spawn);
|
|
93
|
+
expect(calls.filter(isTurboTest)).toEqual([]);
|
|
94
|
+
expect(calls.map((call) => [call.file, ...call.args])).toEqual([
|
|
95
|
+
["bench", "run-tests", "--app", "core", "--", "-m", "integration"],
|
|
96
|
+
["bench", "run-tests", "--app", "live", "--", "-m", "integration"],
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("a bootstrapped bench that fails fails integration, after every app ran", async () => {
|
|
101
|
+
plantBench(root, { bootstrapped: true });
|
|
102
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
103
|
+
const { calls, spawn } = recorder((call) => call.args.includes("core"));
|
|
104
|
+
await expect(runIntegrationTests(root, spawn)).rejects.toThrow(
|
|
105
|
+
'bench tests -m "integration" failed: core',
|
|
106
|
+
);
|
|
107
|
+
expect(benchCalls(calls)).toHaveLength(2);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("a bootstrapped bench that fails fails unit too", async () => {
|
|
111
|
+
plantBench(root, { bootstrapped: true });
|
|
112
|
+
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
113
|
+
const { spawn } = recorder((call) => call.file === "bench");
|
|
114
|
+
await expect(runUnitTests(root, spawn)).rejects.toThrow(
|
|
115
|
+
'bench tests -m "not integration" failed: core, live',
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("a bench that is not bootstrapped is skipped with a note, not run", async () => {
|
|
120
|
+
plantBench(root, { bootstrapped: false });
|
|
121
|
+
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
|
122
|
+
const { calls, spawn } = recorder();
|
|
123
|
+
await runIntegrationTests(root, spawn);
|
|
124
|
+
expect(calls).toEqual([]);
|
|
125
|
+
expect(warn).toHaveBeenCalledWith(
|
|
126
|
+
'no frappe bench (apps/frappe/sites): skipped bench tests -m "integration"',
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("mpo build (FZ-10496)", () => {
|
|
132
|
+
let root: string;
|
|
133
|
+
|
|
134
|
+
beforeEach(() => {
|
|
135
|
+
root = mkdtempSync(join(tmpdir(), "mpo-verbs-spec-"));
|
|
136
|
+
const build = { scripts: { build: "true" } };
|
|
137
|
+
write(root, "apps/one/package.json", JSON.stringify(build));
|
|
138
|
+
write(root, "apps/solana/package.json", JSON.stringify(build));
|
|
139
|
+
write(root, "apps/sui/package.json", JSON.stringify(build));
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
afterEach(() => {
|
|
143
|
+
rmSync(root, { recursive: true, force: true });
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("has no api service", () => {
|
|
147
|
+
expect(availableServices).not.toContain("api");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("builds each chain service once", async () => {
|
|
151
|
+
const { calls, spawn } = recorder();
|
|
152
|
+
await runBuild([], root, spawn);
|
|
153
|
+
const filters = calls.map((call) => call.args.at(-1));
|
|
154
|
+
expect(filters.filter((f) => f === "--filter=./apps/solana")).toHaveLength(1);
|
|
155
|
+
expect(filters.filter((f) => f === "--filter=./apps/sui")).toHaveLength(1);
|
|
156
|
+
expect(filters.filter((f) => f === "--filter=./apps/one")).toHaveLength(1);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("builds a named service once", async () => {
|
|
160
|
+
const { calls, spawn } = recorder();
|
|
161
|
+
await runBuild(["solana"], root, spawn);
|
|
162
|
+
expect(calls.map((call) => [call.file, ...call.args])).toEqual([
|
|
163
|
+
["pnpm", "turbo", "run", "build", "--filter=./apps/solana"],
|
|
164
|
+
]);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe("mpo lint (FZ-10496)", () => {
|
|
169
|
+
it("runs the root lint task and no typecheck", async () => {
|
|
170
|
+
const { calls, spawn } = recorder();
|
|
171
|
+
expect(await runTurboLint("/project", spawn)).toBe(false);
|
|
172
|
+
expect(calls).toEqual([
|
|
173
|
+
{ file: "turbo", args: ["run", "lint", "--filter=//"], cwd: "/project" },
|
|
174
|
+
]);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("reports a failed lint", async () => {
|
|
178
|
+
const { spawn } = recorder(() => true);
|
|
179
|
+
expect(await runTurboLint("/project", spawn)).toBe(true);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe("mpo frappe bench (FZ-10496)", () => {
|
|
184
|
+
it("passes the arguments after -- to bench as given", async () => {
|
|
185
|
+
const { calls, spawn } = recorder();
|
|
186
|
+
await runFrappeBench(
|
|
187
|
+
["--site", "my site", "migrate"],
|
|
188
|
+
"/cli/scripts/frappe.sh",
|
|
189
|
+
"/project",
|
|
190
|
+
spawn,
|
|
191
|
+
);
|
|
192
|
+
expect(calls).toEqual([
|
|
193
|
+
{
|
|
194
|
+
file: "sh",
|
|
195
|
+
args: ["/cli/scripts/frappe.sh", "bench", "--site", "my site", "migrate"],
|
|
196
|
+
cwd: "/project",
|
|
197
|
+
},
|
|
198
|
+
]);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("mpo wait (FZ-10496)", () => {
|
|
203
|
+
it("has a probe for every service its help lists", () => {
|
|
204
|
+
expect(Object.keys(waitFunctions).sort()).toEqual([...waitServices].sort());
|
|
205
|
+
expect(waitFunctions.mariadb).toBe(waitForMariaDB);
|
|
206
|
+
});
|
|
207
|
+
});
|