(writeOutput)
| 14 | import { TestRunner } from "./tester"; |
| 15 | |
| 16 | export async function runCodeMirrorTests(writeOutput) { |
| 17 | const runner = new TestRunner("CodeMirror 6 Editor Tests"); |
| 18 | |
| 19 | function createEditor(doc = "", extensions = []) { |
| 20 | const container = document.createElement("div"); |
| 21 | container.style.width = "500px"; |
| 22 | container.style.height = "300px"; |
| 23 | container.style.backgroundColor = "#1e1e1e"; |
| 24 | document.body.appendChild(container); |
| 25 | |
| 26 | const state = EditorState.create({ |
| 27 | doc, |
| 28 | extensions: [...createBaseExtensions(), ...extensions], |
| 29 | }); |
| 30 | |
| 31 | const view = new EditorView({ state, parent: container }); |
| 32 | return { view, container }; |
| 33 | } |
| 34 | |
| 35 | async function withEditor(test, fn, initialDoc = "", extensions = []) { |
| 36 | let view, container; |
| 37 | |
| 38 | try { |
| 39 | ({ view, container } = createEditor(initialDoc, extensions)); |
| 40 | test.assert(view != null, "EditorView instance should be created"); |
| 41 | await new Promise((resolve) => setTimeout(resolve, 100)); |
| 42 | await fn(view); |
| 43 | await new Promise((resolve) => setTimeout(resolve, 200)); |
| 44 | } finally { |
| 45 | if (view) view.destroy(); |
| 46 | if (container) container.remove(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // ========================================= |
| 51 | // BASIC EDITOR TESTS |
| 52 | // ========================================= |
| 53 | |
| 54 | runner.test("CodeMirror imports available", async (test) => { |
| 55 | test.assert( |
| 56 | typeof EditorView !== "undefined", |
| 57 | "EditorView should be defined", |
| 58 | ); |
| 59 | test.assert( |
| 60 | typeof EditorState !== "undefined", |
| 61 | "EditorState should be defined", |
| 62 | ); |
| 63 | test.assert( |
| 64 | typeof EditorState.create === "function", |
| 65 | "EditorState.create should be a function", |
| 66 | ); |
| 67 | }); |
| 68 | |
| 69 | runner.test("Acode exposes shared CodeMirror modules", async (test) => { |
| 70 | const codemirror = acode.require("codemirror"); |
| 71 | const language = acode.require("@codemirror/language"); |
| 72 | const lezer = acode.require("@lezer/highlight"); |
| 73 | const state = acode.require("@codemirror/state"); |
nothing calls this directly
no test coverage detected