持續整合 (CI)

為了幫助您驗證擴充套件並確保其功能正常,擴充套件 SDK 提供了一些工具來幫助您為擴充套件設定持續整合。

重要

The Docker Desktop Actionextension-test-helper 庫 都是 實驗性的.

使用 GitHub Actions 設定 CI 環境

您需要 Docker Desktop 才能安裝和驗證擴充套件。您可以使用 Docker Desktop Action 在 GitHub Actions 中啟動 Docker Desktop,方法是在工作流檔案中新增以下內容

steps:
  - id: start_desktop
    uses: docker/desktop-action/start@v0.1.0

注意

此操作目前僅支援 Github Action macOS 執行器。您需要為您的端到端測試指定 runs-on: macOS-latest

步驟執行完畢後,後續步驟將使用 Docker Desktop 和 Docker CLI 來安裝和測試擴充套件。

使用 Puppeteer 驗證您的擴充套件

Docker Desktop 在 CI 中啟動後,您可以使用 Jest 和 Puppeteer 構建、安裝和驗證擴充套件。

首先,從您的測試中構建並安裝擴充套件

import { DesktopUI } from "@docker/extension-test-helper";
import { exec as originalExec } from "child_process";
import * as util from "util";

export const exec = util.promisify(originalExec);

// keep a handle on the app to stop it at the end of tests
let dashboard: DesktopUI;

beforeAll(async () => {
  await exec(`docker build -t my/extension:latest .`, {
    cwd: "my-extension-src-root",
  });

  await exec(`docker extension install -f my/extension:latest`);
});

然後開啟 Docker 儀表板,在擴充套件的 UI 中執行一些測試

describe("Test my extension", () => {
  test("should be functional", async () => {
    dashboard = await DesktopUI.start();

    const eFrame = await dashboard.navigateToExtension("my/extension");

    // use puppeteer APIs to manipulate the UI, click on buttons, expect visual display and validate your extension
    await eFrame.waitForSelector("#someElementId");
  });
});

最後,關閉 Docker 儀表板並解除安裝您的擴充套件

afterAll(async () => {
  dashboard?.stop();
  await exec(`docker extension uninstall my/extension`);
});

下一步