<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: MaxKless</title>
    <description>The latest articles on DEV Community by MaxKless (@maxkless).</description>
    <link>https://dev.to/maxkless</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F932639%2Fdffd3a01-2f51-4e6b-8a04-9d0f3338b9db.jpeg</url>
      <title>DEV Community: MaxKless</title>
      <link>https://dev.to/maxkless</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/maxkless"/>
    <language>en</language>
    <item>
      <title>Nx Console gets Lit</title>
      <dc:creator>MaxKless</dc:creator>
      <pubDate>Fri, 30 Jun 2023 07:46:51 +0000</pubDate>
      <link>https://dev.to/nx/nx-console-gets-lit-44m7</link>
      <guid>https://dev.to/nx/nx-console-gets-lit-44m7</guid>
      <description>&lt;p&gt;Over the last few weeks, we rebuilt one of Nx Console’s most liked features from the ground up: The Generate UI. It looks better, loads faster, and preliminary research shows using it makes you happier, too ;) &lt;/p&gt;

&lt;p&gt;You can use it today by installing the latest version of Nx Console for VSCode and JetBrains IDEs! 🎉🎉🎉&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console"&gt;Nx Console on the VSCode Marketplace&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://plugins.jetbrains.com/plugin/21060-nx-console"&gt;Nx Console on the JetBrains Marketplace&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you’re curious to learn more about the rewrite and the motivations behind it, this is the blog post for you! We’ll touch on these topics and more: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why did we choose to rewrite?&lt;/li&gt;
&lt;li&gt;What’s Lit and why did we use it over Angular?&lt;/li&gt;
&lt;li&gt;How did the rewrite go and what Lit features were important for us?&lt;/li&gt;
&lt;li&gt;What does the performance look like before and after?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you prefer a video format, check out our Youtube video 👇&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/p455D4W7330"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Background: Why Migrate from Angular to Lit?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  A Short History of Nx Console
&lt;/h3&gt;

&lt;p&gt;Let’s go back in time: Nx Console has been around for a while. &lt;a href="https://blog.nrwl.io/announcing-the-first-stable-release-of-angular-console-the-ui-for-the-angular-cli-bb19093a92d4"&gt;It first launched in 2018&lt;/a&gt; - then called Angular Console - as a standalone Electron app which let you run Angular schematics and builders from a graphical interface. Of course, it was built with Angular and looked something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9RPYMu_S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07kdcaek7hrcwmqbcwgs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9RPYMu_S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/07kdcaek7hrcwmqbcwgs.png" alt="Screenshot of the original Angular Console electron app" width="800" height="817"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In 2019, &lt;a href="https://blog.nrwl.io/brand-new-ui-custom-vscode-task-support-more-in-angular-console-9-0-5e4d3a109fb9"&gt;it was ported to a VSCode extension&lt;/a&gt; with the now familiar UI and support for the standalone app was dropped.&lt;/p&gt;

&lt;p&gt;In 2020, support for the entire Nx ecosystem was added, it was renamed to Nx Console and an amazing transformation began: Today, Nx Console is much more than just a single form - it tightly integrates Nx into your IDE, gives you the overview of your projects that you need and puts your task-running just a click away.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rewriting in Lit
&lt;/h3&gt;

&lt;p&gt;This evolution brought significant improvements to the usability of Nx Console and the value we could provide to developers, but not without presenting its own set of challenges. Inevitably, the codebase grew complex and convoluted over time - the context in which it ran changed, the scope of the product changed, yet the technology remained the same. Adding small features or fixing bugs became increasingly time consuming, and every PR compounded the problem.&lt;/p&gt;

&lt;p&gt;The UI looked somewhat outdated and had been built with only VSCode in mind - which became painfully obvious when support for JetBrains IDEs was added. While the web-based nature of the Generate UI allowed us to reuse the code in the new environment, the design looked out of place. &lt;/p&gt;

&lt;p&gt;In addition, we started questioning our usage of Angular. Angular is a great framework for building web apps, and in the original context of Angular Console, it made a lot of sense: A tool built by and for Angular engineers - of course it’s written in Angular. But things changed, and Angular started to feel overkill for what we needed. Angular has a huge number of features right out of the box. But for our simple form, we didn’t need routing, http requests or modules to organize our code. The amount of boilerplate and overhead Angular introduces is significant.&lt;/p&gt;

&lt;p&gt;So, ultimately, &lt;strong&gt;we decided to pull the plug and rewrite the entire thing in &lt;a href="https://lit.dev/"&gt;Lit&lt;/a&gt;.&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Lit is a lightweight framework built on top of web components and “adds just what you need to be happy and productive: reactivity, declarative templates and a handful of thoughtful features to reduce boilerplate and make your job easier” (taken from their docs). We had used it before to &lt;a href="https://blog.nrwl.io/nx-console-meets-nx-cloud-d45dc099dc5d"&gt;build the Nx Cloud view&lt;/a&gt; and were happy with the simple setup and great DX. So the decision to reuse it here was an easy one, since it allowed us to reuse code, build tooling and expertise. The rewrite also gave us the opportunity to improve the design for both supported IDEs and give the entire UI a clean, new coat of paint.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rXZjDFJF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00f7p77texddqmufh6bt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rXZjDFJF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/00f7p77texddqmufh6bt.png" alt="Screenshot of the new, reworked generate ui" width="800" height="507"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Before I dive deeper into specifics, let’s have a look at the general architecture of Nx Console first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Nx Console Architectural Overview
&lt;/h2&gt;

&lt;p&gt;Nx Console is composed of 3 core parts: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;nxls&lt;/strong&gt; is a language server based on the &lt;a href="https://microsoft.github.io/language-server-protocol/"&gt;Language Server Protocol (LSP)&lt;/a&gt; and acts as the “brain” of Nx Console. It analyzes your Nx workspace and provides information on it, including code completion and more.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;Generate UI&lt;/strong&gt; is the form-based view for running Nx generators.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;platform-specific wrappers&lt;/strong&gt;. These are written in Typescript and Kotlin and connect the rest of Nx Console to IDE-specific APIs. Having the other parts separate greatly reduces the amount of duplicated code we have to write in order to support multiple IDEs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This architecture’s modularity meant we could quickly switch out the Generate UI for a new version without significantly impacting the rest of the codebase - only the parts that actually render the UI and communicate with it had to be adjusted slightly. It also allowed us to ensure backward compatibility: the old generate UI is still available via a feature toggle in the settings. &lt;/p&gt;

