|
1 | 1 | "use client"; |
2 | 2 | import { Heading } from "@/[docs_id]/markdown"; |
3 | | -import "mocha/mocha.js"; |
4 | 3 | import "mocha/mocha.css"; |
5 | 4 | import { Fragment, useEffect, useRef, useState } from "react"; |
6 | 5 | import { useWandbox } from "./wandbox/runtime"; |
@@ -150,19 +149,23 @@ function MochaTest() { |
150 | 149 | ); |
151 | 150 | const { writeFile } = useEmbedContext(); |
152 | 151 |
|
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"); |
155 | 157 |
|
156 | | - mocha.setup("bdd"); |
| 158 | + mocha.setup("bdd"); |
157 | 159 |
|
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 | + } |
161 | 163 |
|
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 | + } |
166 | 169 | }; |
167 | 170 |
|
168 | 171 | return ( |
|
0 commit comments