Skip to content

Commit d398c6a

Browse files
committed
feat(web-host): change logic/message from Loading to Loaded plugins/repl-logic to represent the reality + e2e tests
1 parent 8d0ca76 commit d398c6a

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

packages/web-host/src/components/ReplPage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export const ReplPage = ({ onBackToHome }: ReplPageProps) => {
2626
</div>
2727
{wasm.status === "loading" && <div>Loading...</div>}
2828
{wasm.status === "ready" && <Repl engine={wasm.engine} />}
29-
{wasm.status === "error" && <div>Error</div>}
29+
{wasm.status === "error" && (
30+
<div>An error occurred, please try again.</div>
31+
)}
3032
</div>
3133
);
3234
};

packages/web-host/src/wasm/engine.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,33 @@ async function loadPlugins({
4040
import("./generated/plugin_greet/transpiled/plugin_greet.js"),
4141
import("./generated/plugin_ls/transpiled/plugin_ls.js"),
4242
import("./generated/plugin_cat/transpiled/plugin_cat.js"),
43-
]).then((plugins) => plugins.map((plugin) => plugin.plugin));
44-
45-
// log the plugins names
46-
const pluginsNames = plugins.map((plugin) => plugin.name());
47-
for (const pluginName of pluginsNames) {
48-
addReplHistoryEntry({
49-
stdin: `[Host] Loading plugin: ${pluginName}`,
50-
});
51-
}
43+
]).then((plugins) =>
44+
plugins.map((plugin) => {
45+
addReplHistoryEntry({
46+
stdin: `[Host] Loaded plugin: ${plugin.plugin.name()}`,
47+
});
48+
return plugin.plugin;
49+
}),
50+
);
5251

5352
// set the plugins names in the host state
53+
const pluginsNames = plugins.map((plugin) => plugin.name());
5454
hostStateSetPluginsNames(pluginsNames);
5555

5656
// return the plugins instances
5757
return plugins;
5858
}
5959

60-
async function loadReplLogicGuest(): Promise<HostApi> {
61-
return import("./generated/repl_logic_guest/transpiled/repl_logic_guest.js");
60+
async function loadReplLogicGuest({
61+
addReplHistoryEntry,
62+
}: AddReplHistoryEntryProp): Promise<HostApi> {
63+
const replLogicGuest = await import(
64+
"./generated/repl_logic_guest/transpiled/repl_logic_guest.js"
65+
);
66+
addReplHistoryEntry({
67+
stdin: `[Host] Loaded REPL logic`,
68+
});
69+
return replLogicGuest;
6270
}
6371

6472
export async function prepareEngine({
@@ -75,9 +83,8 @@ export async function prepareEngine({
7583
return;
7684
}
7785
addReplHistoryEntry({ stdin: `[Host] Starting REPL host...` });
78-
addReplHistoryEntry({ stdin: `[Host] Loading REPL logic` });
7986
const [replLogicGuest, plugins] = await Promise.all([
80-
loadReplLogicGuest(),
87+
loadReplLogicGuest({ addReplHistoryEntry }),
8188
loadPlugins({ addReplHistoryEntry }),
8289
]);
8390
const engine = makeEngine();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test("wasm should load", async ({ page }) => {
4+
await page.goto("/#repl");
5+
await expect(page.getByText("[Host] Starting REPL host...")).toBeVisible();
6+
});
7+
8+
test("repl logic should have loaded", async ({ page }) => {
9+
await page.goto("/#repl");
10+
await expect(page.getByText("[Host] Loaded REPL logic")).toBeVisible();
11+
});
12+
13+
test("plugins should have loaded under their names", async ({ page }) => {
14+
const pluginNames = ["echo", "weather", "greet", "ls", "cat"];
15+
await page.goto("/#repl");
16+
for (const pluginName of pluginNames) {
17+
await expect(
18+
page.getByText(`[Host] Loaded plugin: ${pluginName}`),
19+
).toBeVisible();
20+
}
21+
});

0 commit comments

Comments
 (0)