@multiplatform.one/utils 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/lib/dev.cjs +2 -1
- package/lib/dev.mjs +2 -5
- package/package.json +1 -1
- package/src/wait.ts +2 -2
- package/src/waitLoops.spec.ts +1 -2
- package/src/waitMariaDB.spec.ts +73 -0
package/lib/dev.cjs
CHANGED
|
@@ -67,7 +67,8 @@ async function waitForPostgres(interval) {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
async function waitForMariaDB(interval) {
|
|
70
|
-
const
|
|
70
|
+
const { createConnection } = await import("mysql2/promise");
|
|
71
|
+
const connection = await createConnection({
|
|
71
72
|
host: process.env.MARIADB_HOSTNAME || "localhost",
|
|
72
73
|
port: Number.parseInt(process.env.MARIADB_PORT || "3306"),
|
|
73
74
|
user: process.env.MARIADB_USERNAME || "root",
|
package/lib/dev.mjs
CHANGED
|
@@ -5,10 +5,6 @@ import path from "node:path";
|
|
|
5
5
|
import axios from "axios";
|
|
6
6
|
import pg from "pg";
|
|
7
7
|
|
|
8
|
-
//#region \0rolldown/runtime.js
|
|
9
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
8
|
//#region src/wait.ts
|
|
13
9
|
async function waitForFrappe(interval) {
|
|
14
10
|
try {
|
|
@@ -39,7 +35,8 @@ async function waitForPostgres(interval) {
|
|
|
39
35
|
}
|
|
40
36
|
}
|
|
41
37
|
async function waitForMariaDB(interval) {
|
|
42
|
-
const
|
|
38
|
+
const { createConnection } = await import("mysql2/promise");
|
|
39
|
+
const connection = await createConnection({
|
|
43
40
|
host: process.env.MARIADB_HOSTNAME || "localhost",
|
|
44
41
|
port: Number.parseInt(process.env.MARIADB_PORT || "3306"),
|
|
45
42
|
user: process.env.MARIADB_USERNAME || "root",
|
package/package.json
CHANGED
package/src/wait.ts
CHANGED
|
@@ -37,8 +37,8 @@ export async function waitForPostgres(interval: number) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export async function waitForMariaDB(interval: number) {
|
|
40
|
-
const
|
|
41
|
-
const connection = await
|
|
40
|
+
const { createConnection } = await import("mysql2/promise");
|
|
41
|
+
const connection = await createConnection({
|
|
42
42
|
host: process.env.MARIADB_HOSTNAME || "localhost",
|
|
43
43
|
port: Number.parseInt(process.env.MARIADB_PORT || "3306"),
|
|
44
44
|
user: process.env.MARIADB_USERNAME || "root",
|
package/src/waitLoops.spec.ts
CHANGED
|
@@ -3,8 +3,7 @@ import axios from "axios";
|
|
|
3
3
|
import { waitForFrappe, waitForKeycloak, waitForPostgres } from "./wait";
|
|
4
4
|
|
|
5
5
|
// NOTE: waitForMariaDB is intentionally not covered here — it loads its
|
|
6
|
-
// driver through
|
|
7
|
-
// module mocks, so it cannot be exercised without touching the network.
|
|
6
|
+
// driver through `import("mysql2/promise")`, mocked in waitMariaDB.spec.ts.
|
|
8
7
|
|
|
9
8
|
vi.mock("axios", () => ({
|
|
10
9
|
default: { get: vi.fn() },
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { waitForMariaDB } from "./wait";
|
|
3
|
+
|
|
4
|
+
// The driver is loaded with import(), which vitest mocks reach. A bare
|
|
5
|
+
// require() would bypass this mock and dial a real MariaDB, and it throws
|
|
6
|
+
// "require is not defined" when `mpo wait` runs from source under tsx.
|
|
7
|
+
const mysql = vi.hoisted(() => ({
|
|
8
|
+
execute: vi.fn(),
|
|
9
|
+
end: vi.fn(),
|
|
10
|
+
config: undefined as Record<string, unknown> | undefined,
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
vi.mock("mysql2/promise", () => ({
|
|
14
|
+
createConnection: vi.fn(async (config: Record<string, unknown>) => {
|
|
15
|
+
mysql.config = config;
|
|
16
|
+
return { execute: mysql.execute, end: mysql.end };
|
|
17
|
+
}),
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
const envKeys = [
|
|
21
|
+
"MARIADB_DATABASE",
|
|
22
|
+
"MARIADB_HOSTNAME",
|
|
23
|
+
"MARIADB_PASSWORD",
|
|
24
|
+
"MARIADB_PORT",
|
|
25
|
+
"MARIADB_USERNAME",
|
|
26
|
+
] as const;
|
|
27
|
+
|
|
28
|
+
describe("waitForMariaDB (FZ-10496)", () => {
|
|
29
|
+
const saved: Partial<Record<(typeof envKeys)[number], string | undefined>> = {};
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
vi.useFakeTimers();
|
|
33
|
+
for (const key of envKeys) {
|
|
34
|
+
saved[key] = process.env[key];
|
|
35
|
+
delete process.env[key];
|
|
36
|
+
}
|
|
37
|
+
mysql.execute.mockReset().mockResolvedValue([[], []]);
|
|
38
|
+
mysql.end.mockReset().mockResolvedValue(undefined);
|
|
39
|
+
mysql.config = undefined;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
vi.useRealTimers();
|
|
44
|
+
for (const key of envKeys) {
|
|
45
|
+
if (saved[key] === undefined) delete process.env[key];
|
|
46
|
+
else process.env[key] = saved[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("connects with the defaults, answers SELECT 1 and closes", async () => {
|
|
51
|
+
await expect(waitForMariaDB(1000)).resolves.toBeUndefined();
|
|
52
|
+
expect(mysql.config).toEqual({
|
|
53
|
+
host: "localhost",
|
|
54
|
+
port: 3306,
|
|
55
|
+
user: "root",
|
|
56
|
+
password: "root",
|
|
57
|
+
database: "frappe",
|
|
58
|
+
});
|
|
59
|
+
expect(mysql.execute).toHaveBeenCalledWith("SELECT 1");
|
|
60
|
+
expect(mysql.end).toHaveBeenCalledTimes(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("polls every interval until SELECT 1 answers", async () => {
|
|
64
|
+
process.env.MARIADB_PORT = "3307";
|
|
65
|
+
mysql.execute.mockRejectedValueOnce(new Error("not yet")).mockResolvedValue([[], []]);
|
|
66
|
+
const ready = waitForMariaDB(500);
|
|
67
|
+
await vi.advanceTimersByTimeAsync(500);
|
|
68
|
+
await expect(ready).resolves.toBeUndefined();
|
|
69
|
+
expect(mysql.config?.port).toBe(3307);
|
|
70
|
+
expect(mysql.execute).toHaveBeenCalledTimes(2);
|
|
71
|
+
expect(mysql.end).toHaveBeenCalledTimes(1);
|
|
72
|
+
});
|
|
73
|
+
});
|