Use captureWarning helper from dev-tools instead of mocha/test_helpers.js implementation.

This commit is contained in:
Aaron Dodson
2021-06-15 19:10:13 +00:00
parent e5a2df301a
commit 355c54f70a
4 changed files with 5 additions and 24 deletions

View File

@@ -21,7 +21,7 @@
"assertVariableValues": true,
"assertNoWarnings": true,
"assertWarnings": true,
"captureWarnings": true,
"captureWarnings": false,
"createDeprecationWarningStub": true,
"createKeyDownEvent": true,
"createRenderedBlock": true,

View File

@@ -85,7 +85,7 @@ suite('Registry', function() {
test('Incorrect Plugin Name', function() {
this.options['plugins']['test'] = 'random';
var testClass;
var warnings = captureWarnings(() => {
var warnings = testHelpers.captureWarnings(() => {
testClass = Blockly.registry.getClassFromOptions('test', this.options);
});
chai.assert.isNull(testClass);

View File

@@ -20,25 +20,6 @@ function assertVariableValues(container, name, type, id) {
chai.assert.equal(variable.getId(), id);
}
/**
* Captures the strings sent to console.warn() when calling a function.
* @param {function} innerFunc The function where warnings may called.
* @return {string[]} The warning messages (only the first arguments).
*/
function captureWarnings(innerFunc) {
var msgs = [];
var nativeConsoleWarn = console.warn;
try {
console.warn = function(msg) {
msgs.push(msg);
};
innerFunc();
} finally {
console.warn = nativeConsoleWarn;
}
return msgs;
}
/**
* Asserts that the given function logs the provided warning messages.
* @param {function} innerFunc The function to call.
@@ -49,7 +30,7 @@ function assertWarnings(innerFunc, messages) {
if (!Array.isArray(messages)) {
messages = [messages];
}
var warnings = captureWarnings(innerFunc);
var warnings = testHelpers.captureWarnings(innerFunc);
chai.assert.lengthOf(warnings, messages.length);
messages.forEach((message, i) => {
chai.assert.match(warnings[i], message);

View File

@@ -1303,7 +1303,7 @@ function testAWorkspace() {
this.workspace.createVariable('name1', 'type1', 'id1');
this.workspace.deleteVariableById('id1');
var workspace = this.workspace;
var warnings = captureWarnings(function() {
var warnings = testHelpers.captureWarnings(function() {
workspace.deleteVariableById('id1');
});
chai.assert.equal(warnings.length, 1,
@@ -1332,7 +1332,7 @@ function testAWorkspace() {
createVarBlocksNoEvents(this.workspace, ['id1']);
this.workspace.deleteVariableById('id1');
var workspace = this.workspace;
var warnings = captureWarnings(function() {
var warnings = testHelpers.captureWarnings(function() {
workspace.deleteVariableById('id1');
});
chai.assert.equal(warnings.length, 1,