Skip to content

test(blocks-screenshot): scratch-blocks v2 API に合わせてテストモックを更新 #636

@takaokouji

Description

@takaokouji

現象

feat/upstream-merge-2026-05 ブランチの CI で unit-test-gui が以下 9 件失敗している。

FAIL test/unit/lib/blocks-screenshot.test.js
  ● mergeWithBubbleBBox › returns original bbox when bubble canvas has no children
  ● mergeWithBubbleBBox › returns original bbox when workspace has no bubble canvas
  ● mergeWithBubbleBBox › expands bbox to include bubble canvas bounds
  ● buildExportSVG › includes bubble canvas clone in exported SVG
  ● buildExportSVG › strips foreignObject elements from bubble canvas clone to avoid tainted canvas
  ● buildExportSVG › does not include bubble canvas when it has no children
  ● downloadBlocksAsImage › downloads PNG with correct filename
  ● downloadBlocksAsImage › canvas dimensions include padding
  ● downloadBlocksAsImage › canvas dimensions respect scale

TypeError: workspace.getBubbleCanvas is not a function
TypeError: workspace.getCanvas is not a function

原因

packages/scratch-gui/src/lib/blocks-screenshot.js は scratch-blocks v2 (Blockly v12 ベース) に追従して以下のメソッド呼び出しに更新済み:

  • workspace.getCanvas() — block canvas の取得
  • workspace.getBubbleCanvas() — comment bubble canvas の取得

しかしテストの makeMockWorkspace ヘルパーは v1 時代の直接プロパティ参照 (svgBlockCanvas_, svgBubbleCanvas_) のままだったため、本体コードがメソッド呼び出しを試みると is not a function で失敗する。

実本体は実 Blockly インスタンスを使うため動作しているが、テストモックが追従していない (= テストだけが失敗している)。

対応

makeMockWorkspace を v2 API に合わせて以下のように更新する:

 return {
     getBlocksBoundingBox: jest.fn(() => boundingBox),
     scale,
-    svgBlockCanvas_: group,
-    svgBubbleCanvas_: bubbleGroup,
+    getCanvas: jest.fn(() => group),
+    getBubbleCanvas: jest.fn(() => bubbleGroup),
 };

合わせて、テスト内で直接 workspace.svgBubbleCanvas_ を読み書きしている箇所も workspace.getBubbleCanvas() 経由 / workspace.getBubbleCanvas = jest.fn(() => null) に書き換える。

関連

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions