diff --git a/eslint.config.mjs b/eslint.config.mjs index 01947f1cd95..ade06b99230 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -543,5 +543,9 @@ export default defineConfig( files: ['packages/blockly/tests/typescript/**/*.ts', 'packages/blockly/tests/typescript/**/*.tsx'], tsconfig: './tests/typescript/tsconfig.json', }), + buildTSOverride({ + files: ['packages/blockly/tests/mocha/**/*.ts'], + tsconfig: './tests/mocha/tsconfig.json', + }), ), ); diff --git a/package-lock.json b/package-lock.json index 5cd73cfc667..49aab400866 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12777,6 +12777,17 @@ "@types/node": "*" } }, + "node_modules/@types/chai": { + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-5.2.3.tgz", + "integrity": "sha512-Mw558oeA9fFbv65/y4mHtXDs9bPnFMZAL/jxdPFUpOHHIXX91mcgEHbS5Lahr+pwZFR8A7GQleRWeI6cGFC2UA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/deep-eql": "*", + "assertion-error": "^2.0.1" + } + }, "node_modules/@types/concat-stream": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/concat-stream/-/concat-stream-2.0.3.tgz", @@ -12822,6 +12833,13 @@ "@types/ms": "*" } }, + "node_modules/@types/deep-eql": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/@types/deep-eql/-/deep-eql-4.0.2.tgz", + "integrity": "sha512-c9h9dVVMigMPc4bwTvC5dxqtqJZwQPePsWjPlpSOnojbor6pGqdk541lfA7AqFQr5pB1BRdq0juY9db81BwyFw==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/esrecurse": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/@types/esrecurse/-/esrecurse-4.3.1.tgz", @@ -13119,6 +13137,16 @@ "@types/node": "*" } }, + "node_modules/@types/sinon": { + "version": "22.0.0", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-22.0.0.tgz", + "integrity": "sha512-TDbVpbccc2HfiqHR09Argj3mHV1KMW7sCCKj52fsl8lbRLkEn7fB1966EWhOKWUBcqfBueZuPoA7/OK1CKiy3g==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/sinonjs__fake-timers": "*" + } + }, "node_modules/@types/sinonjs__fake-timers": { "version": "8.1.5", "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.5.tgz", @@ -14569,6 +14597,16 @@ "node": ">=12.0.0" } }, + "node_modules/assertion-error": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-2.0.1.tgz", + "integrity": "sha512-Izi8RQcffqCeNVgFigKli1ssklIbpHnCYc6AknXGYoB6grJqyeby7jv12JUQgmTAnIDnbck1uxksT4dzN3PWBA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + } + }, "node_modules/ast-types": { "version": "0.13.4", "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.13.4.tgz", @@ -38413,8 +38451,11 @@ "@blockly/block-test": "^13.1.0", "@hyperjump/browser": "^1.3.1", "@hyperjump/json-schema": "^1.17.6", - "@microsoft/api-documenter": "^7.30.13", + "@microsoft/api-documenter": "7.30.13", "@microsoft/api-extractor": "^7.58.9", + "@types/chai": "^5.2.3", + "@types/mocha": "^10.0.10", + "@types/sinon": "^22.0.0", "async-done": "^2.0.0", "chai": "^6.2.2", "concurrently": "^10.0.4", diff --git a/packages/blockly/package.json b/packages/blockly/package.json index 64915052245..d2c1f66d37e 100644 --- a/packages/blockly/package.json +++ b/packages/blockly/package.json @@ -20,9 +20,18 @@ "jsdom": false }, "imports": { - "#core/*": "./build/src/core/*", - "#blocks/*": "./build/src/blocks/*", - "#generators/*": "./build/src/generators/*" + "#core/*": { + "types": "./build/declarations/core/*", + "default": "./build/src/core/*" + }, + "#blocks/*": { + "types": "./build/declarations/blocks/*", + "default": "./build/src/blocks/*" + }, + "#generators/*": { + "types": "./build/declarations/generators/*", + "default": "./build/src/generators/*" + } }, "publishConfig": { "directory": "dist" @@ -79,9 +88,10 @@ "tsc": "gulp tsc", "test": "gulp test", "test:browser": "npx mocha --config tests/browser/.mocharc.js", - "test:mocha:node": "npx mocha --config tests/mocha/.mocharc.node.cjs \"tests/mocha/**/*_test.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", - "test:mocha:interactive": "npm run build && node scripts/prepare_mocha_bundle.mjs && concurrently -n tsc,esbuild,python3 \"tsc --watch --preserveWatchOutput --outDir \"build/src\" --declarationDir \"build/declarations\"\" \"esbuild build/tests/bundle-entry.js --bundle --sourcemap --alias:blockly/core=./build/src/core/blockly.js --alias:blockly/blocks=./build/src/blocks/blocks.js --alias:blockly=./build/src/core/blockly.js --outfile=build/tests/mocha-bundle.js --servedir=. --serve=127.0.0.1:8080 --watch=forever --log-level=warning\" \"python3 -m webbrowser 'http://localhost:8080/tests/mocha/index.html'\"", + "test:mocha:interactive": "npm run build && node scripts/prepare_mocha_bundle.mjs && concurrently -n tsc,tsc:tests,esbuild,python3 \"tsc --watch --preserveWatchOutput --outDir \"build/src\" --declarationDir \"build/declarations\"\" \"npm run test:mocha:typecheck -- --watch --preserveWatchOutput\" \"esbuild build/tests/bundle-entry.js --bundle --sourcemap --alias:blockly/core=./build/src/core/blockly.js --alias:blockly/blocks=./build/src/blocks/blocks.js --alias:blockly=./build/src/core/blockly.js --outfile=build/tests/mocha-bundle.js --servedir=. --serve=127.0.0.1:8080 --watch=forever --log-level=warning\" \"python3 -m webbrowser 'http://localhost:8080/tests/mocha/index.html'\"", "test:compile:advanced": "gulp buildAdvancedCompilationTest --debug", "updateGithubPages": "npm ci && node scripts/update_github_pages.mjs --upstream", "updateGithubPages:staging": "npm ci && node scripts/update_github_pages.mjs --use-local" @@ -142,6 +152,9 @@ "@hyperjump/json-schema": "^1.17.6", "@microsoft/api-documenter": "7.30.13", "@microsoft/api-extractor": "^7.58.9", + "@types/chai": "^5.2.3", + "@types/mocha": "^10.0.10", + "@types/sinon": "^22.0.0", "async-done": "^2.0.0", "chai": "^6.2.2", "concurrently": "^10.0.4", diff --git a/packages/blockly/tests/mocha/browser-setup.js b/packages/blockly/tests/mocha/browser-setup.js index 36dca422f9a..42a2fa9a024 100644 --- a/packages/blockly/tests/mocha/browser-setup.js +++ b/packages/blockly/tests/mocha/browser-setup.js @@ -26,9 +26,21 @@ import '@blockly/block-test'; chaiConfig.showDiff = false; -globalThis.Blockly = Blockly; -globalThis.javascriptGenerator = javascriptGenerator; -globalThis.sinon = sinon; +// Load globals used by the JS tests. This uses Object.defineProperty to avoid +// Typescript inferring typings for these objects and allowing TS tests to +// typecheck without explicitly importing them. When all tests are converted to +// TS, this should be removed. +for (const [name, value] of Object.entries({ + Blockly, + javascriptGenerator, + sinon, +})) { + Object.defineProperty(globalThis, name, { + value, + configurable: true, + writable: true, + }); +} // The focusable trees, toolbox definitions and #blocklyDiv the tests expect. // Shared with the Node harness so both run against identical markup. diff --git a/packages/blockly/tests/mocha/comment_view_test.js b/packages/blockly/tests/mocha/comment_view_test.js index 5d58b757af4..6928d0f4406 100644 --- a/packages/blockly/tests/mocha/comment_view_test.js +++ b/packages/blockly/tests/mocha/comment_view_test.js @@ -14,7 +14,7 @@ import { suite('Workspace comment', function () { setup(function () { sharedTestSetup.call(this); - this.workspace = new Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS); + this.workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS); this.commentView = new Blockly.comments.CommentView(this.workspace); }); diff --git a/packages/blockly/tests/mocha/event_block_change_test.js b/packages/blockly/tests/mocha/event_block_change_test.js index de459a9c039..356f6b4d499 100644 --- a/packages/blockly/tests/mocha/event_block_change_test.js +++ b/packages/blockly/tests/mocha/event_block_change_test.js @@ -118,7 +118,7 @@ suite('Block Change Event', function () { ); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, this.workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_block_create_test.js b/packages/blockly/tests/mocha/event_block_create_test.js index 2cdbcba232a..8c47a096732 100644 --- a/packages/blockly/tests/mocha/event_block_create_test.js +++ b/packages/blockly/tests/mocha/event_block_create_test.js @@ -96,7 +96,7 @@ suite('Block Create Event', function () { const origEvent = new Blockly.Events.BlockCreate(block); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, this.workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_block_delete_test.js b/packages/blockly/tests/mocha/event_block_delete_test.ts similarity index 61% rename from packages/blockly/tests/mocha/event_block_delete_test.js rename to packages/blockly/tests/mocha/event_block_delete_test.ts index f423a4064bb..e800f35112b 100644 --- a/packages/blockly/tests/mocha/event_block_delete_test.js +++ b/packages/blockly/tests/mocha/event_block_delete_test.ts @@ -4,7 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; +import sinon from 'sinon'; import {defineRowBlock} from './test_helpers/block_definitions.js'; import { sharedTestSetup, @@ -12,28 +14,31 @@ import { } from './test_helpers/setup_teardown.js'; suite('Block Delete Event', function () { - setup(function () { - this.clock = sharedTestSetup.call(this, {fireEventsNow: false}).clock; + let clock: sinon.SinonFakeTimers; + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { + ({clock} = sharedTestSetup.call(this, {fireEventsNow: false})); defineRowBlock(); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Receiving', function () { test('blocks do not receive their own delete events', function () { Blockly.Blocks['test'] = { - onchange: function (e) {}, + onchange: function (_e: Blockly.Events.Abstract) {}, }; // Need to stub the definition, because the property on the definition is // what gets registered as an event listener. const spy = sinon.spy(Blockly.Blocks['test'], 'onchange'); - const testBlock = this.workspace.newBlock('test'); + const testBlock = workspace.newBlock('test'); testBlock.dispose(); - this.clock.runAll(); + clock.runAll(); assert.isFalse(spy.called); }); @@ -41,13 +46,11 @@ suite('Block Delete Event', function () { suite('Serialization', function () { test('events round-trip through JSON', function () { - const block = this.workspace.newBlock('row_block', 'block_id'); + const block = workspace.newBlock('row_block', 'block_id'); const origEvent = new Blockly.Events.BlockDelete(block); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); - delete origEvent.oldXml; // xml fails deep equals for some reason. - delete newEvent.oldXml; // xml fails deep equals for some reason. + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_block_drag_test.js b/packages/blockly/tests/mocha/event_block_drag_test.ts similarity index 63% rename from packages/blockly/tests/mocha/event_block_drag_test.js rename to packages/blockly/tests/mocha/event_block_drag_test.ts index c4859ddc086..54c424b5393 100644 --- a/packages/blockly/tests/mocha/event_block_drag_test.js +++ b/packages/blockly/tests/mocha/event_block_drag_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import {defineRowBlock} from './test_helpers/block_definitions.js'; import { @@ -12,23 +13,25 @@ import { } from './test_helpers/setup_teardown.js'; suite('Block Drag Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); defineRowBlock(); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const block = this.workspace.newBlock('row_block', 'block_id'); + const block = workspace.newBlock('row_block', 'block_id'); const origEvent = new Blockly.Events.BlockDrag(block, true, []); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_bubble_open_test.js b/packages/blockly/tests/mocha/event_bubble_open_test.js index 12ccd774b29..74969b0043d 100644 --- a/packages/blockly/tests/mocha/event_bubble_open_test.js +++ b/packages/blockly/tests/mocha/event_bubble_open_test.js @@ -34,7 +34,7 @@ suite('Bubble Open Event', function () { ); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, this.workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_click_test.js b/packages/blockly/tests/mocha/event_click_test.ts similarity index 65% rename from packages/blockly/tests/mocha/event_click_test.js rename to packages/blockly/tests/mocha/event_click_test.ts index 00d3feb2fcf..facfa284eda 100644 --- a/packages/blockly/tests/mocha/event_click_test.js +++ b/packages/blockly/tests/mocha/event_click_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import {defineRowBlock} from './test_helpers/block_definitions.js'; import { @@ -12,19 +13,21 @@ import { } from './test_helpers/setup_teardown.js'; suite('Click Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); defineRowBlock(); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const block = this.workspace.newBlock('row_block', 'block_id'); + const block = workspace.newBlock('row_block', 'block_id'); const origEvent = new Blockly.Events.Click( block, undefined, @@ -32,7 +35,7 @@ suite('Click Event', function () { ); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_comment_change_test.js b/packages/blockly/tests/mocha/event_comment_change_test.ts similarity index 62% rename from packages/blockly/tests/mocha/event_comment_change_test.js rename to packages/blockly/tests/mocha/event_comment_change_test.ts index e25b008b93c..98102d7c69c 100644 --- a/packages/blockly/tests/mocha/event_comment_change_test.js +++ b/packages/blockly/tests/mocha/event_comment_change_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,18 +12,20 @@ import { } from './test_helpers/setup_teardown.js'; suite('Comment Change Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const comment = new Blockly.comments.WorkspaceComment(this.workspace); + const comment = new Blockly.comments.WorkspaceComment(workspace); comment.setText('old text'); const origEvent = new Blockly.Events.CommentChange( comment, @@ -31,7 +34,7 @@ suite('Comment Change Event', function () { ); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_comment_collapse_test.js b/packages/blockly/tests/mocha/event_comment_collapse_test.ts similarity index 59% rename from packages/blockly/tests/mocha/event_comment_collapse_test.js rename to packages/blockly/tests/mocha/event_comment_collapse_test.ts index d7cd95aa071..f14a03999f9 100644 --- a/packages/blockly/tests/mocha/event_comment_collapse_test.js +++ b/packages/blockly/tests/mocha/event_comment_collapse_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,22 +12,24 @@ import { } from './test_helpers/setup_teardown.js'; suite('Comment Collapse Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const comment = new Blockly.comments.WorkspaceComment(this.workspace); + const comment = new Blockly.comments.WorkspaceComment(workspace); const origEvent = new Blockly.Events.CommentCollapse(comment, true); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_comment_create_test.js b/packages/blockly/tests/mocha/event_comment_create_test.ts similarity index 61% rename from packages/blockly/tests/mocha/event_comment_create_test.js rename to packages/blockly/tests/mocha/event_comment_create_test.ts index 1ba9bd2ea69..68212cfa562 100644 --- a/packages/blockly/tests/mocha/event_comment_create_test.js +++ b/packages/blockly/tests/mocha/event_comment_create_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,26 +12,26 @@ import { } from './test_helpers/setup_teardown.js'; suite('Comment Create Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const comment = new Blockly.comments.WorkspaceComment(this.workspace); + const comment = new Blockly.comments.WorkspaceComment(workspace); comment.setText('test text'); comment.moveTo(new Blockly.utils.Coordinate(10, 10)); const origEvent = new Blockly.Events.CommentCreate(comment); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); - delete origEvent.xml; // xml fails deep equals for some reason. - delete newEvent.xml; // xml fails deep equals for some reason. + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_comment_delete_test.js b/packages/blockly/tests/mocha/event_comment_delete_test.ts similarity index 61% rename from packages/blockly/tests/mocha/event_comment_delete_test.js rename to packages/blockly/tests/mocha/event_comment_delete_test.ts index 7b880c34ee0..c88fe913afd 100644 --- a/packages/blockly/tests/mocha/event_comment_delete_test.js +++ b/packages/blockly/tests/mocha/event_comment_delete_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,26 +12,26 @@ import { } from './test_helpers/setup_teardown.js'; suite('Comment Delete Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const comment = new Blockly.comments.WorkspaceComment(this.workspace); + const comment = new Blockly.comments.WorkspaceComment(workspace); comment.setText('test text'); comment.moveTo(new Blockly.utils.Coordinate(10, 10)); const origEvent = new Blockly.Events.CommentDelete(comment); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); - delete origEvent.xml; // xml fails deep equals for some reason. - delete newEvent.xml; // xml fails deep equals for some reason. + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_comment_drag_test.js b/packages/blockly/tests/mocha/event_comment_drag_test.ts similarity index 60% rename from packages/blockly/tests/mocha/event_comment_drag_test.js rename to packages/blockly/tests/mocha/event_comment_drag_test.ts index 2e9c385a460..16db9c0b09e 100644 --- a/packages/blockly/tests/mocha/event_comment_drag_test.js +++ b/packages/blockly/tests/mocha/event_comment_drag_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,23 +12,25 @@ import { } from './test_helpers/setup_teardown.js'; suite('Comment Drag Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const comment = new Blockly.comments.WorkspaceComment(this.workspace); + const comment = new Blockly.comments.WorkspaceComment(workspace); comment.setText('test text'); const origEvent = new Blockly.Events.CommentDrag(comment, true); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_comment_resize_test.js b/packages/blockly/tests/mocha/event_comment_resize_test.ts similarity index 66% rename from packages/blockly/tests/mocha/event_comment_resize_test.js rename to packages/blockly/tests/mocha/event_comment_resize_test.ts index 7b092497ab7..23f7381c4fd 100644 --- a/packages/blockly/tests/mocha/event_comment_resize_test.js +++ b/packages/blockly/tests/mocha/event_comment_resize_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,18 +12,20 @@ import { } from './test_helpers/setup_teardown.js'; suite('Comment Resize Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const comment = new Blockly.comments.WorkspaceComment(this.workspace); + const comment = new Blockly.comments.WorkspaceComment(workspace); comment.setText('test text'); comment.setSize(new Blockly.utils.Size(100, 100)); const origEvent = new Blockly.Events.CommentResize(comment); @@ -30,7 +33,7 @@ suite('Comment Resize Event', function () { origEvent.recordCurrentSizeAsNewSize(); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_selected_test.js b/packages/blockly/tests/mocha/event_selected_test.ts similarity index 62% rename from packages/blockly/tests/mocha/event_selected_test.js rename to packages/blockly/tests/mocha/event_selected_test.ts index 2cb0b5af5b1..c6a7d44c088 100644 --- a/packages/blockly/tests/mocha/event_selected_test.js +++ b/packages/blockly/tests/mocha/event_selected_test.ts @@ -4,7 +4,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; +import sinon from 'sinon'; import {defineRowBlock} from './test_helpers/block_definitions.js'; import {createChangeListenerSpy} from './test_helpers/events.js'; import { @@ -14,51 +16,55 @@ import { } from './test_helpers/setup_teardown.js'; suite('Selected Event', function () { - setup(function () { - sharedTestSetup.call(this, {fireEventsNow: false}); + let clock: sinon.SinonFakeTimers; + let workspace: Blockly.WorkspaceSvg; + let eventSpy: sinon.SinonSpy; + + setup(function (this: Mocha.Context) { + ({clock} = sharedTestSetup.call(this, {fireEventsNow: false})); defineRowBlock(); - this.workspace = new Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS); - this.eventSpy = createChangeListenerSpy(this.workspace); + workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS); + eventSpy = createChangeListenerSpy(workspace); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const block1 = this.workspace.newBlock('row_block', 'test_id1'); - const block2 = this.workspace.newBlock('row_block', 'test_id2'); + const block1 = workspace.newBlock('row_block', 'test_id1'); + const block2 = workspace.newBlock('row_block', 'test_id2'); const origEvent = new Blockly.Events.Selected( block1.id, block2.id, - this.workspace.id, + workspace.id, ); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); }); test('Moving selection between two blocks fires one select event', function () { - const block1 = this.workspace.newBlock('row_block', 'test_id1'); - const block2 = this.workspace.newBlock('row_block', 'test_id2'); + const block1 = workspace.newBlock('row_block', 'test_id1'); + const block2 = workspace.newBlock('row_block', 'test_id2'); block1.initSvg(); block2.initSvg(); Blockly.getFocusManager().focusNode(block1); - this.clock.runAll(); - this.eventSpy.resetHistory(); + clock.runAll(); + eventSpy.resetHistory(); // Selecting block2 results in block1 becoming unselected; that should not // trigger a select event from block1 to nothing. There should only be one // select event from block1 to block2. Blockly.getFocusManager().focusNode(block2); - this.clock.runAll(); + clock.runAll(); - const calls = this.eventSpy.getCalls(); + const calls = eventSpy.getCalls(); assert.lengthOf(calls, 1); const event = calls[0].firstArg; assert.equal(event.oldElementId, block1.id); @@ -66,23 +72,23 @@ suite('Selected Event', function () { }); test('Refocusing the focused element post-DOM move does not fire a select event', function () { - const block1 = this.workspace.newBlock('row_block', 'test_id1'); - const block2 = this.workspace.newBlock('row_block', 'test_id2'); + const block1 = workspace.newBlock('row_block', 'test_id1'); + const block2 = workspace.newBlock('row_block', 'test_id2'); block1.initSvg(); block2.initSvg(); Blockly.getFocusManager().focusNode(block1); block2.bringToFront(); - this.clock.runAll(); + clock.runAll(); assert.equal(Blockly.getFocusManager().getFocusedNode(), block1); - this.eventSpy.resetHistory(); + eventSpy.resetHistory(); // `bringToFront` moves the block in the DOM, which ordinarily would cause // it to lose focus; however, the implementation re-focuses it post-move. // Since the block was selected before, this should not trigger a select // event to be fired, as the selection has not actually changed. block1.bringToFront(); - this.clock.runAll(); - const calls = this.eventSpy.getCalls(); + clock.runAll(); + const calls = eventSpy.getCalls(); assert.lengthOf(calls, 0); }); }); diff --git a/packages/blockly/tests/mocha/event_theme_change_test.js b/packages/blockly/tests/mocha/event_theme_change_test.ts similarity index 63% rename from packages/blockly/tests/mocha/event_theme_change_test.js rename to packages/blockly/tests/mocha/event_theme_change_test.ts index f514599d131..e4625ca84f7 100644 --- a/packages/blockly/tests/mocha/event_theme_change_test.js +++ b/packages/blockly/tests/mocha/event_theme_change_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,24 +12,26 @@ import { } from './test_helpers/setup_teardown.js'; suite('Theme Change Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { const origEvent = new Blockly.Events.ThemeChange( 'new theme name', - this.workspace.id, + workspace.id, ); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_trashcan_open_test.js b/packages/blockly/tests/mocha/event_trashcan_open_test.ts similarity index 55% rename from packages/blockly/tests/mocha/event_trashcan_open_test.js rename to packages/blockly/tests/mocha/event_trashcan_open_test.ts index 80869b4d50d..55acb41c180 100644 --- a/packages/blockly/tests/mocha/event_trashcan_open_test.js +++ b/packages/blockly/tests/mocha/event_trashcan_open_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,24 +12,23 @@ import { } from './test_helpers/setup_teardown.js'; suite('Trashcan Open Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { - const origEvent = new Blockly.Events.TrashcanOpen( - true, - this.workspace.id, - ); + const origEvent = new Blockly.Events.TrashcanOpen(true, workspace.id); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_var_create_test.js b/packages/blockly/tests/mocha/event_var_create_test.ts similarity index 65% rename from packages/blockly/tests/mocha/event_var_create_test.js rename to packages/blockly/tests/mocha/event_var_create_test.ts index 730c5fcd236..5031a33d3e3 100644 --- a/packages/blockly/tests/mocha/event_var_create_test.js +++ b/packages/blockly/tests/mocha/event_var_create_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,34 +12,31 @@ import { } from './test_helpers/setup_teardown.js'; suite('Var Create Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('untyped variable events round-trip through JSON', function () { - const varModel = new Blockly.VariableModel( - this.workspace, - 'name', - '', - 'id', - ); + const varModel = new Blockly.VariableModel(workspace, 'name', '', 'id'); const origEvent = new Blockly.Events.VarCreate(varModel); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); test('typed variable events round-trip through JSON', function () { const varModel = new Blockly.VariableModel( - this.workspace, + workspace, 'name', 'type', 'id', @@ -46,7 +44,7 @@ suite('Var Create Event', function () { const origEvent = new Blockly.Events.VarCreate(varModel); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_var_delete_test.js b/packages/blockly/tests/mocha/event_var_delete_test.ts similarity index 65% rename from packages/blockly/tests/mocha/event_var_delete_test.js rename to packages/blockly/tests/mocha/event_var_delete_test.ts index 098b5a6a43c..de30d67d0a5 100644 --- a/packages/blockly/tests/mocha/event_var_delete_test.js +++ b/packages/blockly/tests/mocha/event_var_delete_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,34 +12,31 @@ import { } from './test_helpers/setup_teardown.js'; suite('Var Delete Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('untyped variable events round-trip through JSON', function () { - const varModel = new Blockly.VariableModel( - this.workspace, - 'name', - '', - 'id', - ); + const varModel = new Blockly.VariableModel(workspace, 'name', '', 'id'); const origEvent = new Blockly.Events.VarDelete(varModel); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); test('typed variable events round-trip through JSON', function () { const varModel = new Blockly.VariableModel( - this.workspace, + workspace, 'name', 'type', 'id', @@ -46,7 +44,7 @@ suite('Var Delete Event', function () { const origEvent = new Blockly.Events.VarDelete(varModel); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_var_rename_test.js b/packages/blockly/tests/mocha/event_var_rename_test.ts similarity index 66% rename from packages/blockly/tests/mocha/event_var_rename_test.js rename to packages/blockly/tests/mocha/event_var_rename_test.ts index 1edefe3a4f3..f6132360820 100644 --- a/packages/blockly/tests/mocha/event_var_rename_test.js +++ b/packages/blockly/tests/mocha/event_var_rename_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,19 +12,21 @@ import { } from './test_helpers/setup_teardown.js'; suite('Var Rename Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('events round-trip through JSON', function () { const varModel = new Blockly.VariableModel( - this.workspace, + workspace, 'old name', 'type', 'id', @@ -31,7 +34,7 @@ suite('Var Rename Event', function () { const origEvent = new Blockly.Events.VarRename(varModel, 'new name'); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_var_type_change_test.js b/packages/blockly/tests/mocha/event_var_type_change_test.ts similarity index 68% rename from packages/blockly/tests/mocha/event_var_type_change_test.js rename to packages/blockly/tests/mocha/event_var_type_change_test.ts index 3a7cd890c47..177ed97e7f0 100644 --- a/packages/blockly/tests/mocha/event_var_type_change_test.js +++ b/packages/blockly/tests/mocha/event_var_type_change_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,19 +12,21 @@ import { } from './test_helpers/setup_teardown.js'; suite('Var Type Change Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { test('variable type change events round-trip through JSON', function () { const varModel = new Blockly.VariableModel( - this.workspace, + workspace, 'name', 'foo', 'id', @@ -35,7 +38,7 @@ suite('Var Type Change Event', function () { ); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/event_viewport_test.js b/packages/blockly/tests/mocha/event_viewport_test.ts similarity index 64% rename from packages/blockly/tests/mocha/event_viewport_test.js rename to packages/blockly/tests/mocha/event_viewport_test.ts index fbf0c780e36..319841658eb 100644 --- a/packages/blockly/tests/mocha/event_viewport_test.js +++ b/packages/blockly/tests/mocha/event_viewport_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,13 +12,15 @@ import { } from './test_helpers/setup_teardown.js'; suite('Viewport Change Event', function () { - setup(function () { + let workspace: Blockly.Workspace; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = new Blockly.Workspace(); + workspace = new Blockly.Workspace(); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); suite('Serialization', function () { @@ -26,12 +29,12 @@ suite('Viewport Change Event', function () { 10, 10, 1, - this.workspace.id, + workspace.id, 0.8, ); const json = origEvent.toJson(); - const newEvent = new Blockly.Events.fromJson(json, this.workspace); + const newEvent = Blockly.Events.fromJson(json, workspace); assert.deepEqual(newEvent, origEvent); }); diff --git a/packages/blockly/tests/mocha/node-setup.mjs b/packages/blockly/tests/mocha/node-setup.mjs index d4a33102477..ad29fb348da 100644 --- a/packages/blockly/tests/mocha/node-setup.mjs +++ b/packages/blockly/tests/mocha/node-setup.mjs @@ -130,8 +130,9 @@ for (const name of [...domInterfaceNames(window), ...WINDOW_MEMBERS]) { } } -// Tests use sinon and chai's config as ambient globals (sinon) / shared config. -globalThis.sinon = sinon; +// JS tests use sinon and chai's config as ambient globals (sinon) / shared +// config. +defineGlobal('sinon', sinon); chaiConfig.showDiff = false; // Silence console output from the tests and from Blockly itself. @@ -174,14 +175,13 @@ sinon.createSandbox = function (...args) { // text measurement) that JSDom does not implement. installSvgLayoutStubs(window); -// Load Blockly, the standard blocks and the JavaScript generator, and expose -// them as globals, mirroring what tests/mocha/index.html does in the browser. -const Blockly = await import('../../build/blockly.loader.mjs'); +// Load Blockly, the standard blocks and the JavaScript generator, mirroring +// what tests/mocha/index.html does in the browser. +await import('../../build/blockly.loader.mjs'); await import('../../build/blocks.loader.mjs'); const {javascriptGenerator} = await import('../../build/javascript.loader.mjs'); -globalThis.Blockly = Blockly; -globalThis.javascriptGenerator = javascriptGenerator; +defineGlobal('javascriptGenerator', javascriptGenerator); // Load English messages. build/msg/en.js is a classic script (not a module) // that augments the global Blockly.Msg, exactly as the browser harness loads it diff --git a/packages/blockly/tests/mocha/rect_test.js b/packages/blockly/tests/mocha/rect_test.ts similarity index 87% rename from packages/blockly/tests/mocha/rect_test.js rename to packages/blockly/tests/mocha/rect_test.ts index 86b65a48e22..0fdeabaea35 100644 --- a/packages/blockly/tests/mocha/rect_test.js +++ b/packages/blockly/tests/mocha/rect_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,13 +12,10 @@ import { } from './test_helpers/setup_teardown.js'; suite('Rect', function () { - setup(function () { + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.createCoord = function (x, y) { - return new Blockly.utils.Coordinate(x, y); - }; }); - teardown(function () { + teardown(function (this: Mocha.Context) { sharedTestTeardown.call(this); }); @@ -35,7 +33,7 @@ suite('Rect', function () { suite('createFromPoint()', function () { test('initializes properties correctly', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -50,7 +48,7 @@ suite('Rect', function () { suite('clone()', function () { test('copies properties correctly', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -67,7 +65,7 @@ suite('Rect', function () { suite('equals()', function () { test('same object instance should equal itself', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -85,7 +83,7 @@ suite('Rect', function () { test('an object and null should not be equal', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -97,7 +95,7 @@ suite('Rect', function () { test('null and an object should not be equal', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -109,7 +107,7 @@ suite('Rect', function () { test('object should equal its clone', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -121,12 +119,12 @@ suite('Rect', function () { test('object should equal an exact explicit copy', function () { const rect1 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); const rect2 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -141,12 +139,12 @@ suite('Rect', function () { test('object should not equal object with different x position', function () { const rect1 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); const rect2 = Blockly.utils.Rect.createFromPoint( - this.createCoord(3, 2), + new Blockly.utils.Coordinate(3, 2), 23, 45, ); @@ -161,12 +159,12 @@ suite('Rect', function () { test('object should not equal object with different y position', function () { const rect1 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); const rect2 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 4), + new Blockly.utils.Coordinate(1, 4), 23, 45, ); @@ -181,12 +179,12 @@ suite('Rect', function () { test('object should not equal object with different x and y positions', function () { const rect1 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); const rect2 = Blockly.utils.Rect.createFromPoint( - this.createCoord(3, 4), + new Blockly.utils.Coordinate(3, 4), 23, 45, ); @@ -201,12 +199,12 @@ suite('Rect', function () { test('object should not equal object with different width', function () { const rect1 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); const rect2 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 46, 45, ); @@ -221,12 +219,12 @@ suite('Rect', function () { test('object should not equal object with different height', function () { const rect1 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); const rect2 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 89, ); @@ -241,12 +239,12 @@ suite('Rect', function () { test('object should not equal object with all different properties', function () { const rect1 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); const rect2 = Blockly.utils.Rect.createFromPoint( - this.createCoord(3, 4), + new Blockly.utils.Coordinate(3, 4), 46, 89, ); @@ -263,7 +261,7 @@ suite('Rect', function () { suite('getHeight()', function () { test('computes zero height for empty rectangle', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0, 0), + new Blockly.utils.Coordinate(0, 0), 0, 0, ); @@ -273,7 +271,7 @@ suite('Rect', function () { test('computes height of 1 for unit square rectangle', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0, 0), + new Blockly.utils.Coordinate(0, 0), 1, 1, ); @@ -283,7 +281,7 @@ suite('Rect', function () { test('computes height of 1 for unit square rectangle not at origin', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 1, 1, ); @@ -293,7 +291,7 @@ suite('Rect', function () { test('computes height of 1 for unit square rectangle with negative position', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(-1, -2), + new Blockly.utils.Coordinate(-1, -2), 1, 1, ); @@ -303,7 +301,7 @@ suite('Rect', function () { test('computes decimal height for non-square rectangle not at origin', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1.1, 2.2), + new Blockly.utils.Coordinate(1.1, 2.2), 3.3, 4.4, ); @@ -315,7 +313,7 @@ suite('Rect', function () { suite('getWidth()', function () { test('computes zero width for empty rectangle', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0, 0), + new Blockly.utils.Coordinate(0, 0), 0, 0, ); @@ -325,7 +323,7 @@ suite('Rect', function () { test('computes width of 1 for unit square rectangle', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0, 0), + new Blockly.utils.Coordinate(0, 0), 1, 1, ); @@ -335,7 +333,7 @@ suite('Rect', function () { test('computes width of 1 for unit square rectangle not at origin', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 1, 1, ); @@ -345,7 +343,7 @@ suite('Rect', function () { test('computes width of 1 for unit square rectangle with negative position', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(-1, -2), + new Blockly.utils.Coordinate(-1, -2), 1, 1, ); @@ -355,7 +353,7 @@ suite('Rect', function () { test('computes decimal width for non-square rectangle not at origin', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1.1, 2.2), + new Blockly.utils.Coordinate(1.1, 2.2), 3.3, 4.4, ); @@ -368,7 +366,7 @@ suite('Rect', function () { suite('point contained within rect', function () { test('origin for zero-sized square', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0, 0), + new Blockly.utils.Coordinate(0, 0), 0, 0, ); @@ -380,7 +378,7 @@ suite('Rect', function () { test('whole number centroid for square at origin', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0, 0), + new Blockly.utils.Coordinate(0, 0), 2, 2, ); @@ -392,7 +390,7 @@ suite('Rect', function () { test('decimal number centroid for square at origin', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0, 0), + new Blockly.utils.Coordinate(0, 0), 1, 1, ); @@ -404,7 +402,7 @@ suite('Rect', function () { test('centroid for non-square not at origin', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -416,7 +414,7 @@ suite('Rect', function () { test('negative centroid for non-square not at origin', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(-10, -20), + new Blockly.utils.Coordinate(-10, -20), 3, 5, ); @@ -428,7 +426,7 @@ suite('Rect', function () { test('NW corner', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -440,7 +438,7 @@ suite('Rect', function () { test('NE corner', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -452,7 +450,7 @@ suite('Rect', function () { test('SW corner', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -464,7 +462,7 @@ suite('Rect', function () { test('SE corner', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -476,7 +474,7 @@ suite('Rect', function () { test('left edge midpoint', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -488,7 +486,7 @@ suite('Rect', function () { test('right edge midpoint', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -500,7 +498,7 @@ suite('Rect', function () { test('top edge midpoint', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -512,7 +510,7 @@ suite('Rect', function () { test('bottom edge midpoint', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -525,7 +523,7 @@ suite('Rect', function () { suite('point not contained within rect', function () { test('non-origin for zero-sized square', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0, 0), + new Blockly.utils.Coordinate(0, 0), 0, 0, ); @@ -537,7 +535,7 @@ suite('Rect', function () { test('point at midpoint x but above unit square', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); @@ -549,7 +547,7 @@ suite('Rect', function () { test('point at midpoint x but below unit square', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); @@ -561,7 +559,7 @@ suite('Rect', function () { test('point at midpoint y but left of unit square', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); @@ -573,7 +571,7 @@ suite('Rect', function () { test('point at midpoint y but right of unit square', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); @@ -585,7 +583,7 @@ suite('Rect', function () { test('positive point far outside positive rectangle', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -597,7 +595,7 @@ suite('Rect', function () { test('negative point far outside positive rectangle', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -609,7 +607,7 @@ suite('Rect', function () { test('positive point far outside negative rectangle', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(-10, -20), + new Blockly.utils.Coordinate(-10, -20), 3, 5, ); @@ -621,7 +619,7 @@ suite('Rect', function () { test('negative point far outside negative rectangle', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(-10, -20), + new Blockly.utils.Coordinate(-10, -20), 3, 5, ); @@ -633,7 +631,7 @@ suite('Rect', function () { test('Point just outside NW corner', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -645,7 +643,7 @@ suite('Rect', function () { test('Point just outside NE corner', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -657,7 +655,7 @@ suite('Rect', function () { test('Point just outside SW corner', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -669,7 +667,7 @@ suite('Rect', function () { test('Point just outside SE corner', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -681,7 +679,7 @@ suite('Rect', function () { test('Point just outside left edge midpoint', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -693,7 +691,7 @@ suite('Rect', function () { test('Point just outside right edge midpoint', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -705,7 +703,7 @@ suite('Rect', function () { test('Point just outside top edge midpoint', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -717,7 +715,7 @@ suite('Rect', function () { test('Point just outside bottom edge midpoint', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 3, 4, ); @@ -737,7 +735,7 @@ suite('Rect', function () { suite('does intersect', function () { test('rect and itself', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -749,7 +747,7 @@ suite('Rect', function () { test('rect and its clone', function () { const rect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -761,12 +759,12 @@ suite('Rect', function () { test('two rects of the same positions and dimensions', function () { const rect1 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); const rect2 = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 23, 45, ); @@ -785,12 +783,12 @@ suite('Rect', function () { // └─│─┘2│ // └───┘ const nwRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const seRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2, 2), + new Blockly.utils.Coordinate(2, 2), 2, 2, ); @@ -814,12 +812,12 @@ suite('Rect', function () { // │2└─│─┘ // └───┘ const neRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2, 1), + new Blockly.utils.Coordinate(2, 1), 2, 2, ); const swRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 2, 2, ); @@ -843,12 +841,12 @@ suite('Rect', function () { // └───┘ │ // └────┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(0.5, 1.5), + new Blockly.utils.Coordinate(0.5, 1.5), 1, 1, ); @@ -872,12 +870,12 @@ suite('Rect', function () { // │ └───┘ // └────┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2.5, 1.5), + new Blockly.utils.Coordinate(2.5, 1.5), 1, 1, ); @@ -901,12 +899,12 @@ suite('Rect', function () { // │└─┘│ // └───┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1.5, 0.5), + new Blockly.utils.Coordinate(1.5, 0.5), 1, 1, ); @@ -930,12 +928,12 @@ suite('Rect', function () { // └│─│┘ // └─┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1.5, 2.5), + new Blockly.utils.Coordinate(1.5, 2.5), 1, 1, ); @@ -961,12 +959,12 @@ suite('Rect', function () { // │ │ // └─┘ const tallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2, 1), + new Blockly.utils.Coordinate(2, 1), 1, 2, ); const wideRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 2, 1, ); @@ -990,12 +988,12 @@ suite('Rect', function () { // │ └─┘ │ // └─────┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1.5, 1.5), + new Blockly.utils.Coordinate(1.5, 1.5), 1, 1, ); @@ -1018,12 +1016,12 @@ suite('Rect', function () { // │ 2│ │2 │ // └──└────┘ const leftRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const rightRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2, 1), + new Blockly.utils.Coordinate(2, 1), 2, 2, ); @@ -1047,12 +1045,12 @@ suite('Rect', function () { // │───│ // └───┘ const topRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const bottomRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2), + new Blockly.utils.Coordinate(1, 2), 2, 2, ); @@ -1075,12 +1073,12 @@ suite('Rect', function () { // │ 2 │ 2 │ // └───┴───┘ const leftRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const rightRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3, 1), + new Blockly.utils.Coordinate(3, 1), 2, 2, ); @@ -1105,12 +1103,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const topRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const bottomRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 3), + new Blockly.utils.Coordinate(1, 3), 2, 2, ); @@ -1134,12 +1132,12 @@ suite('Rect', function () { // └─┘ │ // └───┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2, 1), + new Blockly.utils.Coordinate(2, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1.5), + new Blockly.utils.Coordinate(1, 1.5), 1, 1, ); @@ -1163,12 +1161,12 @@ suite('Rect', function () { // │ └─┘ // └───┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3, 1.5), + new Blockly.utils.Coordinate(3, 1.5), 1, 1, ); @@ -1192,12 +1190,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1.5, 0), + new Blockly.utils.Coordinate(1.5, 0), 1, 1, ); @@ -1221,12 +1219,12 @@ suite('Rect', function () { // └┌─┐┘ // └─┘ const bigRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const smallRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1.5, 3), + new Blockly.utils.Coordinate(1.5, 3), 1, 1, ); @@ -1251,12 +1249,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const swRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 3), + new Blockly.utils.Coordinate(1, 3), 2, 2, ); const neRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3, 1), + new Blockly.utils.Coordinate(3, 1), 2, 2, ); @@ -1281,12 +1279,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const nwRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const seRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3, 3), + new Blockly.utils.Coordinate(3, 3), 2, 2, ); @@ -1310,12 +1308,12 @@ suite('Rect', function () { // │ 2 │ │ 2 │ // └───┘ └───┘ const westRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const eastRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3.5, 1), + new Blockly.utils.Coordinate(3.5, 1), 2, 2, ); @@ -1341,12 +1339,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const northRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const southRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 3.5), + new Blockly.utils.Coordinate(1, 3.5), 2, 2, ); @@ -1370,12 +1368,12 @@ suite('Rect', function () { // └─┘│ │ // └───┘ const westRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 1, 1, ); const eastRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2.5, 1), + new Blockly.utils.Coordinate(2.5, 1), 2, 2, ); @@ -1399,12 +1397,12 @@ suite('Rect', function () { // │ │└─┘ // └───┘ const westRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const eastRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3.5, 1), + new Blockly.utils.Coordinate(3.5, 1), 1, 1, ); @@ -1429,12 +1427,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const northRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 1, 1, ); const southRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2.5), + new Blockly.utils.Coordinate(1, 2.5), 2, 2, ); @@ -1459,12 +1457,12 @@ suite('Rect', function () { // ┌─┐ // └─┘ const northRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const southRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 3.5), + new Blockly.utils.Coordinate(1, 3.5), 1, 1, ); @@ -1490,12 +1488,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const neRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3.5, 1), + new Blockly.utils.Coordinate(3.5, 1), 2, 2, ); const swRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 3.5), + new Blockly.utils.Coordinate(1, 3.5), 2, 2, ); @@ -1521,12 +1519,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const nwRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const seRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3.5, 3.5), + new Blockly.utils.Coordinate(3.5, 3.5), 2, 2, ); @@ -1551,12 +1549,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const neRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3.5, 1), + new Blockly.utils.Coordinate(3.5, 1), 1, 1, ); const swRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 2.5), + new Blockly.utils.Coordinate(1, 2.5), 2, 2, ); @@ -1581,12 +1579,12 @@ suite('Rect', function () { // │ 2 │ // └───┘ const nwRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 1, 1, ); const seRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2.5, 2.5), + new Blockly.utils.Coordinate(2.5, 2.5), 2, 2, ); @@ -1611,12 +1609,12 @@ suite('Rect', function () { // ┌─┐ // └─┘ const neRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(2.5, 1), + new Blockly.utils.Coordinate(2.5, 1), 2, 2, ); const swRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 3.5), + new Blockly.utils.Coordinate(1, 3.5), 1, 1, ); @@ -1641,12 +1639,12 @@ suite('Rect', function () { // ┌─┐ // └─┘ const nwRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(1, 1), + new Blockly.utils.Coordinate(1, 1), 2, 2, ); const seRect = Blockly.utils.Rect.createFromPoint( - this.createCoord(3.5, 3.5), + new Blockly.utils.Coordinate(3.5, 3.5), 1, 1, ); diff --git a/packages/blockly/tests/mocha/test_helpers/setup_teardown.js b/packages/blockly/tests/mocha/test_helpers/setup_teardown.js index e4700a96f39..8f7b78a5c50 100644 --- a/packages/blockly/tests/mocha/test_helpers/setup_teardown.js +++ b/packages/blockly/tests/mocha/test_helpers/setup_teardown.js @@ -108,6 +108,14 @@ function wrapDefineBlocksWithJsonArrayWithCleanup_(sharedCleanupObj) { }); } +/** + * The state sharedTestSetup() installs. + * @typedef {{ + * clock: import('sinon').SinonFakeTimers, + * eventsFireStub: (import('sinon').SinonStub|undefined), + * }} SharedTestState + */ + /** * Shared setup method that sets up fake timer for clock so that pending * setTimeout calls can be cleared in test teardown along with other common @@ -123,10 +131,10 @@ function wrapDefineBlocksWithJsonArrayWithCleanup_(sharedCleanupObj) { * track of block types defined so that they can be undefined in * sharedTestTeardown and calls original method. * + * @this {Mocha.Context} * @param {Object} options Options to enable/disable setup * of certain stubs. - * @return {{clock: *}} The fake clock (as part of an object to make refactoring - * easier). + * @return {SharedTestState} The state this setup created. */ export function sharedTestSetup(options = {}) { this.sharedSetupCalled_ = true; @@ -158,23 +166,29 @@ export function sharedTestSetup(options = {}) { wrapDefineBlocksWithJsonArrayWithCleanup_(this.sharedCleanup); return { clock: this.clock, + eventsFireStub: this.eventsFireStub, }; } /** * Shared cleanup method that clears up pending setTimeout calls, disposes of - * workspace, and resets global variables. Should be called in setup of - * outermost suite using sharedTestTeardown.call(this). + * workspace, and resets global variables. Should be called in the teardown of + * the same suite that called sharedTestSetup, using + * sharedTestTeardown.call(this, workspace). + * @this {Mocha.Context} + * @param {?import('#core/blockly.js').Workspace} [workspace] The workspace to + * dispose, defaulting to whatever is on the Mocha context. Should be + * explicitly passed by TS tests. */ -export function sharedTestTeardown() { +export function sharedTestTeardown(workspace = this.workspace) { const testRef = this.currentTest || this.test; if (!this.sharedSetupCalled_) { console.error('"' + testRef.fullTitle() + '" did not call sharedTestSetup'); } try { - if (this.workspace) { - workspaceTeardown.call(this, this.workspace); + if (workspace) { + workspaceTeardown.call(this, workspace); this.workspace = null; } else { this.clock.runAll(); // Run all queued setTimeout calls. diff --git a/packages/blockly/tests/mocha/touch_test.js b/packages/blockly/tests/mocha/touch_test.ts similarity index 93% rename from packages/blockly/tests/mocha/touch_test.js rename to packages/blockly/tests/mocha/touch_test.ts index 1becaae10a6..0fd1e028784 100644 --- a/packages/blockly/tests/mocha/touch_test.js +++ b/packages/blockly/tests/mocha/touch_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,11 +12,11 @@ import { } from './test_helpers/setup_teardown.js'; suite('Touch', function () { - setup(function () { + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); }); - teardown(function () { + teardown(function (this: Mocha.Context) { Blockly.Touch.clearTouchIdentifier(); sharedTestTeardown.call(this); }); @@ -95,7 +96,7 @@ suite('Touch', function () { pointerId: 7, pointerType: 'mouse', }); - assert.equal(Blockly.Touch.getTouchIdentifierFromEvent(pointerdown), 7); + assert.equal(Blockly.Touch.getTouchIdentifierFromEvent(pointerdown), '7'); }); test('is pointerId for touch PointerEvents', function () { @@ -103,7 +104,10 @@ suite('Touch', function () { pointerId: 42, pointerType: 'touch', }); - assert.equal(Blockly.Touch.getTouchIdentifierFromEvent(pointerdown), 42); + assert.equal( + Blockly.Touch.getTouchIdentifierFromEvent(pointerdown), + '42', + ); }); }); }); diff --git a/packages/blockly/tests/mocha/tsconfig.json b/packages/blockly/tests/mocha/tsconfig.json index a85bf44f30d..2a31482bb70 100644 --- a/packages/blockly/tests/mocha/tsconfig.json +++ b/packages/blockly/tests/mocha/tsconfig.json @@ -3,6 +3,13 @@ "include": ["**/*", "../../build/declarations/core/any_aliases.d.ts"], "compilerOptions": { "checkJs": false, - "noEmit": true + "noEmit": true, + // Keep the incremental cache the parent config enables out of the source + // tree, alongside the other build artifacts. + "tsBuildInfoFile": "../../build/tests/mocha-tsconfig.tsbuildinfo", + // Disallow TS language features requiring codegen. + "erasableSyntaxOnly": true, + "verbatimModuleSyntax": true, + "types": ["mocha"] } } diff --git a/packages/blockly/tests/mocha/workspace_comment_test.js b/packages/blockly/tests/mocha/workspace_comment_test.js index 1e29ed0b500..a33eac87bb7 100644 --- a/packages/blockly/tests/mocha/workspace_comment_test.js +++ b/packages/blockly/tests/mocha/workspace_comment_test.js @@ -18,7 +18,7 @@ import { suite('Workspace comment', function () { setup(function () { this.clock = sharedTestSetup.call(this, {fireEventsNow: false}).clock; - this.workspace = new Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS); + this.workspace = Blockly.inject('blocklyDiv', DEFAULT_INJECT_OPTIONS); }); teardown(function () { diff --git a/packages/blockly/tests/mocha/zelos_info_test.js b/packages/blockly/tests/mocha/zelos_info_test.ts similarity index 76% rename from packages/blockly/tests/mocha/zelos_info_test.js rename to packages/blockly/tests/mocha/zelos_info_test.ts index 222866b6f29..8f00488a247 100644 --- a/packages/blockly/tests/mocha/zelos_info_test.js +++ b/packages/blockly/tests/mocha/zelos_info_test.ts @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +import * as Blockly from '#core/blockly.js'; import {assert} from 'chai'; import { sharedTestSetup, @@ -11,9 +12,11 @@ import { } from './test_helpers/setup_teardown.js'; suite('Zelos RenderInfo', function () { - setup(function () { + let workspace: Blockly.WorkspaceSvg; + + setup(function (this: Mocha.Context) { sharedTestSetup.call(this); - this.workspace = Blockly.inject('blocklyDiv', {renderer: 'zelos'}); + workspace = Blockly.inject('blocklyDiv', {renderer: 'zelos'}); Blockly.defineBlocksWithJsonArray([ { 'type': 'tall_round_reporter', @@ -34,17 +37,17 @@ suite('Zelos RenderInfo', function () { ]); }); - teardown(function () { - sharedTestTeardown.call(this); + teardown(function (this: Mocha.Context) { + sharedTestTeardown.call(this, workspace); }); test('tall image on round reporter keeps corners inside the caps', function () { - const block = this.workspace.newBlock('tall_round_reporter'); + const block = workspace.newBlock('tall_round_reporter'); block.initSvg(); block.render(); const size = block.getHeightWidth(); - const fieldSize = block.getField('IMG').getSize(); + const fieldSize = block.getField('IMG')!.getSize(); const horizontalPad = size.width - fieldSize.width; // Height-aware round-cap clearance for a 75px field (radius 42) needs