mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 08:20:43 +00:00
test(extensions): share direct import smoke harness
This commit is contained in:
@@ -1,53 +1,18 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
||||
const ircImportEnv = {
|
||||
HOME: process.env.HOME,
|
||||
NODE_OPTIONS: process.env.NODE_OPTIONS,
|
||||
NODE_PATH: process.env.NODE_PATH,
|
||||
PATH: process.env.PATH,
|
||||
TERM: process.env.TERM,
|
||||
} satisfies NodeJS.ProcessEnv;
|
||||
import { runDirectImportSmoke } from "../../test/helpers/plugins/direct-smoke.js";
|
||||
|
||||
describe("irc bundled api seams", () => {
|
||||
it("loads the narrow channel plugin api in direct smoke", async () => {
|
||||
const { stdout } = await execFileAsync(
|
||||
process.execPath,
|
||||
[
|
||||
"--import",
|
||||
"tsx",
|
||||
"-e",
|
||||
'const mod = await import("./extensions/irc/channel-plugin-api.ts"); process.stdout.write(JSON.stringify({keys:Object.keys(mod).sort(), id: mod.ircPlugin.id}));',
|
||||
],
|
||||
{
|
||||
cwd: repoRoot,
|
||||
env: ircImportEnv,
|
||||
timeout: 40_000,
|
||||
},
|
||||
const stdout = await runDirectImportSmoke(
|
||||
'const mod = await import("./extensions/irc/channel-plugin-api.ts"); process.stdout.write(JSON.stringify({keys:Object.keys(mod).sort(), id: mod.ircPlugin.id}));',
|
||||
);
|
||||
|
||||
expect(stdout).toBe('{"keys":["ircPlugin"],"id":"irc"}');
|
||||
}, 45_000);
|
||||
|
||||
it("loads the narrow runtime api in direct smoke", async () => {
|
||||
const { stdout } = await execFileAsync(
|
||||
process.execPath,
|
||||
[
|
||||
"--import",
|
||||
"tsx",
|
||||
"-e",
|
||||
'const mod = await import("./extensions/irc/runtime-api.ts"); process.stdout.write(JSON.stringify({keys:Object.keys(mod).sort(), type: typeof mod.setIrcRuntime}));',
|
||||
],
|
||||
{
|
||||
cwd: repoRoot,
|
||||
env: ircImportEnv,
|
||||
timeout: 40_000,
|
||||
},
|
||||
const stdout = await runDirectImportSmoke(
|
||||
'const mod = await import("./extensions/irc/runtime-api.ts"); process.stdout.write(JSON.stringify({keys:Object.keys(mod).sort(), type: typeof mod.setIrcRuntime}));',
|
||||
);
|
||||
|
||||
expect(stdout).toBe('{"keys":["setIrcRuntime"],"type":"function"}');
|
||||
|
||||
@@ -1,34 +1,10 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
||||
const importEnv = {
|
||||
HOME: process.env.HOME,
|
||||
NODE_OPTIONS: process.env.NODE_OPTIONS,
|
||||
NODE_PATH: process.env.NODE_PATH,
|
||||
PATH: process.env.PATH,
|
||||
TERM: process.env.TERM,
|
||||
} satisfies NodeJS.ProcessEnv;
|
||||
import { runDirectImportSmoke } from "../../test/helpers/plugins/direct-smoke.js";
|
||||
|
||||
describe("mattermost bundled api seam", () => {
|
||||
it("loads the narrow channel plugin api in direct smoke", async () => {
|
||||
const { stdout } = await execFileAsync(
|
||||
process.execPath,
|
||||
[
|
||||
"--import",
|
||||
"tsx",
|
||||
"-e",
|
||||
'const mod = await import("./extensions/mattermost/channel-plugin-api.ts"); process.stdout.write(JSON.stringify({keys:Object.keys(mod).sort(), id: mod.mattermostPlugin.id, setupId: mod.mattermostSetupPlugin.id}));',
|
||||
],
|
||||
{
|
||||
cwd: repoRoot,
|
||||
env: importEnv,
|
||||
timeout: 40_000,
|
||||
},
|
||||
const stdout = await runDirectImportSmoke(
|
||||
'const mod = await import("./extensions/mattermost/channel-plugin-api.ts"); process.stdout.write(JSON.stringify({keys:Object.keys(mod).sort(), id: mod.mattermostPlugin.id, setupId: mod.mattermostSetupPlugin.id}));',
|
||||
);
|
||||
|
||||
expect(stdout).toBe(
|
||||
|
||||
25
test/helpers/plugins/direct-smoke.ts
Normal file
25
test/helpers/plugins/direct-smoke.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
|
||||
const execFileAsync = promisify(execFile);
|
||||
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
|
||||
|
||||
const SHARED_IMPORT_ENV = {
|
||||
HOME: process.env.HOME,
|
||||
NODE_OPTIONS: process.env.NODE_OPTIONS,
|
||||
NODE_PATH: process.env.NODE_PATH,
|
||||
PATH: process.env.PATH,
|
||||
TERM: process.env.TERM,
|
||||
} satisfies NodeJS.ProcessEnv;
|
||||
|
||||
export async function runDirectImportSmoke(code: string): Promise<string> {
|
||||
const { stdout } = await execFileAsync(process.execPath, ["--import", "tsx", "-e", code], {
|
||||
cwd: repoRoot,
|
||||
env: SHARED_IMPORT_ENV,
|
||||
timeout: 40_000,
|
||||
});
|
||||
|
||||
return stdout;
|
||||
}
|
||||
Reference in New Issue
Block a user