From 029ff15e35636eaea4568d350f803812d494b449 Mon Sep 17 00:00:00 2001 From: Aaron Dodson Date: Tue, 1 Sep 2026 14:10:38 -0700 Subject: [PATCH] test: Reenable the drag-out-every-test-block browser tests --- packages/blockly/package.json | 2 +- .../tests/browser/test/toolbox_drag_test.mjs | 39 +++++++++++++++---- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/packages/blockly/package.json b/packages/blockly/package.json index d2c1f66d37e..2e2dd9a2c93 100644 --- a/packages/blockly/package.json +++ b/packages/blockly/package.json @@ -87,7 +87,7 @@ "start": "npm run package && npx nx run @blockly/dev-tools:build && concurrently -n watch,devtools-server,core-server \"npx nx watch --projects=@blockly/dev-tools --includeDependencies -- npm run build\" \"npx nx run @blockly/dev-tools:start --no-open\" \"http-server ./ -p 8081 -s -o /tests/playground.html -c-1\"", "tsc": "gulp tsc", "test": "gulp test", - "test:browser": "npx mocha --config tests/browser/.mocharc.js", + "test:browser": "npx nx run @blockly/block-test:build && npx mocha --config tests/browser/.mocharc.js", "test:mocha:node": "npm run test:mocha:typecheck && npx mocha --config tests/mocha/.mocharc.node.cjs \"tests/mocha/**/*_test.{js,ts}\"", "test:mocha:typecheck": "tsc -p tests/mocha/tsconfig.json", "test:generators": "gulp testGenerators", diff --git a/packages/blockly/tests/browser/test/toolbox_drag_test.mjs b/packages/blockly/tests/browser/test/toolbox_drag_test.mjs index 7934c61a794..d7fbc5c87b2 100644 --- a/packages/blockly/tests/browser/test/toolbox_drag_test.mjs +++ b/packages/blockly/tests/browser/test/toolbox_drag_test.mjs @@ -9,6 +9,8 @@ */ import * as chai from 'chai'; +import {readFileSync} from 'fs'; +import {createRequire} from 'module'; import {Key} from 'webdriverio'; import { getBlockTypeFromCategory, @@ -19,6 +21,29 @@ import { testSetup, } from './test_setup.mjs'; +const require = createRequire(import.meta.url); + +const blockTestSource = readFileSync( + require.resolve('@blockly/block-test'), + 'utf8', +); + +/** + * Load the test blocks into the playground page and swap in their toolbox. + * @param browser The active WebdriverIO Browser object. + */ +async function loadTestBlocks(browser) { + await browser.execute((source) => { + const script = document.createElement('script'); + script.textContent = source; + document.head.appendChild(script); + + const workspace = Blockly.getMainWorkspace(); + workspace.updateToolbox(window.toolboxTestBlocks); + window.toolboxTestBlocksInit(workspace); + }, blockTestSource); +} + // Categories in the basic toolbox. const basicCategories = [ 'Logic', @@ -194,17 +219,15 @@ suite('Open toolbox categories', function () { await openCategories(this.browser, basicCategories, screenDirection.RTL); }); - test.skip('opening every toolbox category in the test toolbox in LTR', async function () { - this.browser = await testSetup( - testFileLocations.PLAYGROUND + '?toolbox=test-blocks', - ); + test('opening every toolbox category in the test toolbox in LTR', async function () { + this.browser = await testSetup(testFileLocations.PLAYGROUND); + await loadTestBlocks(this.browser); await openCategories(this.browser, testCategories, screenDirection.LTR); }); - test.skip('opening every toolbox category in the test toolbox in RTL', async function () { - this.browser = await testSetup( - testFileLocations.PLAYGROUND + '?toolbox=test-blocks&dir=rtl', - ); + test('opening every toolbox category in the test toolbox in RTL', async function () { + this.browser = await testSetup(testFileLocations.PLAYGROUND_RTL); + await loadTestBlocks(this.browser); await openCategories(this.browser, testCategories, screenDirection.RTL); });