Skip to content

Commit

Permalink
fix: fixup warning helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Mar 2, 2022
1 parent 9c13a36 commit 0e39153
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
14 changes: 7 additions & 7 deletions tests/deps.mocha.js

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

5 changes: 3 additions & 2 deletions tests/mocha/block_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +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, sharedTestSetup, sharedTestTeardown, workspaceTeardown} = goog.require('Blockly.test.helpers.setupTeardown');
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/field_registry_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

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

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


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

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

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


suite('Abstract Fields', function() {
Expand Down
21 changes: 0 additions & 21 deletions tests/mocha/test_helpers/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,24 +110,3 @@ function runTestSuites(testSuites, createTestCaseCallback) {
});
}
exports.runTestSuites = runTestSuites;

/**
* Captures the strings sent to console.warn() when calling a function.
* Copies from core.
* @param {Function} innerFunc The function where warnings may called.
* @return {Array<string>} The warning messages (only the first arguments).
*/
function captureWarnings(innerFunc) {
const msgs = [];
const nativeConsoleWarn = console.warn;
try {
console.warn = function(msg) {
msgs.push(msg);
};
innerFunc();
} finally {
console.warn = nativeConsoleWarn;
}
return msgs;
}
exports.captureWarnings = captureWarnings;
24 changes: 20 additions & 4 deletions tests/mocha/test_helpers/warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,27 @@

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');

/**
* Captures the strings sent to console.warn() when calling a function.
* Copies from core.
* @param {Function} innerFunc The function where warnings may called.
* @return {Array<string>} The warning messages (only the first arguments).
*/
function captureWarnings(innerFunc) {
const msgs = [];
const nativeConsoleWarn = console.warn;
try {
console.warn = function(msg) {
msgs.push(msg);
};
innerFunc();
} finally {
console.warn = nativeConsoleWarn;
}
return msgs;
}
exports.captureWarnings = captureWarnings;

/**
* Asserts that the given function logs the provided warning messages.
Expand Down

0 comments on commit 0e39153

Please sign in to comment.