Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move test helpers from samples into core #5969

Merged
merged 24 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
99af064
fix: move core test helpers into new directory
BeksOmega Feb 28, 2022
eff84af
fix: add test helpers to core and convert to goog modules
BeksOmega Feb 28, 2022
e276745
fix: change tests to use local helpers
BeksOmega Feb 28, 2022
fb57f18
fix: change local tests to use chai asserts
BeksOmega Mar 1, 2022
3a655c5
fix: skip field tests in serializer b/c test blocks are unavailable
BeksOmega Mar 1, 2022
0ded768
fix: rename some helper files
BeksOmega Mar 1, 2022
08cddc8
fix: rename some helper modules
BeksOmega Mar 1, 2022
6d47b07
fix: split block helpers into code gen and serialization
BeksOmega Mar 1, 2022
8a78f68
fix: split block defs into new helper file
BeksOmega Mar 1, 2022
e084e91
fix: split warning helpers into new file
BeksOmega Mar 1, 2022
ccfd888
fix: split user input helpers into new file
BeksOmega Mar 1, 2022
e1ad627
fix: split event helpers into a new file
BeksOmega Mar 1, 2022
0766370
fix: split variable helper into new file
BeksOmega Mar 1, 2022
b332bdf
fix: move remaining test helpers to new setup-teardown file
BeksOmega Mar 1, 2022
e2dd397
fix: rename setup and teardown module
BeksOmega Mar 1, 2022
a72953c
fix: cleanup from rebase
BeksOmega Mar 1, 2022
acb3e3b
fix: undo accidental rename
BeksOmega Mar 1, 2022
39db79b
fix: lint?
BeksOmega Mar 1, 2022
9c13a36
fix: bad toolbox definitions namespace
BeksOmega Mar 2, 2022
0e39153
fix: fixup warning helpers
BeksOmega Mar 2, 2022
1f8eb8f
fix: remove inclusion of dev-tools in mocha tests
BeksOmega Mar 2, 2022
220d7bb
move to modules, but break mocha
BeksOmega Mar 3, 2022
4dac25a
fix: run mocha as a module
BeksOmega Mar 4, 2022
050956d
fix: lint
BeksOmega Mar 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