&lt;p&gt;If you want to dive deeper, there are many more resources on the architecture of Nx Console and how it’s built: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://blog.nrwl.io/expanding-nx-console-to-jetbrains-ides-8a5b80fff2d7"&gt;In-depth blog post about expanding to JetBrains IDEs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=xUTm6GDqwJM"&gt;Accompanying Youtube video by Zack DeRose&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.youtube.com/watch?v=3C_9g9kt2KM"&gt;The Power of Nx Console - talk by Jon Cammisuli&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Migrating to Lit: Step by Step
&lt;/h2&gt;

&lt;p&gt;To rebuild our UI, we first needed a new Lit app to work on. While there’s no native Nx plugin for Lit, generating the code we need was still very straightforward:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;nx generate @nx/web:app --name generate-ui-v2&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This generates an entire project for us, with a &lt;code&gt;tsconfig.json&lt;/code&gt; , &lt;code&gt;index.html&lt;/code&gt; , &lt;code&gt;main.ts&lt;/code&gt; and a &lt;code&gt;project.json&lt;/code&gt; , where our Nx-specific config lives. &lt;/p&gt;

&lt;p&gt;I also installed a couple of dependencies: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;@nx/esbuild&lt;/code&gt; plugin because I like fast build times 🏎️&lt;/li&gt;
&lt;li&gt;TailwindCSS because I don’t like writing CSS 🤫&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;@vscode/webview-ui-toolkit&lt;/code&gt; because it does all of the VSCode work for me 🤖&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is really where Nx shines, because it allows you to take these tools and quickly patch them together and build a pipeline that does exactly what you need. And it also allows you to think about your workspace visually. This is what this is what my task graph for building the Lit app ultimately looks like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rkrC2AHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jg9i5j89zjq6u57pch93.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rkrC2AHx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jg9i5j89zjq6u57pch93.png" alt="Nx task graph containing three nodes" width="800" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see three build steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;generate-ui-v2:_build&lt;/code&gt; uses esbuild to bundle my Lit components written in Typescript and spits out a &lt;code&gt;main.js&lt;/code&gt; file&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;generate-ui-v2:extract-dependencies&lt;/code&gt; copies the third party assets we need into the &lt;code&gt;dist&lt;/code&gt; folder. Right now it’s just codicons &lt;code&gt;.css&lt;/code&gt; and &lt;code&gt;.ttf&lt;/code&gt; files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;generate-ui-v2:build&lt;/code&gt; finally runs tailwind over the bundled code. This could also be done with &lt;code&gt;postCss&lt;/code&gt; or a custom &lt;code&gt;esbuild&lt;/code&gt; plugin but running tailwind directly is the easier, so why complicate things?&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 There’s different ways to generate this visualisation for your own workspaces:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In VSCode, use the Nx Project View or the &lt;code&gt;Nx: Focus task in Graph&lt;/code&gt; action&lt;/li&gt;
&lt;li&gt;In JetBrains IDEs, use the Nx Toolwindow or context menus&lt;/li&gt;
&lt;li&gt;In the command line, run &lt;code&gt;nx build {{your project}} --graph&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;In the bigger context of Nx Console, here’s what happens when you build the VSCode extension&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--apXb3UxU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpjhx5iu6ncsb6g2j629.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--apXb3UxU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cpjhx5iu6ncsb6g2j629.png" alt="Nx task graph for building the VSCode extension, containing more nodes" width="800" height="220"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can see that we’re still building both the new &amp;amp; old generate UI as well as the Nxls and the Nx Cloud webview before combining them all into one VSCode extension artifact.&lt;/p&gt;

&lt;h3&gt;
  
  
  Building the Form
&lt;/h3&gt;

&lt;p&gt;Lit is a very small library that provides useful abstractions over browser-native features like web components and messages. Here’s what a simple Lit component, written with Typescript, looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// main.ts&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;customElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root-element&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Root&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;LitElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="s2"&gt;`&amp;lt;p&amp;gt; Hello World &amp;lt;/p&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;//index.html&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="na"&gt;DOCTYPE&lt;/span&gt; &lt;span class="na"&gt;html&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"module"&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"main.js"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;root&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;root&lt;/span&gt;&lt;span class="err"&gt;-&lt;/span&gt;&lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you need to pass information up the DOM, you use normal events and you can set properties to send information to descendants. Check out the &lt;a href="https://lit.dev/docs/components/rendering/"&gt;Lit Docs&lt;/a&gt; to learn more about how the &lt;code&gt;render()&lt;/code&gt; method works, how to leverage reactivity, the shadow DOM and so much more.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 All code samples in this section have been adapted for brevity and clarity. So you won’t find this exact code anywhere, but it demonstrates the concepts well&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Communicating with the IDE - using Reactive Controllers
&lt;/h3&gt;

&lt;p&gt;To communicate with the host IDE, we were able to reuse almost all the logic from the previous UI (for more details, see &lt;a href="https://blog.nrwl.io/expanding-nx-console-to-jetbrains-ides-8a5b80fff2d7#d151"&gt;Communicating with IntelliJ&lt;/a&gt; from the last blog post). Instead of a service that exposes observables that our component can consume, we used a &lt;a href="https://lit.dev/docs/composition/controllers/"&gt;Reactive Controller&lt;/a&gt;. Controllers are a neat feature of Lit - they hook into a component and can request DOM updates on their behalf. This eliminates the need for observable streams and subscriptions while keeping the communication code self-contained. Look at this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// main.ts&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;customElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;root-element&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;Root&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;LitElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;icc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;IdeCommunicationController&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;IdeCommunicationController&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;icc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;generatorSchema&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// ide-communication-controller.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;IdeCommunicationController&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;ReactiveController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;generatorSchema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;GeneratorSchema&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ReactiveControllerHost&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

    &lt;span class="c1"&gt;// ...&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;handleMessageFromIde&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;InputMessage&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ...&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;generatorSchema&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;requestUpdate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that &lt;code&gt;root-element&lt;/code&gt; can really just deal with rendering the form contents, delegating communicating with the IDE and when to update the DOM to the controller.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rendering the form fields - using Mixins
&lt;/h3&gt;

