diff --git a/tests/deps.mocha.js b/tests/deps.mocha.js index c43d84e13..f2d550157 100644 --- a/tests/deps.mocha.js +++ b/tests/deps.mocha.js @@ -44,19 +44,19 @@ goog.addDependency('../../tests/mocha/registry_test.js', ['Blockly.test.registry goog.addDependency('../../tests/mocha/run_mocha_tests_in_browser.js', [], [], {'lang': 'es8'}); goog.addDependency('../../tests/mocha/serializer_test.js', ['Blockly.test.serialization'], ['Blockly.test.helpers.common', 'Blockly.test.helpers.setupTeardown'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/shortcut_registry_test.js', ['Blockly.test.shortcutRegistry'], ['Blockly.test.helpers.setupTeardown', 'Blockly.test.helpers.userInput'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/block_definitions.js', ['Blockly.test.helpers.blockDefinitions'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/code_generation.js', ['Blockly.test.helpers.codeGeneration'], ['Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/common.js', ['Blockly.test.helpers.common'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/events.js', ['Blockly.test.helpers.events'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/fields.js', ['Blockly.test.helpers.fields'], ['Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/procedures.js', ['Blockly.test.helpers.procedures'], ['Blockly.ConnectionType'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/serialization.js', ['Blockly.test.helpers.serialization'], ['Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/setup_teardown.js', ['Blockly.test.helpers.setupTeardown'], ['Blockly.Events.utils', 'Blockly.blocks'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/toolbox_definitions.js', ['Blockly.test.helpers.toolboxDefinitions'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/user_input.js', ['Blockly.test.helpers.userInput'], ['Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/variables.js', ['Blockly.test.helpers.variables'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/warnings.js', ['Blockly.test.helpers.warnings'], [], {'lang': 'es6', 'module': 'goog'}); -goog.addDependency('../../tests/mocha/test_helpers/workspace.js', ['Blockly.test.helpers.workspace'], ['Blockly.Events.utils', 'Blockly.test.helpers.setupTeardown', 'Blockly.test.helpers.variables', 'Blockly.test.helpers.warnings'], {'lang': 'es6', 'module': 'goog'}); +goog.addDependency('../../tests/mocha/test_helpers/block_definitions.js', ['Blockly.test.helpers.blockDefinitions'], [], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/code_generation.js', ['Blockly.test.helpers.codeGeneration'], ['Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/common.js', ['Blockly.test.helpers.common'], [], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/events.js', ['Blockly.test.helpers.events'], [], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/fields.js', ['Blockly.test.helpers.fields'], ['Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/procedures.js', ['Blockly.test.helpers.procedures'], ['Blockly.ConnectionType'], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/serialization.js', ['Blockly.test.helpers.serialization'], ['Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/setup_teardown.js', ['Blockly.test.helpers.setupTeardown'], ['Blockly.Events.utils', 'Blockly.blocks'], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/toolbox_definitions.js', ['Blockly.test.helpers.toolboxDefinitions'], [], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/user_input.js', ['Blockly.test.helpers.userInput'], ['Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/variables.js', ['Blockly.test.helpers.variables'], [], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/warnings.js', ['Blockly.test.helpers.warnings'], [], {'lang': 'es6', 'module': 'es6'}); +goog.addDependency('../../tests/mocha/test_helpers/workspace.js', ['Blockly.test.helpers.workspace'], ['Blockly.Events.utils', 'Blockly.test.helpers.setupTeardown', 'Blockly.test.helpers.variables', 'Blockly.test.helpers.warnings'], {'lang': 'es6', 'module': 'es6'}); goog.addDependency('../../tests/mocha/theme_test.js', ['Blockly.test.theme'], ['Blockly.Events.utils', 'Blockly.test.helpers.events', 'Blockly.test.helpers.setupTeardown'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/toolbox_test.js', ['Blockly.test.toolbox'], ['Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.setupTeardown', 'Blockly.test.helpers.toolboxDefinitions'], {'lang': 'es6', 'module': 'goog'}); goog.addDependency('../../tests/mocha/tooltip_test.js', ['Blockly.test.tooltip'], ['Blockly.test.helpers.setupTeardown'], {'lang': 'es6', 'module': 'goog'}); diff --git a/tests/mocha/.eslintrc.json b/tests/mocha/.eslintrc.json index 8ebf31ae6..08eee3328 100644 --- a/tests/mocha/.eslintrc.json +++ b/tests/mocha/.eslintrc.json @@ -1,4 +1,7 @@ { + "parserOptions": { + "sourceType": "module" + }, "env": { "browser": true, "mocha": true diff --git a/tests/mocha/astnode_test.js b/tests/mocha/astnode_test.js index f974f3ea8..1a15dfb62 100644 --- a/tests/mocha/astnode_test.js +++ b/tests/mocha/astnode_test.js @@ -11,6 +11,7 @@ const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('B suite('ASTNode', function() { + console.log('1/a'); setup(function() { sharedTestSetup.call(this); Blockly.defineBlocksWithJsonArray([{ @@ -100,7 +101,9 @@ suite('ASTNode', function() { }); suite('HelperFunctions', function() { + console.log('2'); test('findNextForInput_', function() { + console.log('3'); const input = this.blocks.statementInput1.inputList[0]; const input2 = this.blocks.statementInput1.inputList[1]; const connection = input.connection; @@ -169,6 +172,7 @@ suite('ASTNode', function() { }); suite('NavigationFunctions', function() { + console.log('b'); setup(function() { Blockly.defineBlocksWithJsonArray([{ "type": "top_connection", @@ -319,7 +323,9 @@ suite('ASTNode', function() { workspaceTeardown.call(this, this.singleBlockWorkspace); }); + console.log('c'); test('fromPreviousToBlock', function() { + console.log('d'); const prevConnection = this.blocks.statementInput1.previousConnection; const node = ASTNode.createConnectionNode(prevConnection); const nextNode = node.next(); diff --git a/tests/mocha/test_helpers/block_definitions.js b/tests/mocha/test_helpers/block_definitions.js index a30d7defe..213075a74 100644 --- a/tests/mocha/test_helpers/block_definitions.js +++ b/tests/mocha/test_helpers/block_definitions.js @@ -4,10 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.blockDefinitions'); +goog.declareModuleId('Blockly.test.helpers.blockDefinitions'); -function defineStackBlock(name = 'stack_block') { +export function defineStackBlock(name = 'stack_block') { Blockly.defineBlocksWithJsonArray([{ "type": name, "message0": "", @@ -15,9 +15,8 @@ function defineStackBlock(name = 'stack_block') { "nextStatement": null, }]); } -exports.defineStackBlock = defineStackBlock; -function defineRowBlock(name = 'row_block') { +export function defineRowBlock(name = 'row_block') { Blockly.defineBlocksWithJsonArray([{ "type": name, "message0": "%1", @@ -30,9 +29,8 @@ function defineRowBlock(name = 'row_block') { "output": null, }]); } -exports.defineRowBlock = defineRowBlock; -function defineStatementBlock(name = 'statement_block') { +export function defineStatementBlock(name = 'statement_block') { Blockly.defineBlocksWithJsonArray([{ "type": name, "message0": "%1", @@ -49,9 +47,8 @@ function defineStatementBlock(name = 'statement_block') { "helpUrl": "", }]); } -exports.defineStatementBlock = defineStatementBlock; -function defineBasicBlockWithField(name = 'test_field_block') { +export function defineBasicBlockWithField(name = 'test_field_block') { Blockly.defineBlocksWithJsonArray([{ "type": name, "message0": "%1", @@ -64,9 +61,8 @@ function defineBasicBlockWithField(name = 'test_field_block') { "output": null, }]); } -exports.defineBasicBlockWithField = defineBasicBlockWithField; -function defineMutatorBlocks() { +export function defineMutatorBlocks() { Blockly.defineBlocksWithJsonArray([ { 'type': 'xml_block', @@ -158,9 +154,8 @@ function defineMutatorBlocks() { }; Blockly.Extensions.registerMutator('jso_mutator', jsoMutator); } -exports.defineMutatorBlocks = defineMutatorBlocks; -function createTestBlock() { +export function createTestBlock() { return { 'id': 'test', 'rendered': false, @@ -174,12 +169,10 @@ function createTestBlock() { 'updateVarName': Blockly.Block.prototype.updateVarName, }; } -exports.createTestBlock = createTestBlock; -function createRenderedBlock(workspaceSvg, type) { +export function createRenderedBlock(workspaceSvg, type) { const block = workspaceSvg.newBlock(type); block.initSvg(); block.render(); return block; } -exports.createRenderedBlock = createRenderedBlock; diff --git a/tests/mocha/test_helpers/code_generation.js b/tests/mocha/test_helpers/code_generation.js index 72d520c7f..4d3c0a375 100644 --- a/tests/mocha/test_helpers/code_generation.js +++ b/tests/mocha/test_helpers/code_generation.js @@ -5,7 +5,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.codeGeneration'); +goog.declareModuleId('Blockly.test.helpers.codeGeneration'); const {runTestSuites} = goog.require('Blockly.test.helpers.common'); @@ -15,7 +15,7 @@ const {runTestSuites} = goog.require('Blockly.test.helpers.common'); * @implements {TestCase} * @record */ -class CodeGenerationTestCase { +export class CodeGenerationTestCase { /** * Class for a code generation test case. */ @@ -43,14 +43,13 @@ class CodeGenerationTestCase { */ createBlock(workspace) {} } -exports.CodeGenerationTestCase = CodeGenerationTestCase; /** * Code generation test suite. * @extends {TestSuite} * @record */ -class CodeGenerationTestSuite { +export class CodeGenerationTestSuite { /** * Class for a code generation test suite. */ @@ -61,7 +60,6 @@ class CodeGenerationTestSuite { this.generator; } } -exports.CodeGenerationTestSuite = CodeGenerationTestSuite; /** * Returns mocha test callback for code generation based on provided @@ -102,7 +100,7 @@ const createCodeGenerationTestFn_ = (generator) => { * Runs blockToCode test suites. * @param {!Array} testSuites The test suites to run. */ -const runCodeGenerationTestSuites = (testSuites) => { +export const runCodeGenerationTestSuites = (testSuites) => { /** * Creates function used to generate mocha test callback. * @param {!CodeGenerationTestSuite} suiteInfo The test suite information. @@ -115,4 +113,3 @@ const runCodeGenerationTestSuites = (testSuites) => { runTestSuites(testSuites, createTestFn); }; -exports.runCodeGenerationTestSuites = runCodeGenerationTestSuites; diff --git a/tests/mocha/test_helpers/common.js b/tests/mocha/test_helpers/common.js index fcb61021a..8e705b0fc 100644 --- a/tests/mocha/test_helpers/common.js +++ b/tests/mocha/test_helpers/common.js @@ -4,13 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.common'); +goog.declareModuleId('Blockly.test.helpers.common'); /** * Test case configuration. * @record */ -class TestCase { +export class TestCase { /** * Class for a test case configuration. */ @@ -31,7 +31,6 @@ class TestCase { this.only; } } -exports.TestCase = TestCase; /** * Test suite configuration. @@ -39,7 +38,7 @@ exports.TestCase = TestCase; * @template {TestCase} T * @template {TestSuite} U */ -class TestSuite { +export class TestSuite { /** * Class for a test suite configuration. */ @@ -68,7 +67,6 @@ class TestSuite { this.only; } } -exports.TestSuite = TestSuite; /** * Runs provided test cases. @@ -77,14 +75,13 @@ exports.TestSuite = TestSuite; * @param {function(T):Function} createTestCallback Creates test * callback using given test case. */ -function runTestCases(testCases, createTestCallback) { +export function runTestCases(testCases, createTestCallback) { testCases.forEach((testCase) => { let testCall = (testCase.skip ? test.skip : test); testCall = (testCase.only ? test.only : testCall); testCall(testCase.title, createTestCallback(testCase)); }); } -exports.runTestCases = runTestCases; /** * Runs provided test suite. @@ -95,7 +92,7 @@ exports.runTestCases = runTestCases; * } createTestCaseCallback Creates test case callback using given test * suite. */ -function runTestSuites(testSuites, createTestCaseCallback) { +export function runTestSuites(testSuites, createTestCaseCallback) { testSuites.forEach((testSuite) => { let suiteCall = (testSuite.skip ? suite.skip : suite); suiteCall = (testSuite.only ? suite.only : suiteCall); @@ -109,4 +106,3 @@ function runTestSuites(testSuites, createTestCaseCallback) { }); }); } -exports.runTestSuites = runTestSuites; diff --git a/tests/mocha/test_helpers/events.js b/tests/mocha/test_helpers/events.js index e69573318..ba1b3f4f8 100644 --- a/tests/mocha/test_helpers/events.js +++ b/tests/mocha/test_helpers/events.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.events'); +goog.declareModuleId('Blockly.test.helpers.events'); /** @@ -13,10 +13,9 @@ goog.module('Blockly.test.helpers.events'); * calls on. * @return {!SinonSpy} The created spy. */ -function createFireChangeListenerSpy(workspace) { +export function createFireChangeListenerSpy(workspace) { return sinon.spy(workspace, 'fireChangeListener'); } -exports.createFireChangeListenerSpy = createFireChangeListenerSpy; /** * Asserts whether the given xml property has the expected property. @@ -75,7 +74,7 @@ function isXmlProperty_(key) { * @param {boolean=} [isUiEvent=false] Whether the event is a UI event. * @param {string=} message Optional message to prepend assert messages. */ -function assertEventEquals(event, expectedType, +export function assertEventEquals(event, expectedType, expectedWorkspaceId, expectedBlockId, expectedProperties, isUiEvent = false, message) { let prependMessage = message ? message + ' ' : ''; prependMessage += 'Event fired '; @@ -107,7 +106,6 @@ function assertEventEquals(event, expectedType, chai.assert.isFalse(event.isUiEvent); } } -exports.assertEventEquals = assertEventEquals; /** * Asserts that an event with the given values was fired. @@ -119,7 +117,7 @@ exports.assertEventEquals = assertEventEquals; * @param {string} expectedWorkspaceId Expected workspace id of event fired. * @param {?string=} expectedBlockId Expected block id of event fired. */ -function assertEventFired(spy, instanceType, expectedProperties, +export function assertEventFired(spy, instanceType, expectedProperties, expectedWorkspaceId, expectedBlockId) { expectedProperties = Object.assign({ workspaceId: expectedWorkspaceId, @@ -129,7 +127,6 @@ function assertEventFired(spy, instanceType, expectedProperties, sinon.match.instanceOf(instanceType).and(sinon.match(expectedProperties)); sinon.assert.calledWith(spy, expectedEvent); } -exports.assertEventFired = assertEventFired; /** * Asserts that an event with the given values was not fired. @@ -141,7 +138,7 @@ exports.assertEventFired = assertEventFired; * @param {string=} expectedWorkspaceId Expected workspace id of event fired. * @param {?string=} expectedBlockId Expected block id of event fired. */ -function assertEventNotFired(spy, instanceType, expectedProperties, +export function assertEventNotFired(spy, instanceType, expectedProperties, expectedWorkspaceId, expectedBlockId) { expectedProperties.type = instanceType.prototype.type; if (expectedWorkspaceId !== undefined) { @@ -154,7 +151,6 @@ function assertEventNotFired(spy, instanceType, expectedProperties, sinon.match.instanceOf(instanceType).and(sinon.match(expectedProperties)); sinon.assert.neverCalledWith(spy, expectedEvent); } -exports.assertEventNotFired = assertEventNotFired; /** * Filters out xml properties from given object based on key. @@ -189,7 +185,7 @@ function splitByXmlProperties_(properties) { * @param {string} expectedWorkspaceId Expected workspace id of event fired. * @param {?string=} expectedBlockId Expected block id of event fired. */ -function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties, +export function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties, expectedWorkspaceId, expectedBlockId) { const nthCall = spy.getCall(n); const splitProperties = splitByXmlProperties_(expectedProperties); @@ -201,4 +197,3 @@ function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties, const eventArg = nthCall.firstArg; assertXmlProperties_(eventArg, xmlProperties); } -exports.assertNthCallEventArgEquals = assertNthCallEventArgEquals; diff --git a/tests/mocha/test_helpers/fields.js b/tests/mocha/test_helpers/fields.js index dd89e55fa..ce69e2eb3 100644 --- a/tests/mocha/test_helpers/fields.js +++ b/tests/mocha/test_helpers/fields.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.fields'); +goog.declareModuleId('Blockly.test.helpers.fields'); const {runTestCases, TestCase} = goog.require('Blockly.test.helpers.common'); @@ -14,7 +14,7 @@ const {runTestCases, TestCase} = goog.require('Blockly.test.helpers.common'); * @implements {TestCase} * @record */ -class FieldValueTestCase { +export class FieldValueTestCase { /** * Class for a a field value test case. */ @@ -39,14 +39,13 @@ class FieldValueTestCase { this.errMsgMatcher; } } -exports.FieldValueTestCase = FieldValueTestCase; /** * Field creation test case. * @extends {FieldValueTestCase} * @record */ -class FieldCreationTestCase { +export class FieldCreationTestCase { /** * Class for a field creation test case. */ @@ -61,7 +60,6 @@ class FieldCreationTestCase { this.json; } } -exports.FieldCreationTestCase = FieldCreationTestCase; /** * Assert a field's value is the same as the expected value. @@ -69,7 +67,7 @@ exports.FieldCreationTestCase = FieldCreationTestCase; * @param {*} expectedValue The expected value. * @param {string=} expectedText The expected text. */ -function assertFieldValue(field, expectedValue, expectedText = undefined) { +export function assertFieldValue(field, expectedValue, expectedText = undefined) { const actualValue = field.getValue(); const actualText = field.getText(); if (expectedText === undefined) { @@ -78,7 +76,6 @@ function assertFieldValue(field, expectedValue, expectedText = undefined) { chai.assert.equal(actualValue, expectedValue, 'Value'); chai.assert.equal(actualText, expectedText, 'Text'); } -exports.assertFieldValue = assertFieldValue; /** * Runs provided creation test cases. @@ -145,7 +142,7 @@ function runCreationTestsAssertThrows_(testCases, creation) { * @param {function(!FieldCreationTestCase=)=} customCreateWithJs Custom * creation function to use in tests. */ -function runConstructorSuiteTests(TestedField, validValueTestCases, +export function runConstructorSuiteTests(TestedField, validValueTestCases, invalidValueTestCases, validRunAssertField, assertFieldDefault, customCreateWithJs) { suite('Constructor', function() { @@ -182,7 +179,6 @@ function runConstructorSuiteTests(TestedField, validValueTestCases, runCreationTests_(validValueTestCases, validRunAssertField, createWithJs); }); } -exports.runConstructorSuiteTests = runConstructorSuiteTests; /** * Runs suite of tests for fromJson creation of specified field. @@ -200,7 +196,7 @@ exports.runConstructorSuiteTests = runConstructorSuiteTests; * @param {function(!FieldCreationTestCase=)=} customCreateWithJson Custom * creation function to use in tests. */ -function runFromJsonSuiteTests(TestedField, validValueTestCases, +export function runFromJsonSuiteTests(TestedField, validValueTestCases, invalidValueTestCases, validRunAssertField, assertFieldDefault, customCreateWithJson) { suite('fromJson', function() { @@ -237,7 +233,6 @@ function runFromJsonSuiteTests(TestedField, validValueTestCases, runCreationTests_(validValueTestCases, validRunAssertField, createWithJson); }); } -exports.runFromJsonSuiteTests = runFromJsonSuiteTests; /** * Runs tests for setValue calls. @@ -250,7 +245,7 @@ exports.runFromJsonSuiteTests = runFromJsonSuiteTests; * @param {string=} invalidRunExpectedText Expected text for field after invalid * call to setValue. */ -function runSetValueTests(validValueTestCases, invalidValueTestCases, +export function runSetValueTests(validValueTestCases, invalidValueTestCases, invalidRunExpectedValue, invalidRunExpectedText) { /** * Creates test callback for invalid setValue test. @@ -279,4 +274,3 @@ function runSetValueTests(validValueTestCases, invalidValueTestCases, runTestCases(invalidValueTestCases, createInvalidSetValueTestCallback); runTestCases(validValueTestCases, createValidSetValueTestCallback); } -exports.runSetValueTests = runSetValueTests; diff --git a/tests/mocha/test_helpers/procedures.js b/tests/mocha/test_helpers/procedures.js index 6978e283e..68c7f2f3d 100644 --- a/tests/mocha/test_helpers/procedures.js +++ b/tests/mocha/test_helpers/procedures.js @@ -3,7 +3,7 @@ * Copyright 2020 Google LLC * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.procedures'); +goog.declareModuleId('Blockly.test.helpers.procedures'); const {ConnectionType} = goog.require('Blockly.ConnectionType'); @@ -55,7 +55,7 @@ function assertCallBlockArgsStructure(callBlock, args) { * @param {boolean=} hasStatements If we expect the procedure def to have a * statement input or not. */ -function assertDefBlockStructure(defBlock, hasReturn = false, +export function assertDefBlockStructure(defBlock, hasReturn = false, args = [], varIds = [], hasStatements = true) { if (hasStatements) { chai.assert.isNotNull(defBlock.getInput('STACK'), @@ -82,7 +82,6 @@ function assertDefBlockStructure(defBlock, hasReturn = false, chai.assert.sameOrderedMembers(defBlock.getVars(), args); assertBlockVarModels(defBlock, varIds); } -exports.assertDefBlockStructure = assertDefBlockStructure; /** * Asserts that the procedure definition block has the expected inputs and @@ -91,7 +90,7 @@ exports.assertDefBlockStructure = assertDefBlockStructure; * @param {Array=} args An array of argument names. * @param {Array=} varIds An array of variable ids. */ -function assertCallBlockStructure(callBlock, args = [], varIds = []) { +export function assertCallBlockStructure(callBlock, args = [], varIds = []) { if (args.length) { chai.assert.include(callBlock.toString(), 'with'); } else { @@ -101,7 +100,6 @@ function assertCallBlockStructure(callBlock, args = [], varIds = []) { assertCallBlockArgsStructure(callBlock, args); assertBlockVarModels(callBlock, varIds); } -exports.assertCallBlockStructure = assertCallBlockStructure; /** * Creates procedure definition block using domToBlock call. @@ -111,7 +109,7 @@ exports.assertCallBlockStructure = assertCallBlockStructure; * @param {Array=} args An array of argument names. * @return {Blockly.Block} The created block. */ -function createProcDefBlock( +export function createProcDefBlock( workspace, hasReturn = false, args = []) { const type = hasReturn ? 'procedures_defreturn' : 'procedures_defnoreturn'; @@ -125,7 +123,6 @@ function createProcDefBlock( ''; return Blockly.Xml.domToBlock(Blockly.Xml.textToDom(xml), workspace); } -exports.createProcDefBlock = createProcDefBlock; /** * Creates procedure call block using domToBlock call. @@ -134,7 +131,7 @@ exports.createProcDefBlock = createProcDefBlock; * has return. * @return {Blockly.Block} The created block. */ -function createProcCallBlock( +export function createProcCallBlock( workspace, hasReturn = false) { const type = hasReturn ? 'procedures_callreturn' : 'procedures_callnoreturn'; @@ -144,4 +141,3 @@ function createProcCallBlock( '' ), workspace); } -exports.createProcCallBlock = createProcCallBlock; diff --git a/tests/mocha/test_helpers/serialization.js b/tests/mocha/test_helpers/serialization.js index c8b90ba7f..8aa4cc1f0 100644 --- a/tests/mocha/test_helpers/serialization.js +++ b/tests/mocha/test_helpers/serialization.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.serialization'); +goog.declareModuleId('Blockly.test.helpers.serialization'); const {runTestCases} = goog.require('Blockly.test.helpers.common'); @@ -13,7 +13,7 @@ const {runTestCases} = goog.require('Blockly.test.helpers.common'); * @implements {TestCase} * @record */ -class SerializationTestCase { +export class SerializationTestCase { /** * Class for a block serialization test case. */ @@ -45,13 +45,12 @@ class SerializationTestCase { */ assertBlockStructure(block) {} } -exports.SerializationTestCase = SerializationTestCase; /** * Runs serialization test suite. * @param {!Array} testCases The test cases to run. */ -const runSerializationTestSuite = (testCases) => { +export const runSerializationTestSuite = (testCases) => { /** * Creates test callback for xmlToBlock test. * @param {!SerializationTestCase} testCase The test case information. @@ -129,4 +128,3 @@ const runSerializationTestSuite = (testCases) => { }); }); }; -exports.runSerializationTestSuite = runSerializationTestSuite; diff --git a/tests/mocha/test_helpers/setup_teardown.js b/tests/mocha/test_helpers/setup_teardown.js index e1b085be1..3b66f7a9a 100644 --- a/tests/mocha/test_helpers/setup_teardown.js +++ b/tests/mocha/test_helpers/setup_teardown.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.setupTeardown'); +goog.declareModuleId('Blockly.test.helpers.setupTeardown'); const eventUtils = goog.require('Blockly.Events.utils'); const {Blocks} = goog.require('Blockly.blocks'); @@ -16,7 +16,7 @@ const {Blocks} = goog.require('Blockly.blocks'); * using workspaceTeardown.call(this). * @param {!Blockly.Workspace} workspace The workspace to dispose. */ -function workspaceTeardown(workspace) { +export function workspaceTeardown(workspace) { try { this.clock.runAll(); // Run all queued setTimeout calls. workspace.dispose(); @@ -26,7 +26,6 @@ function workspaceTeardown(workspace) { console.error(testRef.fullTitle() + '\n', e); } } -exports.workspaceTeardown = workspaceTeardown; /** * Creates stub for Blockly.Events.fire that advances the clock forward after @@ -53,10 +52,9 @@ function createEventsFireStubFireImmediately_(clock) { * sharedTestSetup. * @param {string} message The message to add to shared cleanup object. */ -function addMessageToCleanup(sharedCleanupObj, message) { +export function addMessageToCleanup(sharedCleanupObj, message) { sharedCleanupObj.messagesCleanup_.push(message); } -exports.addMessageToCleanup = addMessageToCleanup; /** * Adds block type to shared cleanup object so that it is cleaned from @@ -65,10 +63,9 @@ exports.addMessageToCleanup = addMessageToCleanup; * sharedTestSetup. * @param {string} blockType The block type to add to shared cleanup object. */ -function addBlockTypeToCleanup(sharedCleanupObj, blockType) { +export function addBlockTypeToCleanup(sharedCleanupObj, blockType) { sharedCleanupObj.blockTypesCleanup_.push(blockType); } -exports.addBlockTypeToCleanup = addBlockTypeToCleanup; /** * Wraps Blockly.defineBlocksWithJsonArray using stub in order to keep track of @@ -111,7 +108,7 @@ function wrapDefineBlocksWithJsonArrayWithCleanup_(sharedCleanupObj) { * @param {Object} options Options to enable/disable setup * of certain stubs. */ -function sharedTestSetup(options = {}) { +export function sharedTestSetup(options = {}) { this.sharedSetupCalled_ = true; // Sandbox created for greater control when certain stubs are cleared. this.sharedSetupSandbox_ = sinon.createSandbox(); @@ -128,14 +125,13 @@ function sharedTestSetup(options = {}) { this.messagesCleanup_ = this.sharedCleanup.messagesCleanup_; wrapDefineBlocksWithJsonArrayWithCleanup_(this.sharedCleanup); } -exports.sharedTestSetup = sharedTestSetup; /** * 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). */ -function sharedTestTeardown() { +export function sharedTestTeardown() { const testRef = this.currentTest || this.test; if (!this.sharedSetupCalled_) { console.error('"' + testRef.fullTitle() + '" did not call sharedTestSetup'); @@ -183,7 +179,6 @@ function sharedTestTeardown() { Blockly.WidgetDiv.testOnly_setDiv(null); } } -exports.sharedTestTeardown = sharedTestTeardown; /** * Creates stub for Blockly.utils.genUid that returns the provided id or ids. @@ -194,7 +189,7 @@ exports.sharedTestTeardown = sharedTestTeardown; * that value. * @return {!SinonStub} The created stub. */ -function createGenUidStubWithReturns(returnIds) { +export function createGenUidStubWithReturns(returnIds) { const stub = sinon.stub(Blockly.utils.idGenerator.TEST_ONLY, "genUid"); if (Array.isArray(returnIds)) { for (let i = 0; i < returnIds.length; i++) { @@ -205,4 +200,3 @@ function createGenUidStubWithReturns(returnIds) { } return stub; } -exports.createGenUidStubWithReturns = createGenUidStubWithReturns; diff --git a/tests/mocha/test_helpers/toolbox_definitions.js b/tests/mocha/test_helpers/toolbox_definitions.js index ee7ff576f..0a7f2b9ef 100644 --- a/tests/mocha/test_helpers/toolbox_definitions.js +++ b/tests/mocha/test_helpers/toolbox_definitions.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.toolboxDefinitions'); +goog.declareModuleId('Blockly.test.helpers.toolboxDefinitions'); /** @@ -12,7 +12,7 @@ goog.module('Blockly.test.helpers.toolboxDefinitions'); * @return {Blockly.utils.toolbox.ToolboxJson} The array holding information * for a toolbox. */ -function getCategoryJSON() { +export function getCategoryJSON() { return {"contents": [ { "kind": "CATEGORY", @@ -42,14 +42,13 @@ function getCategoryJSON() { "name": "Second", }]}; } -exports.getCategoryJSON = getCategoryJSON; /** * Get JSON for a simple toolbox. * @return {Blockly.utils.toolbox.ToolboxJson} The array holding information * for a simple toolbox. */ -function getSimpleJson() { +export function getSimpleJson() { return {"contents": [ { "kind": "BLOCK", @@ -83,9 +82,8 @@ function getSimpleJson() { }, ]}; } -exports.getSimpleJson = getSimpleJson; -function getProperSimpleJson() { +export function getProperSimpleJson() { return { "contents": [ { @@ -128,14 +126,13 @@ function getProperSimpleJson() { }, ]}; } -exports.getProperSimpleJson = getProperSimpleJson; /** * Get JSON for a toolbox that contains categories that contain categories. * @return {Blockly.utils.toolbox.ToolboxJson} The array holding information * for a toolbox. */ -function getDeeplyNestedJSON() { +export function getDeeplyNestedJSON() { return {"contents": [ { "kind": "CATEGORY", @@ -173,13 +170,12 @@ function getDeeplyNestedJSON() { "name": "Second", }]}; } -exports.getDeeplyNestedJSON = getDeeplyNestedJSON; /** * Get an array filled with xml elements. * @return {Array} Array holding xml elements for a toolbox. */ -function getXmlArray() { +export function getXmlArray() { const block = Blockly.Xml.textToDom( ` NEQ @@ -199,9 +195,8 @@ function getXmlArray() { const label = Blockly.Xml.textToDom(''); return [block, separator, button, label]; } -exports.getXmlArray = getXmlArray; -function getInjectedToolbox() { +export function getInjectedToolbox() { /** * Category: First * sep @@ -221,18 +216,16 @@ function getInjectedToolbox() { }); return workspace.getToolbox(); } -exports.getInjectedToolbox = getInjectedToolbox; -function getBasicToolbox() { +export function getBasicToolbox() { const workspace = new Blockly.WorkspaceSvg(new Blockly.Options({})); const toolbox = new Blockly.Toolbox(workspace); toolbox.HtmlDiv = document.createElement('div'); toolbox.flyout_ = sinon.createStubInstance(Blockly.VerticalFlyout); return toolbox; } -exports.getBasicToolbox = getBasicToolbox; -function getCollapsibleItem(toolbox) { +export function getCollapsibleItem(toolbox) { const contents = toolbox.contents_; for (let i = 0; i < contents.length; i++) { const item = contents[i]; @@ -241,9 +234,8 @@ function getCollapsibleItem(toolbox) { } } } -exports.getCollapsibleItem = getCollapsibleItem; -function getNonCollapsibleItem(toolbox) { +export function getNonCollapsibleItem(toolbox) { const contents = toolbox.contents_; for (let i = 0; i < contents.length; i++) { const item = contents[i]; @@ -252,14 +244,11 @@ function getNonCollapsibleItem(toolbox) { } } } -exports.getNonCollapsibleItem = getNonCollapsibleItem; -function getChildItem(toolbox) { +export function getChildItem(toolbox) { return toolbox.getToolboxItemById('nestedCategory'); } -exports.getChildItem = getChildItem; -function getSeparator(toolbox) { +export function getSeparator(toolbox) { return toolbox.getToolboxItemById('separator'); } -exports.getSeparator = getSeparator; diff --git a/tests/mocha/test_helpers/user_input.js b/tests/mocha/test_helpers/user_input.js index 9482a7909..2cae27bf1 100644 --- a/tests/mocha/test_helpers/user_input.js +++ b/tests/mocha/test_helpers/user_input.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.userInput'); +goog.declareModuleId('Blockly.test.helpers.userInput'); const {KeyCodes} = goog.require('Blockly.utils.KeyCodes'); @@ -17,7 +17,7 @@ const {KeyCodes} = goog.require('Blockly.utils.KeyCodes'); * @param {Object=} properties Properties to pass into event * constructor. */ -function dispatchPointerEvent(target, type, properties) { +export function dispatchPointerEvent(target, type, properties) { const eventInitDict = { cancelable: true, bubbles: true, @@ -32,7 +32,6 @@ function dispatchPointerEvent(target, type, properties) { const event = new PointerEvent(type, eventInitDict); target.dispatchEvent(event); } -exports.dispatchPointerEvent = dispatchPointerEvent; /** * Creates a key down event used for testing. @@ -40,7 +39,7 @@ exports.dispatchPointerEvent = dispatchPointerEvent; * @param {!Array=} modifiers A list of modifiers. Use Blockly.utils.KeyCodes enum. * @return {!KeyboardEvent} The mocked keydown event. */ -function createKeyDownEvent(keyCode, modifiers) { +export function createKeyDownEvent(keyCode, modifiers) { const event = { keyCode: keyCode, }; @@ -52,7 +51,6 @@ function createKeyDownEvent(keyCode, modifiers) { } return new KeyboardEvent('keydown', event); } -exports.createKeyDownEvent = createKeyDownEvent; /** * Simulates mouse click by triggering relevant mouse events. @@ -60,9 +58,8 @@ exports.createKeyDownEvent = createKeyDownEvent; * @param {Object=} properties Properties to pass into event * constructor. */ -function simulateClick(target, properties) { +export function simulateClick(target, properties) { dispatchPointerEvent(target, 'pointerdown', properties); dispatchPointerEvent(target, 'pointerup', properties); dispatchPointerEvent(target, 'click', properties); } -exports.simulateClick = simulateClick; diff --git a/tests/mocha/test_helpers/variables.js b/tests/mocha/test_helpers/variables.js index f550e960b..e75047c06 100644 --- a/tests/mocha/test_helpers/variables.js +++ b/tests/mocha/test_helpers/variables.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.variables'); +goog.declareModuleId('Blockly.test.helpers.variables'); /** @@ -15,11 +15,10 @@ goog.module('Blockly.test.helpers.variables'); * @param {!string} type The expected type of the variable. * @param {!string} id The expected id of the variable. */ -function assertVariableValues(container, name, type, id) { +export function assertVariableValues(container, name, type, id) { const variable = container.getVariableById(id); chai.assert.isDefined(variable); chai.assert.equal(variable.name, name); chai.assert.equal(variable.type, type); chai.assert.equal(variable.getId(), id); } -exports.assertVariableValues = assertVariableValues; diff --git a/tests/mocha/test_helpers/warnings.js b/tests/mocha/test_helpers/warnings.js index 0457395cc..4d8658573 100644 --- a/tests/mocha/test_helpers/warnings.js +++ b/tests/mocha/test_helpers/warnings.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.warnings'); +goog.declareModuleId('Blockly.test.helpers.warnings'); /** @@ -13,7 +13,7 @@ goog.module('Blockly.test.helpers.warnings'); * @param {Function} innerFunc The function where warnings may called. * @return {Array} The warning messages (only the first arguments). */ -function captureWarnings(innerFunc) { +export function captureWarnings(innerFunc) { const msgs = []; const nativeConsoleWarn = console.warn; try { @@ -26,7 +26,6 @@ function captureWarnings(innerFunc) { } return msgs; } -exports.captureWarnings = captureWarnings; /** * Asserts that the given function logs the provided warning messages. @@ -34,7 +33,7 @@ exports.captureWarnings = captureWarnings; * @param {Array|!RegExp} messages A list of regex for the expected * messages (in the expected order). */ -function assertWarnings(innerFunc, messages) { +export function assertWarnings(innerFunc, messages) { if (!Array.isArray(messages)) { messages = [messages]; } @@ -44,25 +43,22 @@ function assertWarnings(innerFunc, messages) { chai.assert.match(warnings[i], message); }); } -exports.assertWarnings = assertWarnings; /** * Asserts that the given function logs no warning messages. * @param {function()} innerFunc The function to call. */ -function assertNoWarnings(innerFunc) { +export function assertNoWarnings(innerFunc) { assertWarnings(innerFunc, []); } -exports.assertNoWarnings = assertNoWarnings; /** * Stubs Blockly.utils.deprecation.warn call. * @return {!SinonStub} The created stub. */ -function createDeprecationWarningStub() { +export function createDeprecationWarningStub() { return sinon.stub(Blockly.utils.deprecation, 'warn'); } -exports.createDeprecationWarningStub = createDeprecationWarningStub; /** * Asserts whether the given deprecation warning stub or call was called with @@ -71,10 +67,9 @@ exports.createDeprecationWarningStub = createDeprecationWarningStub; * @param {string} functionName The function name to check that the given spy or * spy call was called with. */ -function assertDeprecationWarningCall(spyOrSpyCall, functionName) { +export function assertDeprecationWarningCall(spyOrSpyCall, functionName) { sinon.assert.calledWith(spyOrSpyCall, functionName); } -exports.assertDeprecationWarningCall = assertDeprecationWarningCall; /** * Asserts that there was a single deprecation warning call with the given @@ -83,8 +78,7 @@ exports.assertDeprecationWarningCall = assertDeprecationWarningCall; * @param {string} functionName The function name to check that the given spy * was called with. */ -function assertSingleDeprecationWarningCall(spy, functionName) { +export function assertSingleDeprecationWarningCall(spy, functionName) { sinon.assert.calledOnce(spy); assertDeprecationWarningCall(spy.getCall(0), functionName); } -exports.assertSingleDeprecationWarningCall = assertSingleDeprecationWarningCall; diff --git a/tests/mocha/test_helpers/workspace.js b/tests/mocha/test_helpers/workspace.js index 204a46df6..ca1df2550 100644 --- a/tests/mocha/test_helpers/workspace.js +++ b/tests/mocha/test_helpers/workspace.js @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -goog.module('Blockly.test.helpers.workspace'); +goog.declareModuleId('Blockly.test.helpers.workspace'); const {assertVariableValues} = goog.require('Blockly.test.helpers.variables'); const {assertWarnings} = goog.require('Blockly.test.helpers.warnings'); @@ -12,7 +12,7 @@ const eventUtils = goog.require('Blockly.Events.utils'); const {workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown'); -function testAWorkspace() { +export function testAWorkspace() { setup(function() { Blockly.defineBlocksWithJsonArray([{ "type": "get_var_block", @@ -1528,4 +1528,3 @@ function testAWorkspace() { }); }); } -exports.testAWorkspace = testAWorkspace;