131 changes: 70 additions & 61 deletions tests/deps.mocha.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions tests/mocha/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
},
"globals": {
"chai": false,
"sinon": false,
"testHelpers": true
"sinon": false
},
"rules": {
"no-unused-vars": ["off"],
Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/astnode_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
goog.module('Blockly.test.astNode');

const {ASTNode} = goog.require('Blockly.ASTNode');
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('ASTNode', function() {
Expand Down
3 changes: 2 additions & 1 deletion tests/mocha/block_change_event_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

goog.module('Blockly.test.blockChangeEvent');

const {defineMutatorBlocks, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
const {defineMutatorBlocks} = goog.require('Blockly.test.helpers.blockDefinitions');


suite('Block Change Event', function() {
Expand Down
3 changes: 2 additions & 1 deletion tests/mocha/block_create_event_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

goog.module('Blockly.test.blockCreateEvent');

const {assertEventFired} = goog.require('Blockly.test.helpers.events');
const eventUtils = goog.require('Blockly.Events.utils');
const {assertEventFired, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Block Create Event', function() {
Expand Down
6 changes: 4 additions & 2 deletions tests/mocha/block_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

goog.module('Blockly.test.blocks');

const eventUtils = goog.require('Blockly.Events.utils');
const {Blocks} = goog.require('Blockly.blocks');
const {ConnectionType} = goog.require('Blockly.ConnectionType');
const {createDeprecationWarningStub, createRenderedBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
const {createDeprecationWarningStub} = goog.require('Blockly.test.helpers.warnings');
const {createRenderedBlock} = goog.require('Blockly.test.helpers.blockDefinitions');
const eventUtils = goog.require('Blockly.Events.utils');
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Blocks', function() {
Expand Down
3 changes: 2 additions & 1 deletion tests/mocha/comment_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

goog.module('Blockly.test.comments');

const {assertEventFired} = goog.require('Blockly.test.helpers.events');
const eventUtils = goog.require('Blockly.Events.utils');
const {assertEventFired, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Comments', function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/connection_checker_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
goog.module('Blockly.test.connectionChecker');

const {ConnectionType} = goog.require('Blockly.ConnectionType');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Connection checker', function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/connection_db_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
goog.module('Blockly.test.connectionDb');

const {ConnectionType} = goog.require('Blockly.ConnectionType');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Connection Database', function() {
Expand Down
3 changes: 2 additions & 1 deletion tests/mocha/connection_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

goog.module('Blockly.test.connection');

const {assertSingleDeprecationWarningCall, createDeprecationWarningStub, createGenUidStubWithReturns, defineRowBlock, defineStatementBlock, defineStackBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
const {createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
const {defineRowBlock, defineStatementBlock, defineStackBlock} = goog.require('Blockly.test.helpers.blockDefinitions');


suite('Connection', function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/contextmenu_items_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

goog.module('Blockly.test.contextMenuItem');

const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Context Menu Items', function() {
Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/cursor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

goog.module('Blockly.test.cursor');

const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
const {ASTNode} = goog.require('Blockly.ASTNode');


Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/dropdowndiv_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

goog.module('Blockly.test.dropdown');

const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('DropDownDiv', function() {
Expand Down
6 changes: 4 additions & 2 deletions tests/mocha/event_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

goog.module('Blockly.test.event');

const eventUtils = goog.require('Blockly.Events.utils');
const {assertEventEquals, assertNthCallEventArgEquals, assertVariableValues, createFireChangeListenerSpy, createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
const {ASTNode} = goog.require('Blockly.ASTNode');
const {assertEventEquals, assertNthCallEventArgEquals, createFireChangeListenerSpy} = goog.require('Blockly.test.helpers.events');
const {assertVariableValues} = goog.require('Blockly.test.helpers.variables');
const {createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
const eventUtils = goog.require('Blockly.Events.utils');
goog.require('Blockly.WorkspaceComment');


Expand Down
2 changes: 1 addition & 1 deletion tests/mocha/extensions_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

goog.module('Blockly.test.extensions');

const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Extensions', function() {
Expand Down
24 changes: 13 additions & 11 deletions tests/mocha/field_angle_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

goog.module('Blockly.test.fieldAngle');

const {createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.helpers.fields');
const {createTestBlock, defineRowBlock} = goog.require('Blockly.test.helpers.blockDefinitions');
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Angle Fields', function() {
Expand Down Expand Up @@ -60,22 +62,22 @@ suite('Angle Fields', function() {
* @param {FieldTemplate} field The field to check.
*/
const assertFieldDefault = function(field) {
testHelpers.assertFieldValue(field, defaultFieldValue);
assertFieldValue(field, defaultFieldValue);
};
/**
* Asserts that the field properties are correct based on the test case.
* @param {!Blockly.FieldAngle} field The field to check.
* @param {!FieldValueTestCase} testCase The test case.
*/
const validTestCaseAssertField = function(field, testCase) {
testHelpers.assertFieldValue(field, testCase.expectedValue);
assertFieldValue(field, testCase.expectedValue);
};

testHelpers.runConstructorSuiteTests(
runConstructorSuiteTests(
Blockly.FieldAngle, validValueTestCases, invalidValueTestCases,
validTestCaseAssertField, assertFieldDefault);

testHelpers.runFromJsonSuiteTests(
runFromJsonSuiteTests(
Blockly.FieldAngle, validValueTestCases, invalidValueTestCases,
validTestCaseAssertField, assertFieldDefault);

Expand All @@ -84,25 +86,25 @@ suite('Angle Fields', function() {
setup(function() {
this.field = new Blockly.FieldAngle();
});
testHelpers.runSetValueTests(
runSetValueTests(
validValueTestCases, invalidValueTestCases, defaultFieldValue);
test('With source block', function() {
this.field.setSourceBlock(createTestBlock());
this.field.setValue(2.5);
testHelpers.assertFieldValue(this.field, 2.5);
assertFieldValue(this.field, 2.5);
});
});
suite('Value -> New Value', function() {
const initialValue = 1;
setup(function() {
this.field = new Blockly.FieldAngle(initialValue);
});
testHelpers.runSetValueTests(
runSetValueTests(
validValueTestCases, invalidValueTestCases, initialValue);
test('With source block', function() {
this.field.setSourceBlock(createTestBlock());
this.field.setValue(2.5);
testHelpers.assertFieldValue(this.field, 2.5);
assertFieldValue(this.field, 2.5);
});
});
});
Expand Down Expand Up @@ -142,12 +144,12 @@ suite('Angle Fields', function() {
this.field.isBeingEdited_ = true;
this.field.htmlInput_.value = String(suiteInfo.value);
this.field.onHtmlInputChange_(null);
testHelpers.assertFieldValue(
assertFieldValue(
this.field, suiteInfo.expectedValue, String(suiteInfo.value));
});
test('When Not Editing', function() {
this.field.setValue(suiteInfo.value);
testHelpers.assertFieldValue(this.field, suiteInfo.expectedValue);
assertFieldValue(this.field, suiteInfo.expectedValue);
});
});
});
Expand Down
18 changes: 10 additions & 8 deletions tests/mocha/field_checkbox_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

goog.module('Blockly.test.fieldCheckbox');

const {defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.helpers.fields');
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
const {defineRowBlock} = goog.require('Blockly.test.helpers.blockDefinitions');


suite('Checkbox Fields', function() {
Expand Down Expand Up @@ -61,7 +63,7 @@ suite('Checkbox Fields', function() {
* @param {!Blockly.FieldCheckbox} field The field to check.
*/
const assertFieldDefault = function(field) {
testHelpers.assertFieldValue(
assertFieldValue(
field, defaultFieldValue, defaultFieldValue.toLowerCase());
};
/**
Expand All @@ -70,15 +72,15 @@ suite('Checkbox Fields', function() {
* @param {!FieldValueTestCase} testCase The test case.
*/
const validTestCaseAssertField = function(field, testCase) {
testHelpers.assertFieldValue(
assertFieldValue(
field, testCase.expectedValue, testCase.expectedValue.toLowerCase());
};

testHelpers.runConstructorSuiteTests(
runConstructorSuiteTests(
Blockly.FieldCheckbox, validValueTestCases, invalidValueTestCases,
validTestCaseAssertField, assertFieldDefault);

testHelpers.runFromJsonSuiteTests(
runFromJsonSuiteTests(
Blockly.FieldCheckbox, validValueTestCases, invalidValueTestCases,
validTestCaseAssertField, assertFieldDefault);

Expand All @@ -87,14 +89,14 @@ suite('Checkbox Fields', function() {
setup(function() {
this.field = new Blockly.FieldCheckbox('TRUE');
});
testHelpers.runSetValueTests(
runSetValueTests(
validValueTestCases, invalidValueTestCases, 'TRUE', 'true');
});
suite('False -> New Value', function() {
setup(function() {
this.field = new Blockly.FieldCheckbox('FALSE');
});
testHelpers.runSetValueTests(
runSetValueTests(
validValueTestCases, invalidValueTestCases, 'FALSE', 'false');
});
});
Expand Down Expand Up @@ -131,7 +133,7 @@ suite('Checkbox Fields', function() {
});
test('New Value', function() {
this.field.setValue(suiteInfo.value);
testHelpers.assertFieldValue(
assertFieldValue(
this.field, suiteInfo.expectedValue,
String(suiteInfo.expectedValue).toLowerCase());
});
Expand Down
22 changes: 12 additions & 10 deletions tests/mocha/field_colour_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

goog.module('Blockly.test.fieldColour');

const {createTestBlock, defineRowBlock, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
const {assertFieldValue, runConstructorSuiteTests, runFromJsonSuiteTests, runSetValueTests} = goog.require('Blockly.test.helpers.fields');
const {createTestBlock, defineRowBlock} = goog.require('Blockly.test.helpers.blockDefinitions');
const {sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');


suite('Colour Fields', function() {
Expand Down Expand Up @@ -87,23 +89,23 @@ suite('Colour Fields', function() {
* @param {FieldTemplate} field The field to check.
*/
const assertFieldDefault = function(field) {
testHelpers.assertFieldValue(field, defaultFieldValue, defaultTextValue);
assertFieldValue(field, defaultFieldValue, defaultTextValue);
};
/**
* Asserts that the field properties are correct based on the test case.
* @param {!Blockly.FieldAngle} field The field to check.
* @param {!FieldValueTestCase} testCase The test case.
*/
const validTestCaseAssertField = function(field, testCase) {
testHelpers.assertFieldValue(
assertFieldValue(
field, testCase.expectedValue, testCase.expectedText);
};

testHelpers.runConstructorSuiteTests(
runConstructorSuiteTests(
Blockly.FieldColour, validValueTestCases, invalidValueTestCases,
validTestCaseAssertField, assertFieldDefault);

testHelpers.runFromJsonSuiteTests(
runFromJsonSuiteTests(
Blockly.FieldColour, validValueTestCases, invalidValueTestCases,
validTestCaseAssertField, assertFieldDefault);

Expand All @@ -112,25 +114,25 @@ suite('Colour Fields', function() {
setup(function() {
this.field = new Blockly.FieldColour();
});
testHelpers.runSetValueTests(
runSetValueTests(
validValueTestCases, invalidValueTestCases, defaultFieldValue,
defaultTextValue);
test('With source block', function() {
this.field.setSourceBlock(createTestBlock());
this.field.setValue('#bcbcbc');
testHelpers.assertFieldValue(this.field, '#bcbcbc', '#bcbcbc');
assertFieldValue(this.field, '#bcbcbc', '#bcbcbc');
});
});
suite('Value -> New Value', function() {
setup(function() {
this.field = new Blockly.FieldColour('#aaaaaa');
});
testHelpers.runSetValueTests(
runSetValueTests(
validValueTestCases, invalidValueTestCases, '#aaaaaa', '#aaa');
test('With source block', function() {
this.field.setSourceBlock(createTestBlock());
this.field.setValue('#bcbcbc');
testHelpers.assertFieldValue(this.field, '#bcbcbc', '#bcbcbc');
assertFieldValue(this.field, '#bcbcbc', '#bcbcbc');
});
});
});
Expand Down Expand Up @@ -161,7 +163,7 @@ suite('Colour Fields', function() {
});
test('New Value', function() {
this.field.setValue(suiteInfo.value);
testHelpers.assertFieldValue(
assertFieldValue(
this.field, suiteInfo.expectedValue, suiteInfo.expectedText);
});
});
Expand Down
Loading