&lt;p&gt;The core part of the UI is the form. We built all kinds of inputs: text fields, checkboxes, (multi-) select boxes and array fields. While those each have unique implementations, displaying them is also going to take a lot of repeated code. Every fields needs a label and description. Every field needs to know about its validation state, how dispatch change events and what aria attributes to set. In order to keep this code clean and DRY, we used &lt;a href="https://lit.dev/docs/composition/mixins/"&gt;Class Mixins&lt;/a&gt;. Mixins aren’t really a Lit-specific feature, but I don’t see them used much in other frameworks. A mixin is essentially a factory that takes a class and returns another, modified class. Check out this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// field-mixin.ts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Field&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;superClass&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;superClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// we can define (reactive) properties that every field is going to need&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;property&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Option&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;fieldId&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;-field`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// we can define methods that should be available to all fields&lt;/span&gt;
    &lt;span class="nx"&gt;dispatchValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// field-wrapper-mixin.ts&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;FieldWrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;superClass&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;superClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// we can define a render() method so that fields are all rendered the same&lt;/span&gt;
    &lt;span class="k"&gt;protected&lt;/span&gt; &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="s2"&gt;`
            &amp;lt;label for="&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fieldId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/label&amp;gt;
            &amp;lt;p&amp;gt; &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;description&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &amp;lt;/p&amp;gt;
            &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;renderField&lt;/span&gt;&lt;span class="p"&gt;()}&lt;/span&gt;&lt;span class="s2"&gt;
        `&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// input-field.ts&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;customElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input-field&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;InputField&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;FieldWrapper&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;Field&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;LitElement&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;renderField&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="s2"&gt;`
            &amp;lt;input 
                id="&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fieldId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"
                @input="&lt;/span&gt;&lt;span class="p"&gt;${(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dispatchValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="s2"&gt;"
            /&amp;gt;
        `&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see that each component and mixin deals with a specific subset of the overall logic, keeping our code cleanly separated and reusable. A checkbox, for example, is a special case because it’s layout on the page is slightly different - no problem, we simply wrote a &lt;code&gt;CheckboxWrapper&lt;/code&gt; with some modifications without having to worry about changing the checkbox logic itself. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Properly typing mixins is complicated so I left that part out. Refer to &lt;a href="https://lit.dev/docs/composition/mixins/#mixins-in-typescript"&gt;Mixins in Typescript&lt;/a&gt; to learn more or &lt;a href="https://github.com/nrwl/nx-console"&gt;check out our source code on GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Injecting Services &amp;amp; Data - Lit Context
&lt;/h3&gt;

&lt;p&gt;If you’re coming from the Angular world, you probably appreciate the great dependency injection (DI) mechanism they have. You can centrally define some services and reuse them across your app, without thinking about passing on props from component to component - the DI system takes care of it. Lit provides something similar via the [&lt;code&gt;@lit-labs/context]&lt;/code&gt;(&lt;a href="https://lit.dev/docs/data/context/"&gt;https://lit.dev/docs/data/context/&lt;/a&gt;) package. It’s based on the &lt;a href="https://github.com/webcomponents-cg/community-protocols/blob/main/proposals/context.md"&gt;Context Community Protocol&lt;/a&gt; and similar to React’s context API. &lt;/p&gt;

&lt;p&gt;Under the hood, it still works with normal browser events, but it abstracts it away from you so you can easily share data and services across your app. &lt;/p&gt;

&lt;p&gt;The Generate UI is rendered in both VSCode and JetBrains IDEs. In order to look appropriate, components need to know which environment they’re in and adjust styling accordingly. Instead of passing this information from component to component, we can make it available contextually! And with a proper mixin, reading the editor context only has to be implemented once, too.&lt;/p&gt;

&lt;p&gt;Have a look at the following example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// editor-context.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;editorContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;createContext&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vscode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;intellij&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nb"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;editor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;EditorContext&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;superClass&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;superClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;consume&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;editorContext&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;state&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;editor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vscode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;intellij&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// ide-communication-controller.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;IdeCommunicationController&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;ReactiveController&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;ReactiveElement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;editor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;isVscode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vscode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;intellij&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// provide the context to all DOM children of the host element&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ContextProvider&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;host&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;editorContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;editor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// some-component.ts&lt;/span&gt;
&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;customElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;some-component&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;SomeComponent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;EditorContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;LitElement&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;render&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="s2"&gt;`&amp;lt;p&amp;gt; I am rendered in &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;editor&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/p&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  VSCode Webview UI Toolkit
&lt;/h3&gt;

&lt;p&gt;As we mentioned above, a big part of why we rewrote the UI is that it looked quite out of place in JetBrains IDEs. It was still useful, of course, but it’s important to make sure the form &lt;em&gt;feels&lt;/em&gt; right. &lt;/p&gt;

&lt;p&gt;In VSCode, this is very easy to achieve, thanks to the &lt;a href="https://github.com/microsoft/vscode-webview-ui-toolkit"&gt;VSCode Webview UI Toolkit&lt;/a&gt;. It’s a set of web components, provided by Microsoft, that are designed to look good and be used in VSCode webviews. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j12RT99A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ubl13xdicyrmfysb68gb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j12RT99A--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ubl13xdicyrmfysb68gb.png" alt="Sample image of the VSCode Webview UI Toolkit showing the different components it provides" width="800" height="534"&gt;&lt;/a&gt;&lt;br&gt;
Using it, you get the native look, a11y, and theme-aware styling for free! Thanks to everyone who built it, it’s a huge help!&lt;/p&gt;

&lt;h3&gt;
  
  
  E2E Testing with Cypress
&lt;/h3&gt;

&lt;p&gt;One big upside of using a webview is the huge Javascript ecosystem is available to you! To make sure that no regressions are introduced later on, we use &lt;a href="https://www.cypress.io/"&gt;Cypress&lt;/a&gt;. We can mock the editor communication and provide different schemas, make sure the form is rendered correctly and the right messages are sent back to the IDE. &lt;/p&gt;

&lt;p&gt;While there’s no particular Lit integration for Cypress, the tool itself is framework agnostic so it still works perfectly fine. Using the &lt;a href="https://nx.dev/packages/cypress"&gt;&lt;code&gt;@nx/cypress&lt;/code&gt;&lt;/a&gt; executors did most of the work for us so setup was pretty quick too.&lt;/p&gt;

&lt;h2&gt;
  
  
  Results: Comparing Performance
&lt;/h2&gt;

&lt;p&gt;There’s a number of different aspects to performance we can compare between the two implementations. The biggest one by far is not really quantifiable: The maintainability and looks of the new UI. In my opinion, it looks a lot fresher and more native in both environments. We got rid of a lot of legacy code and the new version is easier to reason about and work with. &lt;/p&gt;

&lt;p&gt;But there are thing we can measure, so let’s talk numbers!&lt;/p&gt;

&lt;h3&gt;
  
  
  Startup Time
&lt;/h3&gt;

