chore: Improve code health of generator tests. (#8703)

This commit is contained in:
Aaron Dodson
2025-01-06 10:55:57 -08:00
committed by GitHub
parent b8bb26f8fd
commit bd7c86a909
2 changed files with 15 additions and 12 deletions

View File

@@ -38,7 +38,7 @@ function start() {
* If some tests are failing, load test suites individually to continue * If some tests are failing, load test suites individually to continue
* debugging. * debugging.
*/ */
function loadSelected() { async function loadSelected() {
var output = document.getElementById('importExport'); var output = document.getElementById('importExport');
output.style.background = 'gray'; output.style.background = 'gray';
@@ -53,9 +53,12 @@ function loadSelected() {
if (boxList[i].checked) { if (boxList[i].checked) {
var testUrl = boxList[i].value; var testUrl = boxList[i].value;
if (testUrl) { if (testUrl) {
var xmlText = fetchFile(testUrl); var xmlText = await fetchFile(testUrl);
if (xmlText !== null) { if (xmlText !== null) {
fromXml(testUrl, xmlText, /* opt_append */ true); fromXml(testUrl, xmlText, /* opt_append */ true);
// Clean up the workspace to normalize the position of blocks and
// thus the order of functions in the generated code.
Blockly.getMainWorkspace().cleanUp();
} }
} }
} }
@@ -67,23 +70,24 @@ function loadSelected() {
/** /**
* Ask the user for a file name, then load that file's contents. * Ask the user for a file name, then load that file's contents.
*/ */
function loadOther() { async function loadOther() {
var url = window.prompt('Enter URL of test file.'); var url = window.prompt('Enter URL of test file.');
if (!url) { if (!url) {
return; return;
} }
var xmlText = fetchFile(url); var xmlText = await fetchFile(url);
if (xmlText !== null) { if (xmlText !== null) {
fromXml(url, xmlText); fromXml(url, xmlText);
} }
} }
function fetchFile(xmlUrl) { async function fetchFile(xmlUrl) {
try { try {
var xmlHttp = new XMLHttpRequest(); const response = await fetch(xmlUrl);
xmlHttp.open('GET', xmlUrl, false); if (!response.ok) {
xmlHttp.setRequestHeader('Content-Type', 'text/xml'); throw new Error(`Got a 404 when loading ${xmlUrl}`);
xmlHttp.send(''); }
return response.text();
} catch (e) { } catch (e) {
// Attempt to diagnose the problem. // Attempt to diagnose the problem.
var msg = 'Error: Unable to load XML data.\n'; var msg = 'Error: Unable to load XML data.\n';
@@ -95,7 +99,6 @@ function fetchFile(xmlUrl) {
alert(msg + '\n' + e); alert(msg + '\n' + e);
return null; return null;
} }
return xmlHttp.responseText;
} }
/** /**
@@ -188,7 +191,7 @@ function toDart() {
function changeIndex() { function changeIndex() {
var oneBasedIndex = document.getElementById('indexing').checked; var oneBasedIndex = document.getElementById('indexing').checked;
demoWorkspace.options.oneBasedIndex = oneBasedIndex; demoWorkspace.options.oneBasedIndex = oneBasedIndex;
demoWorkspace.getToolbox().flyout_.workspace_.options.oneBasedIndex = oneBasedIndex; demoWorkspace.getToolbox().getFlyout().getWorkspace().options.oneBasedIndex = oneBasedIndex;
} }
</script> </script>

View File

@@ -78,7 +78,7 @@ async function runGeneratorsInBrowser(outputDir) {
await browser.execute(function() { await browser.execute(function() {
checkAll(); checkAll();
loadSelected(); return loadSelected();
}); });
await runLangGeneratorInBrowser(browser, prefix + '.js', await runLangGeneratorInBrowser(browser, prefix + '.js',