持續整合 (CI)

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

重要

Docker Desktop Actionextension-test-helper 函式庫實驗性階段使用 GitHub Actions 設定 CI 環境

您需要 Docker Desktop 才能安裝和驗證您的擴充功能。您可以在 GitHub Actions 中使用 Docker Desktop Action,方法是將以下內容添加到工作流程檔案中

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 Desktop Dashboard 並在擴充功能的 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 Desktop Dashboard 並解除安裝您的擴充功能

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

後續步驟