&lt;p&gt;It takes time to bootstrap a large framework like Angular, so skipping that, the UI should load quicker than before.&lt;/p&gt;

&lt;p&gt;We measured the median time it took to render all options of the &lt;code&gt;@nx/angular:application&lt;/code&gt; generator in both VSCode and IntelliJ. You can see that the results are pretty clear-cut, even though they are not hugely impactful.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Old UI (Angular)&lt;/th&gt;
&lt;th&gt;New UI (Lit)&lt;/th&gt;
&lt;th&gt;Speedup&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;VSCode&lt;/td&gt;
&lt;td&gt;65 ms&lt;/td&gt;
&lt;td&gt;39 ms&lt;/td&gt;
&lt;td&gt;~ 1.7x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;IntelliJ&lt;/td&gt;
&lt;td&gt;189 ms&lt;/td&gt;
&lt;td&gt;122 ms&lt;/td&gt;
&lt;td&gt;~ 1.5x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h3&gt;
  
  
  Bundle Size
&lt;/h3&gt;

&lt;p&gt;As mentioned earlier, Angular comes with a lot more features out-of-the-box than Lit, so it would make sense that the built bundle will be bigger. &lt;/p&gt;

&lt;p&gt;We were able to reduce the bundle size (w/o compression) from about 733 kB to 282 kB, which comes out to about a 2,6x decrease. Unlike a website, where the bundle needs to be shipped to users when they load a page, Nx Console users only need to download it once when installing the plugin. This means we’re not affected by network speeds after installation, which makes the bundle size less critical. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;💡 Because of a misconfiguration from a few Angular versions ago, the bundle size that we reported in &lt;a href="https://twitter.com/MaxKless/status/1671095858182381569"&gt;this tweet&lt;/a&gt; was overly bloated. We corrected it, but Lit still came out ahead in terms of size and rendering times.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Build Time
&lt;/h3&gt;

&lt;p&gt;While it might not be important to users of Nx Console, the time it takes to build the project makes a difference to us developers. &lt;/p&gt;

&lt;p&gt;Since Lit is just javascript files that don’t require a custom compiler or build tooling, we decided to use &lt;a href="https://esbuild.github.io/"&gt;&lt;code&gt;esbuild&lt;/code&gt;&lt;/a&gt;  (via &lt;code&gt;@nx/esbuild&lt;/code&gt;), which is written in Go and extremely fast. On the other hand, the old UI used the &lt;code&gt;@angular-builders/custom-webpack:browser&lt;/code&gt; builder, which uses webpack under the hood. &lt;/p&gt;

&lt;p&gt;We went from about 3.5 seconds to less than 2 seconds of build time, which is less of an improvement than we expected. Since we also have to run tailwind over our files, some of that additional &lt;code&gt;esbuild&lt;/code&gt; speed seems to be relativized.&lt;/p&gt;

&lt;h2&gt;
  
  
  Looking Ahead
&lt;/h2&gt;

&lt;p&gt;Rebuilding the UI has paved the road to reduce a lot of the maintenance burden of Nx Console. It will allow us to move even quicker on building new features to provide the best developer experience possible for you. &lt;/p&gt;

&lt;p&gt;Specifically, the updated architecture enabled us to build a (still secret and WIP) plugin feature for Nx Console. Just like Nx, there are always going to be things that are unique to &lt;em&gt;your&lt;/em&gt; workspace. We want to make it easy for you to extend and modify Nx Console in ways that help you make the most of using it. &lt;/p&gt;

&lt;p&gt;So keep your eyes peeled for announcements and let us know via GitHub or Twitter if you have any ideas! We’d love to chat. &lt;/p&gt;

&lt;h2&gt;
  
  
  One more thing!
&lt;/h2&gt;

&lt;p&gt;Nx Console is a tool by developers for developers and there’s one thing we love - keyboard shortcuts. So of course we had to build some in. In addition to being keyboard-friendly and tabbable, you can do the following: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Cmd/Ctrl + Enter&lt;/code&gt; to run the generator&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Cmd/Ctrl + Shift + Enter&lt;/code&gt; to start a dry run&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Cmd/Ctrl + S&lt;/code&gt; to focus the search bar and look for a specific option. Just &lt;code&gt;tab&lt;/code&gt; to get back to the form&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the prettier UI and better performance haven’t convinced you, this surely will! 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn more
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🎮 &lt;a href="https://github.com/nrwl/nx-console"&gt;Nx Console GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🚀 &lt;a href="https://plugins.jetbrains.com/plugin/21060-nx-console"&gt;Nx Console JetBrains plugin&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🤖 &lt;a href="https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console"&gt;Nx Console VSCode extension&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🧠 &lt;a href="https://nx.dev/"&gt;Nx Docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;👩‍💻 &lt;a href="https://github.com/nrwl/nx"&gt;Nx GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💬 &lt;a href="https://go.nrwl.io/join-slack"&gt;Nx Community Slack&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/@nxdevtools"&gt;Nx Youtube Channel&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, if you liked this, click the 👏 and make sure to follow &lt;a href="https://twitter.com/MaxKless"&gt;Max&lt;/a&gt; and &lt;a href="https://twitter.com/nxdevtools"&gt;Nx&lt;/a&gt; on Twitter for more!&lt;/p&gt;

</description>
      <category>nx</category>
      <category>javascript</category>
      <category>lit</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Battle-Testing Nx Console with E2E Tests</title>
      <dc:creator>MaxKless</dc:creator>
      <pubDate>Wed, 16 Nov 2022 13:03:47 +0000</pubDate>
      <link>https://dev.to/nx/battle-testing-nx-console-with-e2e-tests-5b9</link>
      <guid>https://dev.to/nx/battle-testing-nx-console-with-e2e-tests-5b9</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa53rky3ob957x1pzz8qk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa53rky3ob957x1pzz8qk.png" alt="Nx Console Banner"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nx Console is the UI for Nx &amp;amp; Lerna. It’s available as a VSCode extension (and more IDEs coming soon!) and with it, you get powerful features like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;autocomplete for Nx config files,&lt;/li&gt;
&lt;li&gt;exploration of generators (and schematics) in a form-based view,&lt;/li&gt;
&lt;li&gt;context-aware visualisation of the Nx dependency graph right in your IDE&lt;/li&gt;
&lt;li&gt;and many more DX improvements throughout the extension!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Nx Console project started many years ago and went through various iterations. From a small, standalone client for angular schematics to what it is today: A fully-integrated tool to help you be more productive while developing with Nx. &lt;/p&gt;

