Skip to content

Commit d1381a4

Browse files
committed
mochaもdynamic importに
1 parent 1687131 commit d1381a4

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

app/terminal/page.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"use client";
22
import { Heading } from "@/[docs_id]/markdown";
3-
import "mocha/mocha.js";
43
import "mocha/mocha.css";
54
import { Fragment, useEffect, useRef, useState } from "react";
65
import { useWandbox } from "./wandbox/runtime";
@@ -150,19 +149,23 @@ function MochaTest() {
150149
);
151150
const { writeFile } = useEmbedContext();
152151

153-
const runTest = () => {
154-
setMochaState("running");
152+
const runTest = async () => {
153+
if(typeof window !== "undefined") {
154+
setMochaState("running");
155+
156+
await import("mocha/mocha.js");
155157

156-
mocha.setup("bdd");
158+
mocha.setup("bdd");
157159

158-
for (const lang of Object.keys(runtimeRef.current) as RuntimeLang[]) {
159-
defineTests(lang, runtimeRef, writeFile);
160-
}
160+
for (const lang of Object.keys(runtimeRef.current) as RuntimeLang[]) {
161+
defineTests(lang, runtimeRef, writeFile);
162+
}
161163

162-
const runner = mocha.run();
163-
runner.on("end", () => {
164-
setMochaState("finished");
165-
});
164+
const runner = mocha.run();
165+
runner.on("end", () => {
166+
setMochaState("finished");
167+
});
168+
}
166169
};
167170

168171
return (

0 commit comments

Comments
 (0)