From 2e92123314b46bafef024b530ae3c1e29f566d55 Mon Sep 17 00:00:00 2001 From: Monica Kozbial Date: Wed, 5 Aug 2020 16:00:00 -0700 Subject: [PATCH] Adding async cleanup to tests (#4103) * Adding setup and teardown to more mocha tests. * Update workspace dispose cleanup calls. --- tests/mocha/astnode_test.js | 5 ++--- tests/mocha/block_test.js | 8 +++---- tests/mocha/connection_checker_test.js | 6 +++++ tests/mocha/connection_db_test.js | 22 +++++++++---------- tests/mocha/connection_test.js | 11 ++++++---- tests/mocha/cursor_test.js | 4 ++-- tests/mocha/dropdowndiv_test.js | 6 ++--- tests/mocha/extensions_test.js | 12 ++++------ tests/mocha/field_angle_test.js | 6 +++++ tests/mocha/field_checkbox_test.js | 6 +++++ tests/mocha/field_colour_test.js | 6 +++++ tests/mocha/field_dropdown_test.js | 6 +++++ tests/mocha/field_image_test.js | 6 +++++ tests/mocha/field_label_serializable_test.js | 6 +++++ tests/mocha/field_label_test.js | 6 +++++ tests/mocha/field_number_test.js | 6 +++++ tests/mocha/field_registry_test.js | 5 +++++ tests/mocha/field_test.js | 6 +++++ tests/mocha/field_textinput_test.js | 6 +++++ tests/mocha/field_variable_test.js | 4 ++-- tests/mocha/flyout_test.js | 4 ++-- tests/mocha/generator_test.js | 3 ++- tests/mocha/gesture_test.js | 3 ++- tests/mocha/input_test.js | 6 ++--- tests/mocha/json_test.js | 3 ++- tests/mocha/key_map_test.js | 4 ++++ tests/mocha/logic_ternary_test.js | 3 ++- tests/mocha/metrics_test.js | 7 ++++++ tests/mocha/names_test.js | 6 +++++ tests/mocha/navigation_test.js | 23 +++++++++++++------- tests/mocha/registry_test.js | 4 ++++ tests/mocha/test_helpers.js | 1 - tests/mocha/toolbox_test.js | 8 +++---- tests/mocha/utils_test.js | 7 ++++++ tests/mocha/variable_map_test.js | 4 ++-- tests/mocha/variable_model_test.js | 3 ++- tests/mocha/variables_test.js | 8 ++----- tests/mocha/widget_div_test.js | 6 +++++ tests/mocha/workspace_test.js | 2 +- tests/mocha/xml_procedures_test.js | 7 ++++++ 40 files changed, 183 insertions(+), 72 deletions(-) diff --git a/tests/mocha/astnode_test.js b/tests/mocha/astnode_test.js index 793bdcf9a..6e12f74c0 100644 --- a/tests/mocha/astnode_test.js +++ b/tests/mocha/astnode_test.js @@ -6,6 +6,7 @@ suite('ASTNode', function() { setup(function() { + sharedTestSetup.call(this); Blockly.defineBlocksWithJsonArray([{ "type": "input_statement", "message0": "%1 %2 %3 %4", @@ -90,12 +91,10 @@ suite('ASTNode', function() { sinon.stub(Blockly, "getMainWorkspace").returns(new Blockly.Workspace()); }); teardown(function() { + sharedTestTeardown.call(this); delete Blockly.Blocks['input_statement']; delete Blockly.Blocks['field_input']; delete Blockly.Blocks['value_input']; - - this.workspace.dispose(); - sinon.restore(); }); suite('HelperFunctions', function() { diff --git a/tests/mocha/block_test.js b/tests/mocha/block_test.js index 13982f14c..3581febac 100644 --- a/tests/mocha/block_test.js +++ b/tests/mocha/block_test.js @@ -1077,7 +1077,7 @@ suite('Blocks', function() { ), this.workspace); }); teardown(function() { - this.workspace.dispose(); + workspaceTeardown.call(this, this.workspace); }); test('Text', function() { this.block.setCommentText('test text'); @@ -1139,11 +1139,11 @@ suite('Blocks', function() { suite('Icon Management', function() { suite('Bubbles and Collapsing', function() { setup(function() { - this.workspace.dispose(); + workspaceTeardown.call(this, this.workspace); this.workspace = Blockly.inject('blocklyDiv'); }); teardown(function() { - this.workspace.dispose(); + workspaceTeardown.call(this, this.workspace); }); test('Has Icon', function() { @@ -1653,7 +1653,7 @@ suite('Blocks', function() { }), {}); }); teardown(function() { - this.workspace.dispose(); + workspaceTeardown.call(this, this.workspace); // Clear all registered themes. Blockly.registry.typeMap_['theme'] = {}; }); diff --git a/tests/mocha/connection_checker_test.js b/tests/mocha/connection_checker_test.js index 82528107d..cb6b126db 100644 --- a/tests/mocha/connection_checker_test.js +++ b/tests/mocha/connection_checker_test.js @@ -5,6 +5,12 @@ */ suite('Connection checker', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); suiteSetup(function() { this.checker = new Blockly.ConnectionChecker(); }); diff --git a/tests/mocha/connection_db_test.js b/tests/mocha/connection_db_test.js index 9e43308f0..091503721 100644 --- a/tests/mocha/connection_db_test.js +++ b/tests/mocha/connection_db_test.js @@ -6,6 +6,7 @@ suite('Connection Database', function() { setup(function() { + sharedTestSetup.call(this); this.database = new Blockly.ConnectionDB(new Blockly.ConnectionChecker()); this.assertOrder = function() { @@ -33,6 +34,9 @@ suite('Connection Database', function() { } }; }); + teardown(function() { + sharedTestTeardown.call(this); + }); test('Add Connection', function() { var y2 = {y: 2}; var y4 = {y: 4}; @@ -193,22 +197,21 @@ suite('Connection Database', function() { suite('Search For Closest', function() { setup(function() { - this.allowedStubs = []; // Ignore type checks. - this.allowedStubs.push(sinon.stub(this.database.connectionChecker_, 'doTypeChecks') + sinon.stub(this.database.connectionChecker_, 'doTypeChecks') .callsFake(function(_a, _b) { return true; - })); + }); // Ignore safety checks. - this.allowedStubs.push(sinon.stub(this.database.connectionChecker_, 'doSafetyChecks') + sinon.stub(this.database.connectionChecker_, 'doSafetyChecks') .callsFake(function(_a, _b) { return Blockly.Connection.CAN_CONNECT; - })); + }); // Skip everything but the distance checks. - this.allowedStubs.push(sinon.stub(this.database.connectionChecker_, 'doDragChecks') + sinon.stub(this.database.connectionChecker_, 'doDragChecks') .callsFake(function(a, b, distance) { return a.distanceFrom(b) <= distance; - })); + }); this.createCheckConnection = function(x, y) { var checkConnection = this.createConnection(x, y, Blockly.NEXT_STATEMENT, @@ -216,11 +219,6 @@ suite('Connection Database', function() { return checkConnection; }; }); - teardown(function() { - for (var i = 0; i < this.allowedStubs.length; i++) { - this.allowedStubs[i].restore(); - } - }); test('Empty Database', function() { var checkConnection = this.createConnection(0, 0, Blockly.NEXT_STATEMENT, new Blockly.ConnectionDB()); diff --git a/tests/mocha/connection_test.js b/tests/mocha/connection_test.js index 6472cd41b..da933a404 100644 --- a/tests/mocha/connection_test.js +++ b/tests/mocha/connection_test.js @@ -5,10 +5,10 @@ */ suite('Connection', function() { - suiteSetup(function() { - this.workspace = { - connectionChecker: new Blockly.ConnectionChecker() - }; + setup(function() { + sharedTestSetup.call(this); + this.workspace = sinon.createStubInstance(Blockly.Workspace); + this.workspace.connectionChecker = new Blockly.ConnectionChecker(); this.createConnection = function(type) { var block = { workspace: this.workspace, @@ -18,6 +18,9 @@ suite('Connection', function() { return connection; }; }); + teardown(function() { + sharedTestTeardown.call(this); + }); test('canConnectWithReason passes', function() { var conn1 = this.createConnection(Blockly.PREVIOUS_STATEMENT); var conn2 = this.createConnection(Blockly.NEXT_STATEMENT); diff --git a/tests/mocha/cursor_test.js b/tests/mocha/cursor_test.js index 6286ff283..647ec762d 100644 --- a/tests/mocha/cursor_test.js +++ b/tests/mocha/cursor_test.js @@ -6,6 +6,7 @@ suite('Cursor', function() { setup(function() { + sharedTestSetup.call(this); Blockly.defineBlocksWithJsonArray([{ "type": "input_statement", "message0": "%1 %2 %3 %4", @@ -72,10 +73,9 @@ suite('Cursor', function() { }; }); teardown(function() { + sharedTestTeardown.call(this); delete Blockly.Blocks['input_statement']; delete Blockly.Blocks['field_input']; - - this.workspace.dispose(); }); test('Next - From a Previous skip over next connection and block', function() { diff --git a/tests/mocha/dropdowndiv_test.js b/tests/mocha/dropdowndiv_test.js index 13880a11c..c51c83dea 100644 --- a/tests/mocha/dropdowndiv_test.js +++ b/tests/mocha/dropdowndiv_test.js @@ -7,6 +7,7 @@ suite('DropDownDiv', function() { suite('Positioning', function() { setup(function() { + sharedTestSetup.call(this); this.boundsStub = sinon.stub(Blockly.DropDownDiv, 'getBoundsInfo_') .returns({ left: 0, @@ -27,10 +28,7 @@ suite('DropDownDiv', function() { .get(function() { return 0; }); }); teardown(function() { - this.boundsStub.restore(); - this.sizeStub.restore(); - this.clientHeightStub.restore(); - this.clientTopStub.restore(); + sharedTestTeardown.call(this); }); test('Below, in Bounds', function() { var metrics = Blockly.DropDownDiv.getPositionMetrics_(50, 0, 50, -10); diff --git a/tests/mocha/extensions_test.js b/tests/mocha/extensions_test.js index ea9a81bb4..5dd51b12d 100644 --- a/tests/mocha/extensions_test.js +++ b/tests/mocha/extensions_test.js @@ -6,25 +6,21 @@ suite('Extensions', function() { setup(function() { + sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); this.blockTypesCleanup_ = []; this.extensionsCleanup_ = []; }); teardown(function() { - var i; - for (i = 0; i < this.blockTypesCleanup_.length; i++) { + sharedTestTeardown.call(this); + for (let i = 0; i < this.blockTypesCleanup_.length; i++) { var blockType = this.blockTypesCleanup_[i]; delete Blockly.Blocks[blockType]; } - for (i = 0; i < this.extensionsCleanup_.length; i++) { + for (let i = 0; i < this.extensionsCleanup_.length; i++) { var extension = this.extensionsCleanup_[i]; delete Blockly.Extensions.ALL_[extension]; } - this.workspace.dispose(); - // Clear Blockly.Event state. - Blockly.Events.setGroup(false); - Blockly.Events.disabled_ = 0; - sinon.restore(); }); test('Definition before and after block type', function() { diff --git a/tests/mocha/field_angle_test.js b/tests/mocha/field_angle_test.js index 74206c888..6058aa62a 100644 --- a/tests/mocha/field_angle_test.js +++ b/tests/mocha/field_angle_test.js @@ -5,6 +5,12 @@ */ suite('Angle Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); /** * Configuration for field tests with invalid values. * @type {!Array} diff --git a/tests/mocha/field_checkbox_test.js b/tests/mocha/field_checkbox_test.js index f7ff4dac6..9eac2211d 100644 --- a/tests/mocha/field_checkbox_test.js +++ b/tests/mocha/field_checkbox_test.js @@ -5,6 +5,12 @@ */ suite('Checkbox Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); /** * Configuration for field tests with invalid values. * @type {!Array} diff --git a/tests/mocha/field_colour_test.js b/tests/mocha/field_colour_test.js index 71d1d352a..90f566b1d 100644 --- a/tests/mocha/field_colour_test.js +++ b/tests/mocha/field_colour_test.js @@ -5,6 +5,12 @@ */ suite('Colour Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); /** * Configuration for field tests with invalid values. * @type {!Array} diff --git a/tests/mocha/field_dropdown_test.js b/tests/mocha/field_dropdown_test.js index 9e126adc1..de5571a2e 100644 --- a/tests/mocha/field_dropdown_test.js +++ b/tests/mocha/field_dropdown_test.js @@ -5,6 +5,12 @@ */ suite('Dropdown Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); function assertValue(dropdownField, expectedValue, expectedText) { var actualValue = dropdownField.getValue(); var actualText = dropdownField.getText(); diff --git a/tests/mocha/field_image_test.js b/tests/mocha/field_image_test.js index f2c415a84..6b88bf5ff 100644 --- a/tests/mocha/field_image_test.js +++ b/tests/mocha/field_image_test.js @@ -5,6 +5,12 @@ */ suite('Image Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); function assertValue(imageField, expectedValue, expectedText) { var actualValue = imageField.getValue(); var actualText = imageField.getText(); diff --git a/tests/mocha/field_label_serializable_test.js b/tests/mocha/field_label_serializable_test.js index 8d6ad9864..0f644e39e 100644 --- a/tests/mocha/field_label_serializable_test.js +++ b/tests/mocha/field_label_serializable_test.js @@ -5,6 +5,12 @@ */ suite('Label Serializable Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); /** * Configuration for field tests with invalid values. * @type {!Array} diff --git a/tests/mocha/field_label_test.js b/tests/mocha/field_label_test.js index 698f21f10..f692b2def 100644 --- a/tests/mocha/field_label_test.js +++ b/tests/mocha/field_label_test.js @@ -5,6 +5,12 @@ */ suite('Label Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); /** * Configuration for field tests with invalid values. * @type {!Array} diff --git a/tests/mocha/field_number_test.js b/tests/mocha/field_number_test.js index b18bb1c0e..d182702fa 100644 --- a/tests/mocha/field_number_test.js +++ b/tests/mocha/field_number_test.js @@ -5,6 +5,12 @@ */ suite('Number Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); /** * Configuration for field tests with invalid values. * @type {!Array} diff --git a/tests/mocha/field_registry_test.js b/tests/mocha/field_registry_test.js index eb0d3491e..dffc47af6 100644 --- a/tests/mocha/field_registry_test.js +++ b/tests/mocha/field_registry_test.js @@ -19,11 +19,16 @@ suite('Field Registry', function() { return new CustomFieldType(options['value']); }; + setup(function() { + sharedTestSetup.call(this); + }); teardown(function() { + sharedTestTeardown.call(this); if (Blockly.registry.typeMap_['field']['field_custom_test']) { delete Blockly.registry.typeMap_['field']['field_custom_test']; } }); + suite('Registration', function() { test('Simple', function() { Blockly.fieldRegistry.register('field_custom_test', CustomFieldType); diff --git a/tests/mocha/field_test.js b/tests/mocha/field_test.js index e8ccf595d..98f8762d1 100644 --- a/tests/mocha/field_test.js +++ b/tests/mocha/field_test.js @@ -5,6 +5,12 @@ */ suite('Abstract Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); suite('Is Serializable', function() { // Both EDITABLE and SERIALIZABLE are default. function FieldDefault() { diff --git a/tests/mocha/field_textinput_test.js b/tests/mocha/field_textinput_test.js index f51c1bf92..10a2b0138 100644 --- a/tests/mocha/field_textinput_test.js +++ b/tests/mocha/field_textinput_test.js @@ -5,6 +5,12 @@ */ suite('Text Input Fields', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); /** * Configuration for field tests with invalid values. * @type {!Array} diff --git a/tests/mocha/field_variable_test.js b/tests/mocha/field_variable_test.js index b4776187b..a97cd73b2 100644 --- a/tests/mocha/field_variable_test.js +++ b/tests/mocha/field_variable_test.js @@ -44,14 +44,14 @@ suite('Variable Fields', function() { } setup(function() { + sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); createGenUidStubWithReturns(FAKE_ID); sinon.stub(Blockly.Variables, 'generateUniqueName') .returns(FAKE_VARIABLE_NAME); }); teardown(function() { - this.workspace.dispose(); - sinon.restore(); + sharedTestTeardown.call(this); }); test('Dropdown contains variables', function() { diff --git a/tests/mocha/flyout_test.js b/tests/mocha/flyout_test.js index 1a73f095b..ed7894bd4 100644 --- a/tests/mocha/flyout_test.js +++ b/tests/mocha/flyout_test.js @@ -6,6 +6,7 @@ suite('Flyout', function() { setup(function() { + sharedTestSetup.call(this); Blockly.defineBlocksWithJsonArray([{ "type": "basic_block", "message0": "%1", @@ -25,9 +26,8 @@ suite('Flyout', function() { }); teardown(function() { - this.workspace.dispose(); + sharedTestTeardown.call(this); delete Blockly.Blocks['basic_block']; - sinon.restore(); }); suite('createFlyoutInfo_', function() { diff --git a/tests/mocha/generator_test.js b/tests/mocha/generator_test.js index cf91990ea..2fc0ef6ee 100644 --- a/tests/mocha/generator_test.js +++ b/tests/mocha/generator_test.js @@ -12,11 +12,12 @@ goog.require('Blockly.Python'); suite('Generator', function() { setup(function() { + sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); }); teardown(function() { - this.workspace.dispose(); + sharedTestTeardown.call(this); }); suite('prefix', function() { diff --git a/tests/mocha/gesture_test.js b/tests/mocha/gesture_test.js index 4ba2b591c..a19997ad6 100644 --- a/tests/mocha/gesture_test.js +++ b/tests/mocha/gesture_test.js @@ -13,12 +13,13 @@ suite('Gesture', function() { setup(function() { + sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); this.e = {}; }); teardown(function() { - this.workspace.dispose(); + sharedTestTeardown.call(this); }); test('Constructor', function() { diff --git a/tests/mocha/input_test.js b/tests/mocha/input_test.js index 4b05fe8d6..35b4de2b9 100644 --- a/tests/mocha/input_test.js +++ b/tests/mocha/input_test.js @@ -6,6 +6,7 @@ suite('Inputs', function() { setup(function() { + sharedTestSetup.call(this); Blockly.defineBlocksWithJsonArray([ { "type": "empty_block", @@ -30,11 +31,8 @@ suite('Inputs', function() { this.bumpNeighboursStub.resetHistory(); }); teardown(function() { - this.renderStub.restore(); - this.bumpNeighboursStub.restore(); - + sharedTestTeardown.call(this); delete Blockly.Blocks['empty_block']; - this.workspace.dispose(); }); suite('Insert Field At', function() { suite('Index Bounds', function() { diff --git a/tests/mocha/json_test.js b/tests/mocha/json_test.js index 4e9ca9501..dc64b166d 100644 --- a/tests/mocha/json_test.js +++ b/tests/mocha/json_test.js @@ -6,6 +6,7 @@ suite('JSON Block Definitions', function() { setup(function() { + sharedTestSetup.call(this); this.workspace_ = new Blockly.Workspace(); this.blocks_ = []; this.blockTypes_ = []; @@ -13,6 +14,7 @@ suite('JSON Block Definitions', function() { }); teardown(function() { + sharedTestTeardown.call(this); for (var i = 0; i < this.blocks_.length; i++) { var block = this.blocks_[i]; block.dispose(); @@ -23,7 +25,6 @@ suite('JSON Block Definitions', function() { for (var i = 0, message; (message = this.messages_[i]); i++) { delete Blockly.Msg[message]; } - this.workspace_.dispose(); }); suite('defineBlocksWithJsonArray', function() { diff --git a/tests/mocha/key_map_test.js b/tests/mocha/key_map_test.js index 6ccef7335..301a2a28b 100644 --- a/tests/mocha/key_map_test.js +++ b/tests/mocha/key_map_test.js @@ -6,8 +6,12 @@ suite('Key Map Tests', function() { setup(function() { + sharedTestSetup.call(this); Blockly.user.keyMap.setKeyMap(Blockly.user.keyMap.createDefaultKeyMap()); }); + teardown(function() { + sharedTestTeardown.call(this); + }); test('Test adding a new action to key map', function() { var newAction = new Blockly.Action('test_action', 'test', function(){ diff --git a/tests/mocha/logic_ternary_test.js b/tests/mocha/logic_ternary_test.js index e94598e69..cba993109 100644 --- a/tests/mocha/logic_ternary_test.js +++ b/tests/mocha/logic_ternary_test.js @@ -6,12 +6,13 @@ suite('Logic ternary', function() { setup(function() { + sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); this.block = this.workspace.newBlock('logic_ternary'); }); teardown(function() { - this.workspace.dispose(); + sharedTestTeardown.call(this); }); test('Structure', function() { diff --git a/tests/mocha/metrics_test.js b/tests/mocha/metrics_test.js index f5bfbfbc9..f252b17a9 100644 --- a/tests/mocha/metrics_test.js +++ b/tests/mocha/metrics_test.js @@ -34,6 +34,13 @@ suite('Metrics', function() { }; } + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); + test('GetContentDimensionsExact - empty', function() { var ws = makeMockWs(1, 0, 0, 0, 0); var defaultZoom = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws); diff --git a/tests/mocha/names_test.js b/tests/mocha/names_test.js index 8cf89f380..c8abefd71 100644 --- a/tests/mocha/names_test.js +++ b/tests/mocha/names_test.js @@ -11,6 +11,12 @@ 'use strict'; suite('Names', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); test('Safe name', function() { var varDB = new Blockly.Names('window,door'); diff --git a/tests/mocha/navigation_test.js b/tests/mocha/navigation_test.js index 168577412..ba2b5a9c7 100644 --- a/tests/mocha/navigation_test.js +++ b/tests/mocha/navigation_test.js @@ -22,6 +22,13 @@ suite('Navigation', function() { return workspace; } + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); + // Test that toolbox key handlers call through to the right functions and // transition correctly between toolbox, workspace, and flyout. suite('Tests toolbox keys', function() { @@ -50,8 +57,8 @@ suite('Navigation', function() { }); teardown(function() { + workspaceTeardown.call(this, this.workspace); delete Blockly.Blocks['basic_block']; - this.workspace.dispose(); }); test('Next', function() { @@ -166,8 +173,8 @@ suite('Navigation', function() { }); teardown(function() { + workspaceTeardown.call(this, this.workspace); delete Blockly.Blocks['basic_block']; - this.workspace.dispose(); }); // Should be a no-op @@ -257,8 +264,8 @@ suite('Navigation', function() { }); teardown(function() { + workspaceTeardown.call(this, this.workspace); delete Blockly.Blocks['basic_block']; - this.workspace.dispose(); }); test('Previous', function() { @@ -368,8 +375,8 @@ suite('Navigation', function() { }; }); teardown(function() { + workspaceTeardown.call(this, this.workspace); delete Blockly.Blocks['basic_block']; - this.workspace.dispose(); }); test('Action does not exist', function() { var block = this.workspace.getTopBlocks()[0]; @@ -481,8 +488,8 @@ suite('Navigation', function() { }); teardown(function() { + workspaceTeardown.call(this, this.workspace); delete Blockly.Blocks['field_block']; - this.workspace.dispose(); }); test('Perform valid action for read only', function() { @@ -528,8 +535,8 @@ suite('Navigation', function() { }); teardown(function() { + workspaceTeardown.call(this, this.workspace); delete Blockly.Blocks['basic_block']; - this.workspace.dispose(); }); test('Insert from flyout with a valid connection marked', function() { @@ -633,9 +640,9 @@ suite('Navigation', function() { }); teardown(function() { + workspaceTeardown.call(this, this.workspace); delete Blockly.Blocks['inline_block']; delete Blockly.Blocks['basic_block']; - this.workspace.dispose(); }); test('Connect cursor on previous into stack', function() { @@ -704,8 +711,8 @@ suite('Navigation', function() { }); teardown(function() { + workspaceTeardown.call(this, this.workspace); delete Blockly.Blocks['basic_block']; - this.workspace.dispose(); }); test('Delete block - has parent ', function() { diff --git a/tests/mocha/registry_test.js b/tests/mocha/registry_test.js index 1076b595e..44c941a29 100644 --- a/tests/mocha/registry_test.js +++ b/tests/mocha/registry_test.js @@ -16,7 +16,11 @@ suite('Registry', function() { return 'something'; }; + setup(function() { + sharedTestSetup.call(this); + }); teardown(function() { + sharedTestTeardown.call(this); if (Blockly.registry.typeMap_['test'] && Blockly.registry.typeMap_['test']['test_name']) { delete Blockly.registry.typeMap_['test']['test_name']; diff --git a/tests/mocha/test_helpers.js b/tests/mocha/test_helpers.js index b0c0f8e63..fda3aef1d 100644 --- a/tests/mocha/test_helpers.js +++ b/tests/mocha/test_helpers.js @@ -74,7 +74,6 @@ function createEventsFireStubFireImmediately_(clock) { // stub.wrappedMethod.call(this, ...arguments); // // Advance clock forward to run any queued events. // clock.runAll(); - // if (!Blockly.Events.isEnabled()) { return; } diff --git a/tests/mocha/toolbox_test.js b/tests/mocha/toolbox_test.js index 5b418d90d..d06fe7bef 100644 --- a/tests/mocha/toolbox_test.js +++ b/tests/mocha/toolbox_test.js @@ -6,6 +6,7 @@ suite('Toolbox', function() { setup(function() { + sharedTestSetup.call(this); Blockly.defineBlocksWithJsonArray([{ "type": "basic_block", "message0": "%1", @@ -26,9 +27,8 @@ suite('Toolbox', function() { }); teardown(function() { - this.workspace.dispose(); + sharedTestTeardown.call(this); delete Blockly.Blocks['basic_block']; - sinon.restore(); }); suite('init', function() { @@ -184,9 +184,9 @@ suite('Toolbox', function() { sinon.assert.calledOnce(flyoutHideStub); }); test('UI Event is fired when new category is selected', function() { - var eventsFireStub = sinon.stub(Blockly.Events, 'fire'); + this.eventsFireStub.resetHistory(); this.toolbox.handleAfterTreeSelected_(this.firstChild); - sinon.assert.calledOnce(eventsFireStub); + sinon.assert.calledOnce(this.eventsFireStub); }); test('Last category is updated when there is a new node', function() { this.toolbox.handleAfterTreeSelected_(this.firstChild, this.secondChild); diff --git a/tests/mocha/utils_test.js b/tests/mocha/utils_test.js index 5dfe92af4..11c6fdb2d 100644 --- a/tests/mocha/utils_test.js +++ b/tests/mocha/utils_test.js @@ -5,6 +5,13 @@ */ suite('Utils', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); + test('genUid', function() { var uuids = {}; chai.assert.equal([1,2,3].indexOf(4), -1); diff --git a/tests/mocha/variable_map_test.js b/tests/mocha/variable_map_test.js index 6c7fa7bf8..35078f17f 100644 --- a/tests/mocha/variable_map_test.js +++ b/tests/mocha/variable_map_test.js @@ -6,13 +6,13 @@ suite('Variable Map', function() { setup(function() { + sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); this.variableMap = new Blockly.VariableMap(this.workspace); }); teardown(function() { - this.workspace.dispose(); - sinon.restore(); + sharedTestTeardown.call(this); }); suite('createVariable', function() { diff --git a/tests/mocha/variable_model_test.js b/tests/mocha/variable_model_test.js index fb47818b9..0598da755 100644 --- a/tests/mocha/variable_model_test.js +++ b/tests/mocha/variable_model_test.js @@ -6,11 +6,12 @@ suite('Variable Model', function() { setup(function() { + sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); }); teardown(function() { - this.workspace.dispose(); + sharedTestTeardown.call(this); }); test('Trivial', function() { diff --git a/tests/mocha/variables_test.js b/tests/mocha/variables_test.js index 01710045a..c3e653323 100644 --- a/tests/mocha/variables_test.js +++ b/tests/mocha/variables_test.js @@ -6,6 +6,7 @@ suite('Variables', function() { setup(function() { + sharedTestSetup.call(this); this.workspace = new Blockly.Workspace(); Blockly.defineBlocksWithJsonArray([{ "type": "get_var_block", @@ -24,13 +25,8 @@ suite('Variables', function() { }); teardown(function() { + sharedTestTeardown.call(this); delete Blockly.Blocks['get_var_block']; - this.workspace.dispose(); - - // Clear Blockly.Event state. - Blockly.Events.setGroup(false); - Blockly.Events.disabled_ = 0; - sinon.restore(); }); /** diff --git a/tests/mocha/widget_div_test.js b/tests/mocha/widget_div_test.js index bc90ad960..84571dd59 100644 --- a/tests/mocha/widget_div_test.js +++ b/tests/mocha/widget_div_test.js @@ -5,6 +5,12 @@ */ suite('WidgetDiv', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); suite('positionWithAnchor', function() { function makeBBox(left, top, width, height) { diff --git a/tests/mocha/workspace_test.js b/tests/mocha/workspace_test.js index 7714e1aae..a92f45072 100644 --- a/tests/mocha/workspace_test.js +++ b/tests/mocha/workspace_test.js @@ -256,7 +256,7 @@ function testAWorkspace() { // Have to dispose of the main workspace after the flyout workspace // because it holds the variable map. // Normally the main workspace disposes of the flyout workspace. - this.targetWorkspace.dispose(); + workspaceTeardown.call(this, this.targetWorkspace); }); test('Trivial Flyout is True', function() { diff --git a/tests/mocha/xml_procedures_test.js b/tests/mocha/xml_procedures_test.js index 09d526362..d4d28ee0c 100644 --- a/tests/mocha/xml_procedures_test.js +++ b/tests/mocha/xml_procedures_test.js @@ -8,6 +8,13 @@ goog.require('Blockly.Blocks.procedures'); goog.require('Blockly.Msg'); suite('Procedures XML', function() { + setup(function() { + sharedTestSetup.call(this); + }); + teardown(function() { + sharedTestTeardown.call(this); + }); + suite('Deserialization', function() { setup(function() { this.workspace = new Blockly.Workspace();