-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Description
Describe the bug
Due to the use of global variables to pass some (but not all) items obtained from the jsdom package from scripts/package/node/core.js to core/utils/xml.ts, XML serialisation (and therefore Blockly generally) is broken if:
- Blockly is being loaded in node.js (or another runtime that does not have a native DOM implementation), and
- more than one copy of Blocly is loaded.
Normally modules cannot be loaded more than once, but multiple copies of a module with different paths, or a single copy that is included in more than one (e.g. webpack) bundle, can defeat the usual deduping of loads to satisfy imports and requires.
Specifically, due to this bug, the @blockly/dev-scripts's test script, used by plugin developers (including us), is broken when used to test a project with more than one test/*.mocha.js test harness when using Blockly v9.2.0.
To Reproduce
Steps to reproduce the behavior:
- Clone
blockly-samples. - Choose any plugin with more than one test script in its
test/drirectory, where at least one of those tests creates a block. - Run
npm upgrade blocklyto bumpblocklyto 9.2.0. - Run
npm test - Observe test errors.
Expected behaviour
Test should pass; no errors should occur.
Stack Traces
TypeError: Failed to execute 'serializeToString' on 'XMLSerializer': parameter 1 is not of type 'Node'.
at Object.exports.convert (webpack-internal:///./node_modules/jsdom/lib/jsdom/living/generated/Node.js:25:9)
at XMLSerializer.serializeToString (webpack-internal:///./node_modules/jsdom/lib/jsdom/living/generated/XMLSerializer.js:111:23)
at domToText$$module$build$src$core$utils$xml (webpack-internal:///./node_modules/blockly/blockly_compressed.js:74:333)
Additional context
See this lengthy discussion for more detail about the issue.