&lt;p&gt;And folks like it: We passed a million installs this year! 🎉&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1518620884570820608-948" src="https://platform.twitter.com/embed/Tweet.html?id=1518620884570820608"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1518620884570820608-948');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1518620884570820608&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;Of course we as maintainers need to make sure that all of our features work when we make a PR or release a new version. &lt;/p&gt;

&lt;p&gt;This used to mean manually clicking through features in different sample workspaces - as you can imagine, this quickly became tedious as well as unreliable. Keep in mind that Nx Console works not just for Nx but also for Lerna and Angular workspaces across multiple versions! &lt;/p&gt;

&lt;p&gt;We needed a solution to automate this. &lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem with testing VSCode extensions
&lt;/h2&gt;

&lt;p&gt;There’s many different kinds of tests and different ways to structure and write them. Let’s go over four common types of tests and see how to use them in the context of a VSCode extension.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Static Tests,&lt;/strong&gt; like type checking and linting, are a given. VSCode extensions are written in Typescript and Nx sets up ESLint for us automatically so we get these static checks for free.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unit Tests&lt;/strong&gt; break your code down into ‘units’ and test those in isolation (what exactly constitutes a ‘unit’ is up to interpretation in most cases). They are a bit more complicated to get right here. Because a lot of functionality is tied to the VSCode APIs, unit tests often end up mocking everything which results in little functionality actually being tested. 
Because of this, unit tests are mostly useful for niches as well as helper and utility functions, not for broad coverage. They can still be useful and we have unit tests written with jest throughout our repo (but you could use any JS test runner to write and run unit tests).&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Integration Tests&lt;/strong&gt; combine multiple parts of your software and test them together. They are a good option for testing some behaviour of extensions. If you &lt;a href="https://code.visualstudio.com/api/working-with-extensions/testing-extension" rel="noopener noreferrer"&gt;read the docs&lt;/a&gt;, they suggest using the &lt;a href="https://github.com/microsoft/vscode-test" rel="noopener noreferrer"&gt;&lt;code&gt;@vscode/test-electron&lt;/code&gt;&lt;/a&gt; package and &lt;a href="https://mochajs.org/" rel="noopener noreferrer"&gt;&lt;code&gt;mocha&lt;/code&gt;&lt;/a&gt;. This will allow you to run tests inside an actual VSCode instance, so you avoid mocking. However, you are still constrained. The API gives limited information on many areas. For example even this very simple test is not easily realizable with the VSCode API:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nf"&gt;suite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sample Extension&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;vscode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;commands&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;executeCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;testing-ext.helloWorld&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;should display 'Hello World' notification&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ??? - VSCode API does not expose this information&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;End-to-End (E2E) tests&lt;/strong&gt; are robots that click through your application to make sure it works. They can test every kind of behaviour an actual user could do. Of course, this comes with a price: The overhead to run them can be quite high as you need to spin up fresh VSCode instances for each test. But this is a tradeoff worth taking: You will not be restricted in what you test and the tests mimic actual user flows. The best part: Since VSCode is built on Electron, there is a DOM that you can read, manipulate and assert on just like you would with any web application and keep using the well-established JS tooling we have for this. This is where WebdriverIO comes into play.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  WebdriverIO and the wdio-vscode-service
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://webdriver.io/" rel="noopener noreferrer"&gt;WebdriverIO (abbreviated as WDIO)&lt;/a&gt; is an E2E testing framework for Node.js. It allows you to automate all kinds of web and mobile applications using the Webdriver or Chrome DevTools protocols. &lt;/p&gt;

&lt;p&gt;In theory - since VSCode is built on Electron and is just Javascript, HTML and CSS under the hood - you could use any other framework like Cypress or Nightwatch to test it. &lt;/p&gt;

&lt;p&gt;So why WebdriverIO?&lt;/p&gt;

&lt;p&gt;WDIO has one big advantage: The &lt;a href="https://github.com/webdriverio-community/wdio-vscode-service" rel="noopener noreferrer"&gt;&lt;code&gt;wdio-vscode-service&lt;/code&gt;&lt;/a&gt; . It’s a plugin that integrates with WDIO and handles all setup-related work for you. You won’t have to think about downloading, installing and running a VSCode instance or the matching Chromedriver. On top of that, it bootstraps page objects for many functionalities and lets you access the VSCode API via remote function execution.&lt;/p&gt;

&lt;p&gt;All these (and more) features enable you to set WDIO up quickly and move on to writing test!&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring WDIO and writing the first test
&lt;/h2&gt;

&lt;p&gt;Setting up WDIO is a straightforward process. By following the &lt;a href="https://webdriver.io/docs/wdio-vscode-service" rel="noopener noreferrer"&gt;installation guide&lt;/a&gt; you get a preconfigured &lt;code&gt;wdio.conf.ts&lt;/code&gt; file and all required dependencies installed. After &lt;a href="https://webdriver.io/docs/wdio-vscode-service#typescript-support" rel="noopener noreferrer"&gt;adding some types to &lt;code&gt;tsconfig.json&lt;/code&gt;&lt;/a&gt; and tweaking some paths in &lt;code&gt;wdio.conf.ts&lt;/code&gt; to match our folder structure, we were already at the point where we could execute &lt;code&gt;wdio run ./wdio.conf.ts&lt;/code&gt; . You can see that VSCode is downloaded and unpacked for us. But of course, without any tests nothing really happens. Let’s change that!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  vscode-e2e ✗ npx wdio run ./wdio.conf.ts

Execution of 0 workers started at 2022-10-27T21:39:54.555Z

Downloading VS Code 1.72.2 from https://update.code.visualstudio.com/1.72.2/darwin/stable
Downloading VS Code &lt;span class="o"&gt;[==============================]&lt;/span&gt; 100%
Downloaded VS Code into /Users/maxkless/nx-console/apps/vscode-e2e/.wdio-vscode-service/vscode-darwin-1.72.2

2022-10-27T21:40:42.539Z ERROR @wdio/cli:launcher: No specs found to run, exiting with failure

