fix: revert converting test helpers to es modules (#5982)

* Revert "fix: lint"

This reverts commit 050956d105.

* Revert "fix: run mocha as a module"

This reverts commit 4dac25ae99.

* Revert "move to modules, but break mocha"

This reverts commit 220d7bbd1d.
This commit is contained in:
Beka Westberg
2022-03-09 07:38:37 -08:00
committed by GitHub
parent 3740d51089
commit 01d45972d4
17 changed files with 146 additions and 97 deletions

View File

@@ -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': '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/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/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'});

View File

@@ -1,7 +1,4 @@
{
"parserOptions": {
"sourceType": "module"
},
"env": {
"browser": true,
"mocha": true
@@ -14,8 +11,7 @@
"no-unused-vars": ["off"],
// Allow uncommented helper functions in tests.
"require-jsdoc": ["off"],
"prefer-rest-params": ["off"],
"no-invalid-this": ["off"]
"prefer-rest-params": ["off"]
},
"extends": "../../.eslintrc.json"
}

View File

@@ -11,7 +11,6 @@ const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('B
suite('ASTNode', function() {
console.log('1/a');
setup(function() {
sharedTestSetup.call(this);
Blockly.defineBlocksWithJsonArray([{
@@ -101,9 +100,7 @@ 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;
@@ -172,7 +169,6 @@ suite('ASTNode', function() {
});
suite('NavigationFunctions', function() {
console.log('b');
setup(function() {
Blockly.defineBlocksWithJsonArray([{
"type": "top_connection",
@@ -323,9 +319,7 @@ 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();

View File

@@ -172,7 +172,7 @@
<block type="test_field_block"></block>
</xml>
<script type="module">
<script>
let runner = mocha.run(function(failures) {
var failureDiv = document.getElementById('failureCount');
failureDiv.setAttribute('tests_failed', failures);

View File

@@ -4,10 +4,10 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.blockDefinitions');
goog.module('Blockly.test.helpers.blockDefinitions');
export function defineStackBlock(name = 'stack_block') {
function defineStackBlock(name = 'stack_block') {
Blockly.defineBlocksWithJsonArray([{
"type": name,
"message0": "",
@@ -15,8 +15,9 @@ export function defineStackBlock(name = 'stack_block') {
"nextStatement": null,
}]);
}
exports.defineStackBlock = defineStackBlock;
export function defineRowBlock(name = 'row_block') {
function defineRowBlock(name = 'row_block') {
Blockly.defineBlocksWithJsonArray([{
"type": name,
"message0": "%1",
@@ -29,8 +30,9 @@ export function defineRowBlock(name = 'row_block') {
"output": null,
}]);
}
exports.defineRowBlock = defineRowBlock;
export function defineStatementBlock(name = 'statement_block') {
function defineStatementBlock(name = 'statement_block') {
Blockly.defineBlocksWithJsonArray([{
"type": name,
"message0": "%1",
@@ -47,8 +49,9 @@ export function defineStatementBlock(name = 'statement_block') {
"helpUrl": "",
}]);
}
exports.defineStatementBlock = defineStatementBlock;
export function defineBasicBlockWithField(name = 'test_field_block') {
function defineBasicBlockWithField(name = 'test_field_block') {
Blockly.defineBlocksWithJsonArray([{
"type": name,
"message0": "%1",
@@ -61,8 +64,9 @@ export function defineBasicBlockWithField(name = 'test_field_block') {
"output": null,
}]);
}
exports.defineBasicBlockWithField = defineBasicBlockWithField;
export function defineMutatorBlocks() {
function defineMutatorBlocks() {
Blockly.defineBlocksWithJsonArray([
{
'type': 'xml_block',
@@ -154,8 +158,9 @@ export function defineMutatorBlocks() {
};
Blockly.Extensions.registerMutator('jso_mutator', jsoMutator);
}
exports.defineMutatorBlocks = defineMutatorBlocks;
export function createTestBlock() {
function createTestBlock() {
return {
'id': 'test',
'rendered': false,
@@ -169,10 +174,12 @@ export function createTestBlock() {
'updateVarName': Blockly.Block.prototype.updateVarName,
};
}
exports.createTestBlock = createTestBlock;
export function createRenderedBlock(workspaceSvg, type) {
function createRenderedBlock(workspaceSvg, type) {
const block = workspaceSvg.newBlock(type);
block.initSvg();
block.render();
return block;
}
exports.createRenderedBlock = createRenderedBlock;

View File

@@ -5,7 +5,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.codeGeneration');
goog.module('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
*/
export class CodeGenerationTestCase {
class CodeGenerationTestCase {
/**
* Class for a code generation test case.
*/
@@ -43,13 +43,14 @@ export class CodeGenerationTestCase {
*/
createBlock(workspace) {}
}
exports.CodeGenerationTestCase = CodeGenerationTestCase;
/**
* Code generation test suite.
* @extends {TestSuite<CodeGenerationTestCase, CodeGenerationTestSuite>}
* @record
*/
export class CodeGenerationTestSuite {
class CodeGenerationTestSuite {
/**
* Class for a code generation test suite.
*/
@@ -60,6 +61,7 @@ export class CodeGenerationTestSuite {
this.generator;
}
}
exports.CodeGenerationTestSuite = CodeGenerationTestSuite;
/**
* Returns mocha test callback for code generation based on provided
@@ -100,7 +102,7 @@ const createCodeGenerationTestFn_ = (generator) => {
* Runs blockToCode test suites.
* @param {!Array<!CodeGenerationTestSuite>} testSuites The test suites to run.
*/
export const runCodeGenerationTestSuites = (testSuites) => {
const runCodeGenerationTestSuites = (testSuites) => {
/**
* Creates function used to generate mocha test callback.
* @param {!CodeGenerationTestSuite} suiteInfo The test suite information.
@@ -113,3 +115,4 @@ export const runCodeGenerationTestSuites = (testSuites) => {
runTestSuites(testSuites, createTestFn);
};
exports.runCodeGenerationTestSuites = runCodeGenerationTestSuites;

View File

@@ -4,13 +4,13 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.common');
goog.module('Blockly.test.helpers.common');
/**
* Test case configuration.
* @record
*/
export class TestCase {
class TestCase {
/**
* Class for a test case configuration.
*/
@@ -31,6 +31,7 @@ export class TestCase {
this.only;
}
}
exports.TestCase = TestCase;
/**
* Test suite configuration.
@@ -38,7 +39,7 @@ export class TestCase {
* @template {TestCase} T
* @template {TestSuite} U
*/
export class TestSuite {
class TestSuite {
/**
* Class for a test suite configuration.
*/
@@ -67,6 +68,7 @@ export class TestSuite {
this.only;
}
}
exports.TestSuite = TestSuite;
/**
* Runs provided test cases.
@@ -75,13 +77,14 @@ export class TestSuite {
* @param {function(T):Function} createTestCallback Creates test
* callback using given test case.
*/
export function runTestCases(testCases, createTestCallback) {
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.
@@ -92,7 +95,7 @@ export function runTestCases(testCases, createTestCallback) {
* } createTestCaseCallback Creates test case callback using given test
* suite.
*/
export function runTestSuites(testSuites, createTestCaseCallback) {
function runTestSuites(testSuites, createTestCaseCallback) {
testSuites.forEach((testSuite) => {
let suiteCall = (testSuite.skip ? suite.skip : suite);
suiteCall = (testSuite.only ? suite.only : suiteCall);
@@ -106,3 +109,4 @@ export function runTestSuites(testSuites, createTestCaseCallback) {
});
});
}
exports.runTestSuites = runTestSuites;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.events');
goog.module('Blockly.test.helpers.events');
/**
@@ -13,9 +13,10 @@ goog.declareModuleId('Blockly.test.helpers.events');
* calls on.
* @return {!SinonSpy} The created spy.
*/
export function createFireChangeListenerSpy(workspace) {
function createFireChangeListenerSpy(workspace) {
return sinon.spy(workspace, 'fireChangeListener');
}
exports.createFireChangeListenerSpy = createFireChangeListenerSpy;
/**
* Asserts whether the given xml property has the expected property.
@@ -74,7 +75,7 @@ function isXmlProperty_(key) {
* @param {boolean=} [isUiEvent=false] Whether the event is a UI event.
* @param {string=} message Optional message to prepend assert messages.
*/
export function assertEventEquals(event, expectedType,
function assertEventEquals(event, expectedType,
expectedWorkspaceId, expectedBlockId, expectedProperties, isUiEvent = false, message) {
let prependMessage = message ? message + ' ' : '';
prependMessage += 'Event fired ';
@@ -106,6 +107,7 @@ export function assertEventEquals(event, expectedType,
chai.assert.isFalse(event.isUiEvent);
}
}
exports.assertEventEquals = assertEventEquals;
/**
* Asserts that an event with the given values was fired.
@@ -117,7 +119,7 @@ export function assertEventEquals(event, expectedType,
* @param {string} expectedWorkspaceId Expected workspace id of event fired.
* @param {?string=} expectedBlockId Expected block id of event fired.
*/
export function assertEventFired(spy, instanceType, expectedProperties,
function assertEventFired(spy, instanceType, expectedProperties,
expectedWorkspaceId, expectedBlockId) {
expectedProperties = Object.assign({
workspaceId: expectedWorkspaceId,
@@ -127,6 +129,7 @@ export 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.
@@ -138,7 +141,7 @@ export function assertEventFired(spy, instanceType, expectedProperties,
* @param {string=} expectedWorkspaceId Expected workspace id of event fired.
* @param {?string=} expectedBlockId Expected block id of event fired.
*/
export function assertEventNotFired(spy, instanceType, expectedProperties,
function assertEventNotFired(spy, instanceType, expectedProperties,
expectedWorkspaceId, expectedBlockId) {
expectedProperties.type = instanceType.prototype.type;
if (expectedWorkspaceId !== undefined) {
@@ -151,6 +154,7 @@ export 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.
@@ -185,7 +189,7 @@ function splitByXmlProperties_(properties) {
* @param {string} expectedWorkspaceId Expected workspace id of event fired.
* @param {?string=} expectedBlockId Expected block id of event fired.
*/
export function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
function assertNthCallEventArgEquals(spy, n, instanceType, expectedProperties,
expectedWorkspaceId, expectedBlockId) {
const nthCall = spy.getCall(n);
const splitProperties = splitByXmlProperties_(expectedProperties);
@@ -197,3 +201,4 @@ export function assertNthCallEventArgEquals(spy, n, instanceType, expectedProper
const eventArg = nthCall.firstArg;
assertXmlProperties_(eventArg, xmlProperties);
}
exports.assertNthCallEventArgEquals = assertNthCallEventArgEquals;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.fields');
goog.module('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
*/
export class FieldValueTestCase {
class FieldValueTestCase {
/**
* Class for a a field value test case.
*/
@@ -39,13 +39,14 @@ export class FieldValueTestCase {
this.errMsgMatcher;
}
}
exports.FieldValueTestCase = FieldValueTestCase;
/**
* Field creation test case.
* @extends {FieldValueTestCase}
* @record
*/
export class FieldCreationTestCase {
class FieldCreationTestCase {
/**
* Class for a field creation test case.
*/
@@ -60,6 +61,7 @@ export class FieldCreationTestCase {
this.json;
}
}
exports.FieldCreationTestCase = FieldCreationTestCase;
/**
* Assert a field's value is the same as the expected value.
@@ -67,7 +69,7 @@ export class FieldCreationTestCase {
* @param {*} expectedValue The expected value.
* @param {string=} expectedText The expected text.
*/
export function assertFieldValue(field, expectedValue, expectedText = undefined) {
function assertFieldValue(field, expectedValue, expectedText = undefined) {
const actualValue = field.getValue();
const actualText = field.getText();
if (expectedText === undefined) {
@@ -76,6 +78,7 @@ export 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.
@@ -142,7 +145,7 @@ function runCreationTestsAssertThrows_(testCases, creation) {
* @param {function(!FieldCreationTestCase=)=} customCreateWithJs Custom
* creation function to use in tests.
*/
export function runConstructorSuiteTests(TestedField, validValueTestCases,
function runConstructorSuiteTests(TestedField, validValueTestCases,
invalidValueTestCases, validRunAssertField, assertFieldDefault,
customCreateWithJs) {
suite('Constructor', function() {
@@ -179,6 +182,7 @@ export function runConstructorSuiteTests(TestedField, validValueTestCases,
runCreationTests_(validValueTestCases, validRunAssertField, createWithJs);
});
}
exports.runConstructorSuiteTests = runConstructorSuiteTests;
/**
* Runs suite of tests for fromJson creation of specified field.
@@ -196,7 +200,7 @@ export function runConstructorSuiteTests(TestedField, validValueTestCases,
* @param {function(!FieldCreationTestCase=)=} customCreateWithJson Custom
* creation function to use in tests.
*/
export function runFromJsonSuiteTests(TestedField, validValueTestCases,
function runFromJsonSuiteTests(TestedField, validValueTestCases,
invalidValueTestCases, validRunAssertField, assertFieldDefault,
customCreateWithJson) {
suite('fromJson', function() {
@@ -233,6 +237,7 @@ export function runFromJsonSuiteTests(TestedField, validValueTestCases,
runCreationTests_(validValueTestCases, validRunAssertField, createWithJson);
});
}
exports.runFromJsonSuiteTests = runFromJsonSuiteTests;
/**
* Runs tests for setValue calls.
@@ -245,7 +250,7 @@ export function runFromJsonSuiteTests(TestedField, validValueTestCases,
* @param {string=} invalidRunExpectedText Expected text for field after invalid
* call to setValue.
*/
export function runSetValueTests(validValueTestCases, invalidValueTestCases,
function runSetValueTests(validValueTestCases, invalidValueTestCases,
invalidRunExpectedValue, invalidRunExpectedText) {
/**
* Creates test callback for invalid setValue test.
@@ -274,3 +279,4 @@ export function runSetValueTests(validValueTestCases, invalidValueTestCases,
runTestCases(invalidValueTestCases, createInvalidSetValueTestCallback);
runTestCases(validValueTestCases, createValidSetValueTestCallback);
}
exports.runSetValueTests = runSetValueTests;

View File

@@ -3,7 +3,7 @@
* Copyright 2020 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.procedures');
goog.module('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.
*/
export function assertDefBlockStructure(defBlock, hasReturn = false,
function assertDefBlockStructure(defBlock, hasReturn = false,
args = [], varIds = [], hasStatements = true) {
if (hasStatements) {
chai.assert.isNotNull(defBlock.getInput('STACK'),
@@ -82,6 +82,7 @@ export 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
@@ -90,7 +91,7 @@ export function assertDefBlockStructure(defBlock, hasReturn = false,
* @param {Array<string>=} args An array of argument names.
* @param {Array<string>=} varIds An array of variable ids.
*/
export function assertCallBlockStructure(callBlock, args = [], varIds = []) {
function assertCallBlockStructure(callBlock, args = [], varIds = []) {
if (args.length) {
chai.assert.include(callBlock.toString(), 'with');
} else {
@@ -100,6 +101,7 @@ export function assertCallBlockStructure(callBlock, args = [], varIds = []) {
assertCallBlockArgsStructure(callBlock, args);
assertBlockVarModels(callBlock, varIds);
}
exports.assertCallBlockStructure = assertCallBlockStructure;
/**
* Creates procedure definition block using domToBlock call.
@@ -109,7 +111,7 @@ export function assertCallBlockStructure(callBlock, args = [], varIds = []) {
* @param {Array<string>=} args An array of argument names.
* @return {Blockly.Block} The created block.
*/
export function createProcDefBlock(
function createProcDefBlock(
workspace, hasReturn = false, args = []) {
const type = hasReturn ?
'procedures_defreturn' : 'procedures_defnoreturn';
@@ -123,6 +125,7 @@ export function createProcDefBlock(
'</block>';
return Blockly.Xml.domToBlock(Blockly.Xml.textToDom(xml), workspace);
}
exports.createProcDefBlock = createProcDefBlock;
/**
* Creates procedure call block using domToBlock call.
@@ -131,7 +134,7 @@ export function createProcDefBlock(
* has return.
* @return {Blockly.Block} The created block.
*/
export function createProcCallBlock(
function createProcCallBlock(
workspace, hasReturn = false) {
const type = hasReturn ?
'procedures_callreturn' : 'procedures_callnoreturn';
@@ -141,3 +144,4 @@ export function createProcCallBlock(
'</block>'
), workspace);
}
exports.createProcCallBlock = createProcCallBlock;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.serialization');
goog.module('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
*/
export class SerializationTestCase {
class SerializationTestCase {
/**
* Class for a block serialization test case.
*/
@@ -45,12 +45,13 @@ export class SerializationTestCase {
*/
assertBlockStructure(block) {}
}
exports.SerializationTestCase = SerializationTestCase;
/**
* Runs serialization test suite.
* @param {!Array<!SerializationTestCase>} testCases The test cases to run.
*/
export const runSerializationTestSuite = (testCases) => {
const runSerializationTestSuite = (testCases) => {
/**
* Creates test callback for xmlToBlock test.
* @param {!SerializationTestCase} testCase The test case information.
@@ -128,3 +129,4 @@ export const runSerializationTestSuite = (testCases) => {
});
});
};
exports.runSerializationTestSuite = runSerializationTestSuite;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.setupTeardown');
goog.module('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.
*/
export function workspaceTeardown(workspace) {
function workspaceTeardown(workspace) {
try {
this.clock.runAll(); // Run all queued setTimeout calls.
workspace.dispose();
@@ -26,6 +26,7 @@ export function workspaceTeardown(workspace) {
console.error(testRef.fullTitle() + '\n', e);
}
}
exports.workspaceTeardown = workspaceTeardown;
/**
* Creates stub for Blockly.Events.fire that advances the clock forward after
@@ -52,9 +53,10 @@ function createEventsFireStubFireImmediately_(clock) {
* sharedTestSetup.
* @param {string} message The message to add to shared cleanup object.
*/
export function addMessageToCleanup(sharedCleanupObj, message) {
function addMessageToCleanup(sharedCleanupObj, message) {
sharedCleanupObj.messagesCleanup_.push(message);
}
exports.addMessageToCleanup = addMessageToCleanup;
/**
* Adds block type to shared cleanup object so that it is cleaned from
@@ -63,9 +65,10 @@ export function addMessageToCleanup(sharedCleanupObj, message) {
* sharedTestSetup.
* @param {string} blockType The block type to add to shared cleanup object.
*/
export function addBlockTypeToCleanup(sharedCleanupObj, blockType) {
function addBlockTypeToCleanup(sharedCleanupObj, blockType) {
sharedCleanupObj.blockTypesCleanup_.push(blockType);
}
exports.addBlockTypeToCleanup = addBlockTypeToCleanup;
/**
* Wraps Blockly.defineBlocksWithJsonArray using stub in order to keep track of
@@ -108,7 +111,7 @@ function wrapDefineBlocksWithJsonArrayWithCleanup_(sharedCleanupObj) {
* @param {Object<string, boolean>} options Options to enable/disable setup
* of certain stubs.
*/
export function sharedTestSetup(options = {}) {
function sharedTestSetup(options = {}) {
this.sharedSetupCalled_ = true;
// Sandbox created for greater control when certain stubs are cleared.
this.sharedSetupSandbox_ = sinon.createSandbox();
@@ -125,13 +128,14 @@ export 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).
*/
export function sharedTestTeardown() {
function sharedTestTeardown() {
const testRef = this.currentTest || this.test;
if (!this.sharedSetupCalled_) {
console.error('"' + testRef.fullTitle() + '" did not call sharedTestSetup');
@@ -179,6 +183,7 @@ export function sharedTestTeardown() {
Blockly.WidgetDiv.testOnly_setDiv(null);
}
}
exports.sharedTestTeardown = sharedTestTeardown;
/**
* Creates stub for Blockly.utils.genUid that returns the provided id or ids.
@@ -189,7 +194,7 @@ export function sharedTestTeardown() {
* that value.
* @return {!SinonStub} The created stub.
*/
export function createGenUidStubWithReturns(returnIds) {
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++) {
@@ -200,3 +205,4 @@ export function createGenUidStubWithReturns(returnIds) {
}
return stub;
}
exports.createGenUidStubWithReturns = createGenUidStubWithReturns;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.toolboxDefinitions');
goog.module('Blockly.test.helpers.toolboxDefinitions');
/**
@@ -12,7 +12,7 @@ goog.declareModuleId('Blockly.test.helpers.toolboxDefinitions');
* @return {Blockly.utils.toolbox.ToolboxJson} The array holding information
* for a toolbox.
*/
export function getCategoryJSON() {
function getCategoryJSON() {
return {"contents": [
{
"kind": "CATEGORY",
@@ -42,13 +42,14 @@ export 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.
*/
export function getSimpleJson() {
function getSimpleJson() {
return {"contents": [
{
"kind": "BLOCK",
@@ -82,8 +83,9 @@ export function getSimpleJson() {
},
]};
}
exports.getSimpleJson = getSimpleJson;
export function getProperSimpleJson() {
function getProperSimpleJson() {
return {
"contents": [
{
@@ -126,13 +128,14 @@ export 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.
*/
export function getDeeplyNestedJSON() {
function getDeeplyNestedJSON() {
return {"contents": [
{
"kind": "CATEGORY",
@@ -170,12 +173,13 @@ export function getDeeplyNestedJSON() {
"name": "Second",
}]};
}
exports.getDeeplyNestedJSON = getDeeplyNestedJSON;
/**
* Get an array filled with xml elements.
* @return {Array<Node>} Array holding xml elements for a toolbox.
*/
export function getXmlArray() {
function getXmlArray() {
const block = Blockly.Xml.textToDom(
`<block type="logic_compare">
<field name="OP">NEQ</field>
@@ -195,8 +199,9 @@ export function getXmlArray() {
const label = Blockly.Xml.textToDom('<label text="tooltips"></label>');
return [block, separator, button, label];
}
exports.getXmlArray = getXmlArray;
export function getInjectedToolbox() {
function getInjectedToolbox() {
/**
* Category: First
* sep
@@ -216,16 +221,18 @@ export function getInjectedToolbox() {
});
return workspace.getToolbox();
}
exports.getInjectedToolbox = getInjectedToolbox;
export function getBasicToolbox() {
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;
export function getCollapsibleItem(toolbox) {
function getCollapsibleItem(toolbox) {
const contents = toolbox.contents_;
for (let i = 0; i < contents.length; i++) {
const item = contents[i];
@@ -234,8 +241,9 @@ export function getCollapsibleItem(toolbox) {
}
}
}
exports.getCollapsibleItem = getCollapsibleItem;
export function getNonCollapsibleItem(toolbox) {
function getNonCollapsibleItem(toolbox) {
const contents = toolbox.contents_;
for (let i = 0; i < contents.length; i++) {
const item = contents[i];
@@ -244,11 +252,14 @@ export function getNonCollapsibleItem(toolbox) {
}
}
}
exports.getNonCollapsibleItem = getNonCollapsibleItem;
export function getChildItem(toolbox) {
function getChildItem(toolbox) {
return toolbox.getToolboxItemById('nestedCategory');
}
exports.getChildItem = getChildItem;
export function getSeparator(toolbox) {
function getSeparator(toolbox) {
return toolbox.getToolboxItemById('separator');
}
exports.getSeparator = getSeparator;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.userInput');
goog.module('Blockly.test.helpers.userInput');
const {KeyCodes} = goog.require('Blockly.utils.KeyCodes');
@@ -17,7 +17,7 @@ const {KeyCodes} = goog.require('Blockly.utils.KeyCodes');
* @param {Object<string, string>=} properties Properties to pass into event
* constructor.
*/
export function dispatchPointerEvent(target, type, properties) {
function dispatchPointerEvent(target, type, properties) {
const eventInitDict = {
cancelable: true,
bubbles: true,
@@ -32,6 +32,7 @@ export 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.
@@ -39,7 +40,7 @@ export function dispatchPointerEvent(target, type, properties) {
* @param {!Array<number>=} modifiers A list of modifiers. Use Blockly.utils.KeyCodes enum.
* @return {!KeyboardEvent} The mocked keydown event.
*/
export function createKeyDownEvent(keyCode, modifiers) {
function createKeyDownEvent(keyCode, modifiers) {
const event = {
keyCode: keyCode,
};
@@ -51,6 +52,7 @@ export function createKeyDownEvent(keyCode, modifiers) {
}
return new KeyboardEvent('keydown', event);
}
exports.createKeyDownEvent = createKeyDownEvent;
/**
* Simulates mouse click by triggering relevant mouse events.
@@ -58,8 +60,9 @@ export function createKeyDownEvent(keyCode, modifiers) {
* @param {Object<string, string>=} properties Properties to pass into event
* constructor.
*/
export function simulateClick(target, properties) {
function simulateClick(target, properties) {
dispatchPointerEvent(target, 'pointerdown', properties);
dispatchPointerEvent(target, 'pointerup', properties);
dispatchPointerEvent(target, 'click', properties);
}
exports.simulateClick = simulateClick;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.variables');
goog.module('Blockly.test.helpers.variables');
/**
@@ -15,10 +15,11 @@ goog.declareModuleId('Blockly.test.helpers.variables');
* @param {!string} type The expected type of the variable.
* @param {!string} id The expected id of the variable.
*/
export function assertVariableValues(container, name, type, id) {
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;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.warnings');
goog.module('Blockly.test.helpers.warnings');
/**
@@ -13,7 +13,7 @@ goog.declareModuleId('Blockly.test.helpers.warnings');
* @param {Function} innerFunc The function where warnings may called.
* @return {Array<string>} The warning messages (only the first arguments).
*/
export function captureWarnings(innerFunc) {
function captureWarnings(innerFunc) {
const msgs = [];
const nativeConsoleWarn = console.warn;
try {
@@ -26,6 +26,7 @@ export function captureWarnings(innerFunc) {
}
return msgs;
}
exports.captureWarnings = captureWarnings;
/**
* Asserts that the given function logs the provided warning messages.
@@ -33,7 +34,7 @@ export function captureWarnings(innerFunc) {
* @param {Array<!RegExp>|!RegExp} messages A list of regex for the expected
* messages (in the expected order).
*/
export function assertWarnings(innerFunc, messages) {
function assertWarnings(innerFunc, messages) {
if (!Array.isArray(messages)) {
messages = [messages];
}
@@ -43,22 +44,25 @@ export 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.
*/
export function assertNoWarnings(innerFunc) {
function assertNoWarnings(innerFunc) {
assertWarnings(innerFunc, []);
}
exports.assertNoWarnings = assertNoWarnings;
/**
* Stubs Blockly.utils.deprecation.warn call.
* @return {!SinonStub} The created stub.
*/
export function createDeprecationWarningStub() {
function createDeprecationWarningStub() {
return sinon.stub(Blockly.utils.deprecation, 'warn');
}
exports.createDeprecationWarningStub = createDeprecationWarningStub;
/**
* Asserts whether the given deprecation warning stub or call was called with
@@ -67,9 +71,10 @@ export function createDeprecationWarningStub() {
* @param {string} functionName The function name to check that the given spy or
* spy call was called with.
*/
export function assertDeprecationWarningCall(spyOrSpyCall, functionName) {
function assertDeprecationWarningCall(spyOrSpyCall, functionName) {
sinon.assert.calledWith(spyOrSpyCall, functionName);
}
exports.assertDeprecationWarningCall = assertDeprecationWarningCall;
/**
* Asserts that there was a single deprecation warning call with the given
@@ -78,7 +83,8 @@ export function assertDeprecationWarningCall(spyOrSpyCall, functionName) {
* @param {string} functionName The function name to check that the given spy
* was called with.
*/
export function assertSingleDeprecationWarningCall(spy, functionName) {
function assertSingleDeprecationWarningCall(spy, functionName) {
sinon.assert.calledOnce(spy);
assertDeprecationWarningCall(spy.getCall(0), functionName);
}
exports.assertSingleDeprecationWarningCall = assertSingleDeprecationWarningCall;

View File

@@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
goog.declareModuleId('Blockly.test.helpers.workspace');
goog.module('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');
export function testAWorkspace() {
function testAWorkspace() {
setup(function() {
Blockly.defineBlocksWithJsonArray([{
"type": "get_var_block",
@@ -1528,3 +1528,4 @@ export function testAWorkspace() {
});
});
}
exports.testAWorkspace = testAWorkspace;