From 9a90247dcc4ab461bd419f344caf73b4c9503681 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Wed, 8 Sep 2021 19:16:58 +0100 Subject: [PATCH] feat: Use new location for genUid on Blockly.utils.idGenerator Probe for and, if found, stub the new location. --- .../dev-tools/src/block_test_helpers.mocha.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/plugins/dev-tools/src/block_test_helpers.mocha.js b/plugins/dev-tools/src/block_test_helpers.mocha.js index 727c88192c..42be174f8d 100644 --- a/plugins/dev-tools/src/block_test_helpers.mocha.js +++ b/plugins/dev-tools/src/block_test_helpers.mocha.js @@ -186,7 +186,25 @@ export const runSerializationTestSuite = (testCases) => { }); suite('xml round-trip', function() { setup(function() { - sinon.stub(Blockly.utils, 'genUid').returns('1'); + // The genUid is undergoing change as part of the 2021Q3 + // goog.module migration: + // + // - It is being moved from Blockly.utils to + // Blockly.utils.idGenerator (which itself is being renamed + // from IdGenerator). + // - For compatibility with changes to the module system (from + // goog.provide to goog.module and in future to ES modules), + // .genUid is now a wrapper around .TEST_ONLY.genUid, which + // can be safely stubbed by sinon or other similar + // frameworks in a way that will continue to work. + if (Blockly.utils.idGenerator && + Blockly.utils.idGenerator.TEST_ONLY) { + sinon.stub(Blockly.utils.idGenerator.TEST_ONLY, 'genUid') + .returns('1'); + } else { + // Fall back to stubbing original version on Blockly.utils. + sinon.stub(Blockly.utils, 'genUid').returns('1'); + } }); teardown(function() {