简体   繁体   中英

How to access the editor in vscode tests

I am creating a extension for VSCode that reformats part of the editor text.

How can I make a test for this.

I can't figure how to create a TextEditor inside the test to simulate a opened file.

You should be able to open VS Code for your test file.

See this document: https://code.visualstudio.com/Docs/extensions/testing-extensions

Not sure if you can test against what you are looking for exactly though. You might just be able to check for errors, rather than test "is this UI element here?"

The basic procedure for creating a TextEditor from within a VSCode test is to create a file, open it as a document, and show it. The act of showing yields a TextEditor that you can then manipulate within your test.

API references:

A good example to look at is the test in the VSCode sources for text editing: https://github.com/microsoft/vscode/blob/master/extensions/vscode-api-tests/src/singlefolder-tests/editor.test.ts

Note that that test imports module "utils", which imports "memfs", both in the parent directory. These provide (among other things) "createRandomFile", which is a randomly-named file in an in-memory virtual file system, thereby avoiding disturbing the actual file system.

The above is describing VSCode 1.37.1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM