Repository: stateful/vscode-runme
Pull request #750 (2023-07-31 18:07:07)

(bugfix): fix Vercel deployment workflow
The Vercel deployment view would appear even if calling `npm i vercel`:

![vercelerror](https://github.com/stateful/vscode-runme/assets/731337/1a6c24fe-5901-4932-a384-95855917d948)

This patch fixes this error.


Patch:
diff --git a/src/client/components/github/workflowViewer.ts b/src/client/components/github/workflowViewer.ts
index 70c59917..3c840fd5 100644
--- a/src/client/components/github/workflowViewer.ts
+++ b/src/client/components/github/workflowViewer.ts
@@ -58,18 +58,26 @@ export class WorkflowViewer extends LitElement {
 
   static styles = styles
 
-  private renderSelect(group: string, groupLabel: string, options: string[]) {
+  private renderSelect(group: string, groupLabel: string, options: string[], defaultValue: string) {
     return html`
       <div class="dropdown-container">
         <label slot="label">${groupLabel}</label>
-        <vscode-dropdown class="github-workflow-control">
+        <vscode-dropdown class="github-workflow-control" position="below">
           ${options.map((option: string) => {
-            return html`<vscode-option
-              value="${option}"
-              @click=${(e: Event) => this.setControlValue(group, e)}
-            >
-              ${option}
-            </vscode-option>`
+            return option === defaultValue
+              ? html`<vscode-option
+                  value="${option}"
+                  selected="true"
+                  @click=${(e: Event) => this.setControlValue(group, e)}
+                >
+                  ${option}
+                </vscode-option>`
+              : html`<vscode-option
+                  value="${option}"
+                  @click=${(e: Event) => this.setControlValue(group, e)}
+                >
+                  ${option}
+                </vscode-option>`
           })}
         </vscode-dropdown>
       </div>
@@ -166,7 +174,7 @@ export class WorkflowViewer extends LitElement {
         return html`<div class="row">
           ${when(
             type === 'choice' && options.length <= 3,
-            () => this.renderSelect(key, description, options),
+            () => this.renderSelect(key, description, options, defaultValue),
             () => html``
           )}
           ${when(
diff --git a/src/extension/executors/vercel.ts b/src/extension/executors/vercel.ts
index 8dd722ae..3eabfc11 100644
--- a/src/extension/executors/vercel.ts
+++ b/src/extension/executors/vercel.ts
@@ -117,5 +117,5 @@ export async function handleVercelDeployOutput(
 }
 
 export function isVercelDeployScript(script: string): boolean {
-  return script.trim().endsWith('vercel')
+  return Boolean(script.split(';').pop()?.trim() === 'vercel')
 }


Test patch:
diff --git a/tests/extension/executors/vercel.test.ts b/tests/extension/executors/vercel.test.ts
new file mode 100644
index 00000000..0bed4ef7
--- /dev/null
+++ b/tests/extension/executors/vercel.test.ts
@@ -0,0 +1,25 @@
+import { test, expect, vi } from 'vitest'
+
+import { isVercelDeployScript } from '../../../src/extension/executors/vercel.js'
+
+vi.mock('vscode')
+vi.mock('vscode-telemetry')
+vi.mock('../../../src/extension/executors/task.js', () => ({
+  bash: vi.fn(),
+  sh: vi.fn()
+}))
+vi.mock('../../../src/extension/executors/vercel/index.js', () => ({
+  deploy: vi.fn(),
+  login: vi.fn(),
+  logout: vi.fn()
+}))
+vi.mock('../../../src/extension/cell.js', () => ({
+  NotebookCellOutputManager: vi.fn(),
+  updateCellMetadata: vi.fn()
+}))
+
+test('isVercelDeployScript', () => {
+  expect(isVercelDeployScript('set -e -o pipefail; npm i -g vercel')).toBe(false)
+  expect(isVercelDeployScript('set -e -o pipefail; vercel login')).toBe(false)
+  expect(isVercelDeployScript('set -e -o pipefail; vercel')).toBe(true)
+})