mirror of
https://github.com/google/blockly.git
synced 2026-01-13 11:57:10 +01:00
fix: split warning helpers into new file
This commit is contained in:
@@ -33,14 +33,14 @@ goog.addDependency('../../tests/mocha/input_test.js', ['Blockly.test.input'], ['
|
||||
goog.addDependency('../../tests/mocha/insertion_marker_test.js', ['Blockly.test.insertionMarker'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/jso_deserialization_test.js', ['Blockly.test.jsoDeserialization'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/jso_serialization_test.js', ['Blockly.test.jsoSerialization'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions'], {'lang': 'es8', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/json_test.js', ['Blockly.test.json'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/json_test.js', ['Blockly.test.json'], ['Blockly.test.helpers', 'Blockly.test.helpers.warnings'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/keydown_test.js', ['Blockly.test.keydown'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/logic_ternary_test.js', ['Blockly.test.logicTernary'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.serialization'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/metrics_test.js', ['Blockly.test.metrics'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/mutator_test.js', ['Blockly.test.mutator'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/names_test.js', ['Blockly.test.names'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/procedures_test.js', ['Blockly.test.procedures'], ['Blockly', 'Blockly.Msg', 'Blockly.test.helpers', 'Blockly.test.helpers.procedures', 'Blockly.test.helpers.serialization'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/registry_test.js', ['Blockly.test.registry'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/registry_test.js', ['Blockly.test.registry'], ['Blockly.test.helpers', 'Blockly.test.helpers.warnings'], {'lang': 'es6', 'module': 'goog'});
|
||||
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', 'Blockly.test.helpers.common'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/shortcut_registry_test.js', ['Blockly.test.shortcutRegistry'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
@@ -52,7 +52,8 @@ goog.addDependency('../../tests/mocha/test_helpers/procedures.js', ['Blockly.tes
|
||||
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/test_helpers.js', ['Blockly.test.helpers'], ['Blockly.Events.utils', 'Blockly.blocks', 'Blockly.test.helpers.common', 'Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/test_helpers/toolbox_definitions.js', ['Blockly.test.helpers.toolbox_definitions'], [], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/test_helpers/workspace.js', ['Blockly.test.helpers.workspace'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/test_helpers/warnings.js', ['Blockly.test.helpers.warnings'], ['Blockly.Events.utils', 'Blockly.blocks', 'Blockly.test.helpers.common', 'Blockly.utils.KeyCodes'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/test_helpers/workspace.js', ['Blockly.test.helpers.workspace'], ['Blockly.Events.utils', 'Blockly.test.helpers', 'Blockly.test.helpers.warnings'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/theme_test.js', ['Blockly.test.theme'], ['Blockly.Events.utils', 'Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/toolbox_test.js', ['Blockly.test.toolbox'], ['Blockly.test.helpers', 'Blockly.test.helpers.blockDefinitions', 'Blockly.test.helpers.toolbox_definitions'], {'lang': 'es6', 'module': 'goog'});
|
||||
goog.addDependency('../../tests/mocha/tooltip_test.js', ['Blockly.test.tooltip'], ['Blockly.test.helpers'], {'lang': 'es6', 'module': 'goog'});
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
goog.module('Blockly.test.connection');
|
||||
|
||||
const {assertSingleDeprecationWarningCall, createDeprecationWarningStub, createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
|
||||
const {createGenUidStubWithReturns, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers');
|
||||
const {defineRowBlock, defineStatementBlock, defineStackBlock} = goog.require('Blockly.test.helpers.blockDefinitions');
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
goog.module('Blockly.test.json');
|
||||
|
||||
const {addMessageToCleanup, assertNoWarnings, assertWarnings, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
|
||||
const {addMessageToCleanup, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
|
||||
const {assertNoWarnings, assertWarnings} = goog.require('Blockly.test.helpers.warnings');
|
||||
|
||||
|
||||
suite('JSON Block Definitions', function() {
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
goog.module('Blockly.test.registry');
|
||||
|
||||
const {assertWarnings, sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
|
||||
const {assertWarnings} = goog.require('Blockly.test.helpers.warnings');
|
||||
const {sharedTestSetup, sharedTestTeardown} = goog.require('Blockly.test.helpers');
|
||||
|
||||
|
||||
suite('Registry', function() {
|
||||
|
||||
@@ -29,67 +29,6 @@ function assertVariableValues(container, name, type, id) {
|
||||
}
|
||||
exports.assertVariableValues = assertVariableValues;
|
||||
|
||||
/**
|
||||
* Asserts that the given function logs the provided warning messages.
|
||||
* @param {function()} innerFunc The function to call.
|
||||
* @param {Array<!RegExp>|!RegExp} messages A list of regex for the expected
|
||||
* messages (in the expected order).
|
||||
*/
|
||||
function assertWarnings(innerFunc, messages) {
|
||||
if (!Array.isArray(messages)) {
|
||||
messages = [messages];
|
||||
}
|
||||
const warnings = captureWarnings(innerFunc);
|
||||
chai.assert.lengthOf(warnings, messages.length);
|
||||
messages.forEach((message, i) => {
|
||||
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) {
|
||||
assertWarnings(innerFunc, []);
|
||||
}
|
||||
exports.assertNoWarnings = assertNoWarnings;
|
||||
|
||||
/**
|
||||
* Stubs Blockly.utils.deprecation.warn call.
|
||||
* @return {!SinonStub} The created stub.
|
||||
*/
|
||||
function createDeprecationWarningStub() {
|
||||
return sinon.stub(Blockly.utils.deprecation, 'warn');
|
||||
}
|
||||
exports.createDeprecationWarningStub = createDeprecationWarningStub;
|
||||
|
||||
/**
|
||||
* Asserts whether the given deprecation warning stub or call was called with
|
||||
* the expected functionName.
|
||||
* @param {!SinonSpy|!SinonSpyCall} spyOrSpyCall The spy or spy call to use.
|
||||
* @param {string} functionName The function name to check that the given spy or
|
||||
* spy call was called with.
|
||||
*/
|
||||
function assertDeprecationWarningCall(spyOrSpyCall, functionName) {
|
||||
sinon.assert.calledWith(spyOrSpyCall, functionName);
|
||||
}
|
||||
exports.assertDeprecationWarningCall = assertDeprecationWarningCall;
|
||||
|
||||
/**
|
||||
* Asserts that there was a single deprecation warning call with the given
|
||||
* functionName passed.
|
||||
* @param {!SinonSpy} spy The spy to use.
|
||||
* @param {string} functionName The function name to check that the given spy
|
||||
* was called with.
|
||||
*/
|
||||
function assertSingleDeprecationWarningCall(spy, functionName) {
|
||||
sinon.assert.calledOnce(spy);
|
||||
assertDeprecationWarningCall(spy.getCall(0), functionName);
|
||||
}
|
||||
exports.assertSingleDeprecationWarningCall = assertSingleDeprecationWarningCall;
|
||||
|
||||
/**
|
||||
* Safely disposes of Blockly workspace, logging any errors.
|
||||
* Assumes that sharedTestSetup has also been called. This should be called
|
||||
|
||||
74
tests/mocha/test_helpers/warnings.js
Normal file
74
tests/mocha/test_helpers/warnings.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2019 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
goog.module('Blockly.test.helpers.warnings');
|
||||
|
||||
const {captureWarnings} = goog.require('Blockly.test.helpers.common');
|
||||
const {KeyCodes} = goog.require('Blockly.utils.KeyCodes');
|
||||
const eventUtils = goog.require('Blockly.Events.utils');
|
||||
const {Blocks} = goog.require('Blockly.blocks');
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that the given function logs the provided warning messages.
|
||||
* @param {function()} innerFunc The function to call.
|
||||
* @param {Array<!RegExp>|!RegExp} messages A list of regex for the expected
|
||||
* messages (in the expected order).
|
||||
*/
|
||||
function assertWarnings(innerFunc, messages) {
|
||||
if (!Array.isArray(messages)) {
|
||||
messages = [messages];
|
||||
}
|
||||
const warnings = captureWarnings(innerFunc);
|
||||
chai.assert.lengthOf(warnings, messages.length);
|
||||
messages.forEach((message, i) => {
|
||||
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) {
|
||||
assertWarnings(innerFunc, []);
|
||||
}
|
||||
exports.assertNoWarnings = assertNoWarnings;
|
||||
|
||||
/**
|
||||
* Stubs Blockly.utils.deprecation.warn call.
|
||||
* @return {!SinonStub} The created stub.
|
||||
*/
|
||||
function createDeprecationWarningStub() {
|
||||
return sinon.stub(Blockly.utils.deprecation, 'warn');
|
||||
}
|
||||
exports.createDeprecationWarningStub = createDeprecationWarningStub;
|
||||
|
||||
/**
|
||||
* Asserts whether the given deprecation warning stub or call was called with
|
||||
* the expected functionName.
|
||||
* @param {!SinonSpy|!SinonSpyCall} spyOrSpyCall The spy or spy call to use.
|
||||
* @param {string} functionName The function name to check that the given spy or
|
||||
* spy call was called with.
|
||||
*/
|
||||
function assertDeprecationWarningCall(spyOrSpyCall, functionName) {
|
||||
sinon.assert.calledWith(spyOrSpyCall, functionName);
|
||||
}
|
||||
exports.assertDeprecationWarningCall = assertDeprecationWarningCall;
|
||||
|
||||
/**
|
||||
* Asserts that there was a single deprecation warning call with the given
|
||||
* functionName passed.
|
||||
* @param {!SinonSpy} spy The spy to use.
|
||||
* @param {string} functionName The function name to check that the given spy
|
||||
* was called with.
|
||||
*/
|
||||
function assertSingleDeprecationWarningCall(spy, functionName) {
|
||||
sinon.assert.calledOnce(spy);
|
||||
assertDeprecationWarningCall(spy.getCall(0), functionName);
|
||||
}
|
||||
exports.assertSingleDeprecationWarningCall = assertSingleDeprecationWarningCall;
|
||||
@@ -6,7 +6,8 @@
|
||||
|
||||
goog.module('Blockly.test.helpers.workspace');
|
||||
|
||||
const {assertVariableValues, assertWarnings, workspaceTeardown} = goog.require('Blockly.test.helpers');
|
||||
const {assertVariableValues, workspaceTeardown} = goog.require('Blockly.test.helpers');
|
||||
const {assertWarnings} = goog.require('Blockly.test.helpers.warnings');
|
||||
const eventUtils = goog.require('Blockly.Events.utils');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user