|
1 | 1 | "use client"; |
2 | 2 |
|
3 | | -import { Heading } from "@/markdown/heading"; |
4 | 3 | import "mocha/mocha.css"; |
5 | | -import { Fragment, useEffect, useRef, useState } from "react"; |
6 | | -import { langConstants, RuntimeLang } from "@my-code/runtime/languages"; |
7 | | -import { ReplTerminal } from "./repl"; |
8 | | -import { EditorComponent } from "./editor"; |
9 | | -import { ExecFile } from "./exec"; |
10 | | -import { useTerminal } from "./terminal"; |
| 4 | +import { useEffect, useRef, useState } from "react"; |
| 5 | +import { RuntimeLang } from "@my-code/runtime/languages"; |
11 | 6 | import { |
12 | 7 | RUNTIME_TIMEOUTS, |
13 | 8 | waitForRuntimeReady, |
14 | 9 | } from "@my-code/runtime/tests/utils"; |
15 | 10 | import { replTests } from "@my-code/runtime/tests/repl"; |
16 | 11 | import { fileExecutionTests } from "@my-code/runtime/tests/fileExecution"; |
17 | 12 | import { useRuntimeAll } from "@my-code/runtime/context"; |
18 | | -import { captureException } from "@sentry/nextjs"; |
19 | | - |
20 | | -import { sampleConfig, SampleConfig } from "./sampleConfig"; |
21 | 13 | import { DaisyInfoIcon } from "@/daisyAlertIcon"; |
22 | | - |
23 | | -export default function RuntimeTestPage() { |
24 | | - return ( |
25 | | - <div className="p-4 mx-auto w-full max-w-docs"> |
26 | | - <Heading level={1}>Runtime Test Page</Heading> |
27 | | - |
28 | | - <Heading level={2}>REPLとコード実行のサンプル</Heading> |
29 | | - {/* name of each tab group should be unique */} |
30 | | - <div className="tabs tabs-box"> |
31 | | - {Object.entries(sampleConfig).map(([lang, config]) => ( |
32 | | - <Fragment key={lang}> |
33 | | - <input |
34 | | - type="radio" |
35 | | - name="runtime-sample-tabs" |
36 | | - className="tab" |
37 | | - aria-label={lang} |
38 | | - /> |
39 | | - <div className="tab-content border-base-300 bg-base-100"> |
40 | | - <RuntimeSample lang={lang as RuntimeLang} config={config} /> |
41 | | - </div> |
42 | | - </Fragment> |
43 | | - ))} |
44 | | - </div> |
45 | | - |
46 | | - <Heading level={2}>Xterm.js Colors</Heading> |
47 | | - <AnsiColorSample /> |
48 | | - |
49 | | - <button |
50 | | - className="btn mt-4" |
51 | | - onClick={() => { |
52 | | - throw new Error("Sentry Test Error"); |
53 | | - }} |
54 | | - > |
55 | | - Sentry Test Error |
56 | | - </button> |
57 | | - |
58 | | - <Heading level={2}>自動テスト</Heading> |
59 | | - <MochaTest /> |
60 | | - </div> |
61 | | - ); |
62 | | -} |
63 | | - |
64 | | -function RuntimeSample({ |
65 | | - lang, |
66 | | - config, |
67 | | -}: { |
68 | | - lang: RuntimeLang; |
69 | | - config: SampleConfig; |
70 | | -}) { |
71 | | - return ( |
72 | | - <div className="flex flex-col"> |
73 | | - {config.repl && ( |
74 | | - <ReplTerminal |
75 | | - terminalId="1" |
76 | | - language={langConstants(lang)} |
77 | | - initContent={config.replInitContent} |
78 | | - /> |
79 | | - )} |
80 | | - {config.editor && |
81 | | - Object.entries(config.editor).map(([filename, initContent]) => ( |
82 | | - <EditorComponent |
83 | | - key={filename} |
84 | | - language={langConstants(lang)} |
85 | | - filename={filename} |
86 | | - initContent={initContent} |
87 | | - /> |
88 | | - ))} |
89 | | - {config.exec && ( |
90 | | - <ExecFile |
91 | | - filenames={config.exec} |
92 | | - language={langConstants(lang)} |
93 | | - content="" |
94 | | - /> |
95 | | - )} |
96 | | - {config.readonlyFiles?.map((filename) => ( |
97 | | - <EditorComponent |
98 | | - key={filename} |
99 | | - language={langConstants(lang)} |
100 | | - filename={filename} |
101 | | - initContent="" |
102 | | - readonly |
103 | | - /> |
104 | | - ))} |
105 | | - </div> |
106 | | - ); |
107 | | -} |
108 | | - |
109 | | -function AnsiColorSample() { |
110 | | - const { terminalRef, terminalInstanceRef } = useTerminal({ |
111 | | - getRows: () => 6, |
112 | | - onReady: () => { |
113 | | - for (let i = 0; i <= 7; i++) { |
114 | | - terminalInstanceRef.current!.write(`\x1b[0;${30 + i}m${30 + i}`); |
115 | | - } |
116 | | - terminalInstanceRef.current!.write("\x1b[0m\n"); |
117 | | - terminalInstanceRef.current!.write("\x1b[1m1;"); |
118 | | - for (let i = 0; i <= 7; i++) { |
119 | | - terminalInstanceRef.current!.write(`\x1b[1;${30 + i}m${30 + i}`); |
120 | | - } |
121 | | - terminalInstanceRef.current!.write("\x1b[0m\n"); |
122 | | - for (let i = 0; i <= 7; i++) { |
123 | | - terminalInstanceRef.current!.write(`\x1b[0;${90 + i}m${90 + i}`); |
124 | | - } |
125 | | - terminalInstanceRef.current!.write("\x1b[0m\n"); |
126 | | - terminalInstanceRef.current!.write("\x1b[1m1;"); |
127 | | - for (let i = 0; i <= 7; i++) { |
128 | | - terminalInstanceRef.current!.write(`\x1b[1;${90 + i}m${90 + i}`); |
129 | | - } |
130 | | - terminalInstanceRef.current!.write("\x1b[0m\n"); |
131 | | - for (let i = 0; i <= 7; i++) { |
132 | | - terminalInstanceRef.current!.write(`\x1b[0;${40 + i}m${40 + i}`); |
133 | | - } |
134 | | - terminalInstanceRef.current!.write("\x1b[0m\n"); |
135 | | - for (let i = 0; i <= 7; i++) { |
136 | | - terminalInstanceRef.current!.write(`\x1b[0;${100 + i}m${100 + i}`); |
137 | | - } |
138 | | - }, |
139 | | - }); |
140 | | - return ( |
141 | | - <div className="bg-base-300 border border-accent border-2 shadow-md m-2 p-4 pr-1 rounded-box relative h-max"> |
142 | | - <div ref={terminalRef} /> |
143 | | - </div> |
144 | | - ); |
145 | | -} |
| 14 | +import { captureException } from "@sentry/nextjs"; |
146 | 15 |
|
147 | 16 | function handleRuntimeError(error: unknown) { |
148 | 17 | captureException(error); |
149 | 18 | } |
150 | 19 |
|
151 | | -function MochaTest() { |
| 20 | +export function MochaTest() { |
152 | 21 | const runtimeAll = useRuntimeAll(); |
153 | 22 | const runtimeRef = useRef(runtimeAll); |
154 | 23 | for (const lang of Object.keys(runtimeAll) as RuntimeLang[]) { |
|
0 commit comments