Spec Files:      0 passed, 0 total &lt;span class="o"&gt;(&lt;/span&gt;0% completed&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;00:00:47
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Writing a test isn’t very complicated. Create a file in a location matching your configuration’s &lt;code&gt;specs&lt;/code&gt; property and WDIO will pick it up automatically. You can use mocha, cucumber or jasmine as test frameworks and start writing &lt;code&gt;describe&lt;/code&gt; , &lt;code&gt;it&lt;/code&gt; and &lt;code&gt;before&lt;/code&gt; blocks like you’re used to.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Workbench&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;wdio-vscode-service&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;NxConsole Example&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;should be able to load VSCode&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="na"&gt;workbench&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Workbench&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;browser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getWorkbench&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nf"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;workbench&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTitleBar&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;getTitle&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nf"&gt;toBe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[Extension Development Host] Visual Studio Code&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Refer to the &lt;a href="https://webdriver.io/docs/gettingstarted" rel="noopener noreferrer"&gt;WebdriverIO docs&lt;/a&gt; to learn more about its API and how to write tests. &lt;/p&gt;

&lt;p&gt;If we run &lt;code&gt;wdio run ./wdio.conf.ts&lt;/code&gt;  again, we will see that WDIO is using the cached VSCode binary and successfully executing our test!&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vscode-e2e ✗ npx wdio run ./wdio.conf.ts

Execution of 1 workers started at 2022-11-10T12:10:40.029Z

Found existing &lt;span class="nb"&gt;install &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt; /Users/maxkless/nx-console/apps/vscode-e2e/.wdio-vscode-service/vscode-darwin-1.72.2. Skipping download
&lt;span class="o"&gt;[&lt;/span&gt;0-0] RUNNING &lt;span class="k"&gt;in &lt;/span&gt;chrome - /specs/example.e2e.ts
&lt;span class="o"&gt;[&lt;/span&gt;0-0] PASSED &lt;span class="k"&gt;in &lt;/span&gt;chrome - /specs/example.e2e.ts

 &lt;span class="s2"&gt;"spec"&lt;/span&gt; Reporter:
&lt;span class="nt"&gt;------------------------------------------------------------------&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] Running: chrome (v102.0.5005.167) on mac os x&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] Session ID: da14f0f07ba2fe47728eaf8a249b5bca&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0]&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] » /specs/example.e2e.ts&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] NxConsole Example&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0]    ✓ should be able to load VSCode&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0]&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] 1 passing (1.3s)&lt;/span&gt;

