|
1 | 1 | import * as vscode from "vscode"; |
2 | 2 | import * as assert from "assert"; |
3 | | -import { exampleWorkspacePath } from "./test-utils"; |
| 3 | +import { exampleWorkspacePath, exampleWorkspaceOutPath, copyFile, wait } from "./test-utils"; |
4 | 4 | import { isQuartoDoc } from "../core/doc"; |
| 5 | +import { extension } from "./extension"; |
5 | 6 |
|
6 | | -suite("Quarto basics", () => { |
7 | | - test("Can open a Quarto document", async () => { |
8 | | - const doc = await vscode.workspace.openTextDocument(exampleWorkspacePath("hello.qmd")); |
| 7 | +const APPROX_TIME_TO_OPEN_VISUAL_EDITOR = 1600; |
| 8 | + |
| 9 | +suite("Quarto basics", function () { |
| 10 | + // Before we run any tests, we should copy any files that get edited in the tests to file under `exampleWorkspaceOutPath` |
| 11 | + suiteSetup(async function () { |
| 12 | + const didCopyFile = await copyFile(exampleWorkspacePath('hello.qmd'), exampleWorkspaceOutPath('hello.qmd')); |
| 13 | + assert.ok(didCopyFile); |
| 14 | + }); |
| 15 | + |
| 16 | + test("Can open a Quarto document", async function () { |
| 17 | + const doc = await vscode.workspace.openTextDocument(exampleWorkspaceOutPath("hello.qmd")); |
9 | 18 | const editor = await vscode.window.showTextDocument(doc); |
| 19 | + |
10 | 20 | assert.strictEqual(editor?.document.languageId, "quarto"); |
11 | 21 | assert.strictEqual(isQuartoDoc(editor?.document), true); |
12 | 22 | }); |
| 23 | + |
| 24 | + // Note: the following tests may be flaky. They rely on waiting estimated amounts of time for commands to complete. |
| 25 | + test("Can edit in visual mode", async function () { |
| 26 | + // don't run this in CI for now because we haven't figured out how to get the LSP to start |
| 27 | + if (process.env['CI']) this.skip(); |
| 28 | + |
| 29 | + const doc = await vscode.workspace.openTextDocument(exampleWorkspaceOutPath("hello.qmd")); |
| 30 | + const editor = await vscode.window.showTextDocument(doc); |
| 31 | + |
| 32 | + // manually confirm visual mode so dialogue pop-up doesn't show because dialogues cause test errors |
| 33 | + // and switch to visual editor |
| 34 | + await vscode.commands.executeCommand("quarto.test_setkVisualModeConfirmedTrue"); |
| 35 | + await wait(300); // It seems necessary to wait around 300ms for this command to be done. |
| 36 | + await vscode.commands.executeCommand("quarto.editInVisualMode"); |
| 37 | + await wait(APPROX_TIME_TO_OPEN_VISUAL_EDITOR); |
| 38 | + |
| 39 | + assert.ok(await vscode.commands.executeCommand("quarto.test_isInVisualEditor")); |
| 40 | + }); |
| 41 | + // Note: this test runs after the previous test, so `hello.qmd` has already been touched by the previous |
| 42 | + // test. That's okay for this test, but could cause issues if you expect a qmd to look how it |
| 43 | + // does in `/examples`. |
| 44 | + test("Roundtrip doesn't change hello.qmd", async function () { |
| 45 | + // don't run this in CI for now because we haven't figured out how to get the LSP to start |
| 46 | + if (process.env['CI']) this.skip(); |
| 47 | + |
| 48 | + const doc = await vscode.workspace.openTextDocument(exampleWorkspaceOutPath("hello.qmd")); |
| 49 | + const editor = await vscode.window.showTextDocument(doc); |
| 50 | + |
| 51 | + const docTextBefore = doc.getText(); |
| 52 | + |
| 53 | + // switch to visual editor and back |
| 54 | + await vscode.commands.executeCommand("quarto.test_setkVisualModeConfirmedTrue"); |
| 55 | + await wait(300); |
| 56 | + await vscode.commands.executeCommand("quarto.editInVisualMode"); |
| 57 | + await wait(APPROX_TIME_TO_OPEN_VISUAL_EDITOR); |
| 58 | + await vscode.commands.executeCommand("quarto.editInSourceMode"); |
| 59 | + await wait(300); |
| 60 | + |
| 61 | + const docTextAfter = doc.getText(); |
| 62 | + assert.ok(docTextBefore === docTextAfter); |
| 63 | + }); |
13 | 64 | }); |
0 commit comments