|
| 1 | +--- |
| 2 | +title: Extension for VS Code |
| 3 | +slug: vscode-extension |
| 4 | +hide_table_of_contents: false |
| 5 | +date: 2024-09-26T19:00 |
| 6 | +--- |
| 7 | + |
| 8 | +import Admonition from "@theme/Admonition"; |
| 9 | + |
| 10 | +We have implemented an extension for [VS Code][vscode] for Testplane, which allows you to configure Testplane from scratch, run tests, and conveniently work with the <a href="/ru/docs/v8/command-line/#testplane-repl">REPL mode</a>. |
| 11 | + |
| 12 | +<!-- truncate --> |
| 13 | + |
| 14 | +### Installation |
| 15 | + |
| 16 | +Install the extension from the [VS Code Marketplace][vscode-testplane-marketplace] or from the extensions tab in the VS Code IDE. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +After installation, open VS Code in an empty project and enter in the command panel: |
| 21 | + |
| 22 | +``` |
| 23 | +Install Testplane |
| 24 | +``` |
| 25 | + |
| 26 | + |
| 27 | + |
| 28 | +### Running tests |
| 29 | + |
| 30 | +#### From the sidebar in the testing panel |
| 31 | + |
| 32 | +The testing panel can be opened by clicking on the testing icon in the activity bar. |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +On the left side of the screen, a sidebar displays a tree of all read tests. The tree displays from top to bottom: |
| 37 | + |
| 38 | +- the name of the directory with tests (`testplane-tests`); |
| 39 | +- the name of the test file (`example.testplane.ts`); |
| 40 | +- the name of the suite (`test`). In the example, `describe` from the [Mocha BDD interface][mocha-bdd-interface] is used; |
| 41 | +- the name of the test (`example`). In the example, `it` from the [Mocha BDD interface][mocha-bdd-interface] is used; |
| 42 | +- the name of the browser in which the test will be run (`chrome`). |
| 43 | + |
| 44 | +Each element in the tree has a `Run Test` button. If you click on it at the element: |
| 45 | + |
| 46 | +- for a directory, file, or suite, all child tests will run in all browsers; |
| 47 | +- for a test, the selected test will run in all browsers; |
| 48 | +- for a browser, one test will run in one browser. |
| 49 | + |
| 50 | +Example of running tests from the sidebar: |
| 51 | + |
| 52 | +<video |
| 53 | + src="/video/blog/vscode-extension/run-tests-from-sidebar.mp4" |
| 54 | + width="100%" |
| 55 | + controls="controls" |
| 56 | +> |
| 57 | + The video tag is not supported by your browser. |
| 58 | + <a href="video/blog/vscode-extension/run-tests-from-sidebar.mp4">Download the video</a>. |
| 59 | +</video> |
| 60 | + |
| 61 | +You can also run all tests using the `Run Tests` button. |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +#### From a text editor |
| 66 | + |
| 67 | +If you open a Testplane test in the text editor, a green play button will be displayed next to each suite (`describe`) and test (`it`) for launching them. If you click the left mouse button, the test will run in all browsers, and after execution, the result will be displayed as a status icon for the test's pass/fail status. |
| 68 | +If you right-click the play button, you can run the test in one of the browsers. |
| 69 | + |
| 70 | +Example of running tests from a text editor: |
| 71 | + |
| 72 | +<video |
| 73 | + src="/video/blog/vscode-extension/run-tests-from-editor.mp4" |
| 74 | + width="100%" |
| 75 | + controls="controls" |
| 76 | +> |
| 77 | + The video tag is not supported by your browser. |
| 78 | + <a href="video/blog/vscode-extension/run-tests-from-editor.mp4">Download the video</a>. |
| 79 | +</video> |
| 80 | + |
| 81 | +#### With the `devtools` settings |
| 82 | + |
| 83 | +In the sidebar of the testing panel, there is also a section titled Testplane. Here you can manage settings at runtime. By clicking the `Enable devtools` checkbox and subsequently running tests, browsers will launch using the CDP protocol (regardless of what is specified in the config). You can read more about this mode <a href="/en/docs/v8/guides/how-to-use-cdp/">here</a>.. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +#### With the `REPL` settings |
| 88 | + |
| 89 | +When you click the checkbox `Enable REPL` and subsequently run a test (only one test can be run simultaneously in REPL mode), it will be launched in a special REPL mode. You can read more about this mode <a href="/ru/docs/v8/command-line/#testplane-repl">here</a>. |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +### Filtering tests in the sidebar of the testing panel |
| 94 | + |
| 95 | +To display only tests in a specific browser in the tree, you need to enter the tag `@testplane:browser:your_browser_name` in the filtering input. To get a suggestion, you can simply type `@browser`. You can also use multiple tags there. |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +You can also use the following values in the filter input: |
| 100 | + |
| 101 | +- a string with the name of the tree element (directory/file/suite/test/browser); |
| 102 | +- tag @doc - to display tests from the active file in the text editor; |
| 103 | +- tag @openedFiles - to display tests in all open files in the text editor; |
| 104 | +- tag @executed - to display only running tests; |
| 105 | +- tag @failed - to display only failed tests. |
| 106 | + |
| 107 | +### Restarting the Testplane Environment |
| 108 | + |
| 109 | +You can restart Testplane using the `Refresh Tests` button in the sidebar. In this case, the config and tests will be re-read. This will be useful if you have added a new test to a file (watching test files is not yet supported) or if a critical error has occurred. The test tree is automatically updated when the config changes. |
| 110 | + |
| 111 | + |
| 112 | + |
| 113 | +### Requirements |
| 114 | + |
| 115 | +- the Testplane version must be 8.20.0 or higher (tests will not run with lower versions). |
| 116 | + |
| 117 | +### Current Limitations |
| 118 | + |
| 119 | +- debug and continuous (auto-run) modes are not supported; |
| 120 | +- there is no watching for adding/removing tests and files; |
| 121 | +- using custom Mocha interfaces may lead to incorrect display of icons with the play button for running tests from the text editor. |
| 122 | + |
| 123 | +### Conclusion |
| 124 | + |
| 125 | +This functionality provides our users with new opportunities: |
| 126 | + |
| 127 | +- the ability to run tests directly from the IDE and view the execution results; |
| 128 | +- the ability to quickly switch to devtools and REPL mode; |
| 129 | +- automatically pick up changes made to the Testplane config. |
| 130 | + |
| 131 | +Install the Testplane extension for VS Code and provide us with feedback. If you encounter any issues, please visit the [GitHub issue](https://github.com/gemini-testing/testplane/issues) — we will definitely help you! |
| 132 | + |
| 133 | +[vscode]: https://code.visualstudio.com/ |
| 134 | +[vscode-testplane-marketplace]: https://marketplace.visualstudio.com/items?itemName=gemini-testing.vscode-testplane |
| 135 | +[mocha-bdd-interface]: https://mochajs.org/#bdd |
0 commit comments