Spec Files:      1 passed, 1 total &lt;span class="o"&gt;(&lt;/span&gt;100% completed&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;00:00:28
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Integrating with Nx - defining a target
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8fj3dzoaitf8gi9a9sx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8fj3dzoaitf8gi9a9sx.png" alt="Screenshot of the Nx dependency graph running inside VSCode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Of course, we wanted to take advantage of Nx’s powerful features like &lt;a href="https://nx.dev/core-features/explore-graph" rel="noopener noreferrer"&gt;the task graph&lt;/a&gt;, &lt;a href="https://nx.dev/core-features/cache-task-results" rel="noopener noreferrer"&gt;computation caching&lt;/a&gt; and &lt;a href="https://nx.dev/core-features/distribute-task-execution" rel="noopener noreferrer"&gt;distributed task execution&lt;/a&gt;. If you’re working on an &lt;a href="https://nx.dev/concepts/integrated-vs-package-based" rel="noopener noreferrer"&gt;integrated style Nx repo&lt;/a&gt;, you get access to many official and community plugins that allow for instant integration with popular dev tools. Jest, ESLint, Cypress and many more have executors (&lt;a href="https://nx.dev/plugin-features/use-task-executors" rel="noopener noreferrer"&gt;more on that here&lt;/a&gt;) that allow you to run them through Nx. This isn’t the case for WebdriverIO, so we had two options: Create a custom plugin and WDIO executor or simply use &lt;a href="https://nx.dev/packages/workspace/generators/run-commands" rel="noopener noreferrer"&gt;&lt;code&gt;nx:run-commands&lt;/code&gt;&lt;/a&gt; to wrap arbitrary commands with Nx. If WDIO became widely used in our repo, writing a custom plugin isn’t too much effort and could definitely be worth it! But for this one-time usage, we went with the quicker option. Let’s set up an &lt;code&gt;e2e&lt;/code&gt;  target like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"$schema"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"../../node_modules/nx/schemas/project-schema.json"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"sourceRoot"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"apps/vscode-e2e/src"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"projectType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"application"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"targets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"e2e"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"executor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nx:run-commands"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"wdio run ./wdio.conf.ts"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"cwd"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"apps/vscode-e2e"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"dependsOn"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"^build"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"implicitDependencies"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"vscode"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"nxls"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, if we run &lt;code&gt;nx run vscode-e2e:e2e&lt;/code&gt; , we will see WDIO run inside Nx!&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;➜  nx-console ✗ npx nx run vscode-e2e:e2e

✔    2/2 dependent project tasks succeeded &lt;span class="o"&gt;[&lt;/span&gt;2 &lt;span class="nb"&gt;read &lt;/span&gt;from cache]

Hint: you can run the &lt;span class="nb"&gt;command &lt;/span&gt;with &lt;span class="nt"&gt;--verbose&lt;/span&gt; to see the full dependent project outputs

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; nx run vscode-e2e:e2e

&lt;span class="c"&gt;## Execution of 1 workers started at 2022-10-27T19:44:02.756Z&lt;/span&gt;
Found existing &lt;span class="nb"&gt;install &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt; /Users/maxkless/nx-console/apps/vscode-e2e/.wdio-vscode-service/vscode-darwin-1.71.2. Skipping download
&lt;span class="o"&gt;[&lt;/span&gt;0-0] RUNNING &lt;span class="k"&gt;in &lt;/span&gt;chrome - /specs/example.e2e.ts
&lt;span class="o"&gt;[&lt;/span&gt;0-0] PASSED &lt;span class="k"&gt;in &lt;/span&gt;chrome - /specs/example.e2e.ts
&lt;span class="s2"&gt;"spec"&lt;/span&gt; Reporter:

&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] Running: chrome (v102.0.5005.167) on mac os x&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] Session ID: 74edae2b6a5f68effc8bdec1e2114e5f&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0]&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] » /specs/example.e2e.ts&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] NxConsole Example&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0]    ✓ should be able to load VSCode&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0]&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;chrome 102.0.5005.167 mac os x &lt;span class="c"&gt;#0-0] 1 passing (6.8s)&lt;/span&gt;
Spec Files:      1 passed, 1 total &lt;span class="o"&gt;(&lt;/span&gt;100% completed&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;in &lt;/span&gt;00:00:29

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; NX   Successfully ran target e2e &lt;span class="k"&gt;for &lt;/span&gt;project vscode-e2e and 2 task&lt;span class="o"&gt;(&lt;/span&gt;s&lt;span class="o"&gt;)&lt;/span&gt; it depends on &lt;span class="o"&gt;(&lt;/span&gt;40s&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 

Nx &lt;span class="nb"&gt;read &lt;/span&gt;the output from the cache instead of running the &lt;span class="nb"&gt;command &lt;/span&gt;&lt;span class="k"&gt;for &lt;/span&gt;2 out of 3 tasks.

See Nx Cloud run details at &lt;span class="o"&gt;[&lt;/span&gt;https://cloud.nx.app/runs/rprfQeMdy6]&lt;span class="o"&gt;(&lt;/span&gt;https://cloud.nx.app/runs/rprfQeMdy6&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;While the output doesn’t look too different, this enables some amazing features! If we run the tests again, they will complete in a few milliseconds because the result could be &lt;a href="https://nx.dev/concepts/how-caching-works" rel="noopener noreferrer"&gt;retrieved from cache&lt;/a&gt;. Also, because we defined &lt;code&gt;dependsOn&lt;/code&gt; and &lt;code&gt;implicitDependencies&lt;/code&gt; , Nx will always make sure that up-to-date versions of Nx Console and the nxls are built before E2E tests run. All this with just a few lines of config!&lt;/p&gt;
&lt;h2&gt;
  
  
  Setting up CI
&lt;/h2&gt;

&lt;p&gt;Another important step in getting the maximum value out of automated E2E testing is running it in CI. Adding new checks to an existing Github Actions pipeline isn’t complicated, so a single line of yaml configuration should do the trick:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;run: yarn exec nx affected --target=e2e --parallel=3&lt;/code&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;nx affected&lt;/code&gt; analyzes your code changes in order to compute the minimal set of projects that need to be retested. Learn more about it here: &lt;a href="https://nx.dev/concepts/affected" rel="noopener noreferrer"&gt;How Affected Works&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This will fail, however, because WebdriverIO tries to open VSCode and expects a screen - which action runners obviously don’t have. If we were testing on a simple Chrome or Firefox instance, this could be solved by adding &lt;code&gt;--headless&lt;/code&gt; to the browser’s launch options. VSCode doesn’t support a headless mode, though, so we had to find another solution: &lt;code&gt;xvfb&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.x.org/releases/X11R7.6/doc/man/man1/Xvfb.1.xhtml" rel="noopener noreferrer"&gt;&lt;code&gt;xvfb&lt;/code&gt;, short for X virtual frame buffer&lt;/a&gt;, is a display server that allows you to run any program headlessly by creating a virtual display - the frame buffer. To run our E2E test through &lt;code&gt;xvfb&lt;/code&gt; on CI, two steps were necessary:&lt;/p&gt;

&lt;p&gt;First, we created a new configuration in our &lt;code&gt;e2e&lt;/code&gt; target that runs the same script, but through &lt;code&gt;xvfb&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"e2e"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"configurations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"ci"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"xvfb-run -a wdio run ./wdio.conf.ts"&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Second, we have to make sure &lt;code&gt;xvfb&lt;/code&gt; is installed on our action runners. Theoretically, we could just run &lt;code&gt;sudo apt-get install -y xvfb&lt;/code&gt; on all our runners and call it a day. But for clarity’s sake and to demonstrate some of the advanced things you can do with Nx Cloud, we decided on a different solution. We want to create two kinds of runners: One with &lt;code&gt;xvfb&lt;/code&gt; installed and one without it. This can be done by using the &lt;code&gt;NX_RUN_GROUP&lt;/code&gt; variable in our agent and task definitions. With it, E2E tests are run on the first kind and other tasks are run on any runner.&lt;/p&gt;

&lt;p&gt;First, we specify a unique value of &lt;code&gt;NX_RUN_GROUP&lt;/code&gt; per run attempt and set it as an environment variable in our agent definition. Then, we make sure &lt;code&gt;xvfb&lt;/code&gt; is installed on these agents.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;agent&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Nx Cloud - Agent E2E&lt;/span&gt;
    &lt;span class="na"&gt;timeout-minutes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;15&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Set nx run variable&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;echo "NX_RUN_GROUP=run-group-e2e-${{ github.run_id}}-${{ github.run_attempt }}" &amp;gt;&amp;gt; $GITHUB_ENV&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v2&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;./.github/workflows/setup&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;node_version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ env.node_version }}&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install xvfb&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;sudo apt-get install -y xvfb&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Start Nx Agent E2E&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npx nx-cloud start-agent&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/upload-artifact@v3&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;e2e-screenshots&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apps/vscode-e2e/.screenshots&lt;/span&gt;
          &lt;span class="na"&gt;if-no-files-found&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ignore&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In &lt;code&gt;action.yml&lt;/code&gt; , where we specify the checks to be run, we provide the same  &lt;code&gt;NX_RUN_GROUP&lt;/code&gt; environment variable for our E2E task.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;E2E&lt;/span&gt;
&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;NX_RUN_GROUP&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;run-group-e2e-${{ github.run_id}}-${{ github.run_attempt }}&lt;/span&gt;
&lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;yarn exec nx affected --target=e2e --parallel=3 --configuration=ci&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Nx Cloud then matches these run groups and makes sure that all E2E tasks are only executed on agents with &lt;code&gt;xvfb&lt;/code&gt; installed. With it, we can now do everything we can do locally, with a real screen. For example, we take screenshots on failure and make them available to download from GitHub via &lt;code&gt;actions/upload-artifact&lt;/code&gt; . &lt;/p&gt;
&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the end, we have fully functioning E2E test running on every PR, fully cached and distributable through Nx. &lt;/p&gt;

&lt;p&gt;I want to take a moment and give special thanks to &lt;a href="https://twitter.com/bromann" rel="noopener noreferrer"&gt;Christian Bromann&lt;/a&gt; who is a lead maintainer on WebdriverIO and the wdio-vscode-service. Without his foundational work, this would’ve been 100x harder.&lt;/p&gt;

&lt;p&gt;If you have questions, comments or just want to chat about Nx Console, you can find me on twitter: &lt;a href="https://twitter.com/home" rel="noopener noreferrer"&gt;@MaxKless&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some of the code snippets I showed here have been shortened for clarity, but if you want to see our setup with all details, head over to GitHub: &lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/nrwl" rel="noopener noreferrer"&gt;
        nrwl
      &lt;/a&gt; / &lt;a href="https://github.com/nrwl/nx-console" rel="noopener noreferrer"&gt;
        nx-console
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Nx Console is the user interface for Nx &amp;amp; Lerna.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;p&gt;
    
        
        &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fnrwl%2Fnx-console%2Fmaster%2Fstatic%2Fnx-console-light.png" class="article-body-image-wrapper"&gt;&lt;img alt="Nx Console - The UI for Nx &amp;amp; Lerna" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fnrwl%2Fnx-console%2Fmaster%2Fstatic%2Fnx-console-light.png" width="100%"&gt;&lt;/a&gt;
    
&lt;/p&gt;
&lt;div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;The UI for Nx &amp;amp; Lerna&lt;/h1&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Spend less time looking up command line arguments and more time shipping incredible products.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/nrwl/nx-console/actions/workflows/ci_checks.yml" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/006c576578eaf286e1598406c25c1288f4bdc4000b090b015c9c92dbb9f04b64/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e72776c2f6e782d636f6e736f6c652f63695f636865636b732e796d6c3f6272616e63683d6d6173746572266c6162656c3d4349266c6f676f3d676974687562267374796c653d666c61742d737175617265" alt="CI Status"&gt;&lt;/a&gt;
&lt;a href="https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/0960c8e4200508015cfbd57a7c20404838f7082b5ffc04382dbecdecfbfe10b4/68747470733a2f2f696d672e736869656c64732e696f2f76697375616c2d73747564696f2d6d61726b6574706c6163652f762f6e72776c2e616e67756c61722d636f6e736f6c653f7374796c653d666c61742d737175617265266c6162656c3d56697375616c25323053747564696f253230436f6465253230657874656e73696f6e266c6f676f3d76697375616c73747564696f636f6465" alt="Visual Studio Marketplace Version"&gt;&lt;/a&gt;
&lt;a href="https://plugins.jetbrains.com/plugin/21060-nx-console" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/17018ce22c05952f79ca82b790104850159e3b7cd5206f043f89340babcdfc80/68747470733a2f2f696d672e736869656c64732e696f2f6a6574627261696e732f706c7567696e2f762f6465762e6e782e636f6e736f6c653f7374796c653d666c61742d737175617265266c6162656c3d4a6574427261696e73253230706c7567696e266c6f676f3d6a6574627261696e73" alt="JetBrains Plugin Version"&gt;&lt;/a&gt;
&lt;a href="https://github.com/nrwl/nx-console/blob/master/LICENSE" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/6c8ed2dd982149a467457c294f0e0b152660b51e7e2bce858585d0e5996d3703/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6e72776c2f6e782d636f6e736f6c653f7374796c653d666c61742d737175617265" alt="GitHub"&gt;&lt;/a&gt;
&lt;a rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/3c083aa7bf82ffb71606e833417660b19d0294911972075f54b5ab14861f2f6a/68747470733a2f2f696d672e736869656c64732e696f2f76697375616c2d73747564696f2d6d61726b6574706c6163652f642f6e72776c2e616e67756c61722d636f6e736f6c653f7374796c653d666c61742d737175617265"&gt;&lt;img src="https://camo.githubusercontent.com/3c083aa7bf82ffb71606e833417660b19d0294911972075f54b5ab14861f2f6a/68747470733a2f2f696d672e736869656c64732e696f2f76697375616c2d73747564696f2d6d61726b6574706c6163652f642f6e72776c2e616e67756c61722d636f6e736f6c653f7374796c653d666c61742d737175617265" alt="Visual Studio Marketplace Downloads"&gt;&lt;/a&gt;
&lt;a href="https://code.visualstudio.com" rel="nofollow noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/f24b8c38d68ffab806f894d9e92336ba0809643b6ee2d8436a6959d3661da970/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f56697375616c25323053747564696f253230436f64652d253545312e37312e302d626c75653f7374796c653d666c61742d737175617265266c6f676f3d76697375616c73747564696f636f6465" alt="Visual Studio Code Support"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;


        
        &lt;img alt="Nx Console - The UI for Nx &amp;amp; Lerna" src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fnrwl%2Fnx-console%2Fmaster%2Fstatic%2Fnx-console-ui-light.png" width="100%"&gt;
    
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Why Nx Console?&lt;/h2&gt;
&lt;/div&gt;
&lt;p&gt;Developers use both command-line tools and user interfaces. They commit in the terminal, but resolve conflicts in Visual
Studio Code or WebStorm. They use the right tool for the job.&lt;/p&gt;
&lt;p&gt;Nx is a command-line tool, which works great when you want to serve an application or generate a simple component. But
it falls short once you start doing advanced things.&lt;/p&gt;
&lt;p&gt;For instance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Exploring custom generator collections is hard in the terminal, but it's easy using Nx Console.&lt;/li&gt;
&lt;li&gt;Using rarely-used flags is challenging. Do you pass absolute or relative paths? You don't have to remember any flags
names or paths - Nx Console will help you by providing autocompletion and validating your inputs.&lt;/li&gt;
&lt;li&gt;Context-switching between your IDE and the browser is annoying. With Nx Console, you can view…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/nrwl/nx-console" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Learn more
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;🧠 &lt;a href="https://nx.dev/" rel="noopener noreferrer"&gt;Nx Docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;👩‍💻 &lt;a href="https://github.com/nrwl/nx-console" rel="noopener noreferrer"&gt;Nx Console GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🤖 &lt;a href="https://webdriver.io/" rel="noopener noreferrer"&gt;WebdriverIO Docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;👨‍💻 &lt;a href="https://github.com/webdriverio-community/wdio-vscode-service" rel="noopener noreferrer"&gt;wdio-vscode-service GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🧑‍💻 &lt;a href="https://github.com/nrwl/nx" rel="noopener noreferrer"&gt;Nx GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;💬 &lt;a href="https://go.nrwl.io/join-slack" rel="noopener noreferrer"&gt;Nx Community Slack&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📹 &lt;a href="https://www.youtube.com/@nxdevtools" rel="noopener noreferrer"&gt;Nx Youtube Channel&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, if you liked this, click the ❤️ and make sure to follow &lt;a href="https://twitter.com/MaxKless" rel="noopener noreferrer"&gt;Max&lt;/a&gt; and &lt;a href="https://twitter.com/nxdevtools" rel="noopener noreferrer"&gt;Nx&lt;/a&gt; on Twitter for more!&lt;/p&gt;


&lt;div class="ltag__tag ltag__tag__id__18643"&gt;
    &lt;div class="ltag__tag__content"&gt;
      &lt;h2&gt;#&lt;a href="https://dev.to/t/nx" class="ltag__tag__link"&gt;nx&lt;/a&gt; Follow
&lt;/h2&gt;
      &lt;div class="ltag__tag__summary"&gt;
        
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


</description>
      <category>monorepo</category>
      <category>vscode</category>
      <category>javascript</category>
      <category>nx</category>
    </item>
  </channel>
</rss>
