From 3b45606f92f24dbc5c9db3de47317807248f1afc Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Thu, 26 May 2022 16:56:22 +0100 Subject: [PATCH] fix(tests): Use the blockly repository path for all script src= URLs Previously the (non-advanced) playground was only correctly loadging on localhost because you can put an arbitrary number of "../"s in front of a relative URL and it just takes you to the root directory. --- tests/bootstrap.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/bootstrap.js b/tests/bootstrap.js index 038e14d1c..32c451598 100644 --- a/tests/bootstrap.js +++ b/tests/bootstrap.js @@ -35,6 +35,7 @@ 'use strict'; (function() { + // Values usedd to compute default bootstrap options. const isIe = navigator.userAgent.indexOf('MSIE') !== -1 || navigator.appVersion.indexOf('Trident/') > -1; const localhosts = ['localhost', '127.0.0.1', '[::1]']; @@ -44,6 +45,10 @@ // Decide whether to use compmiled mode or not. Please see issue // #5557 for more information. loadCompiled: isIe || !localhosts.includes(location.hostname), + + // URL of the blockly repository. Default value will work so long + // as top-level page is loaded from somewhere in tests/. + root: window.location.href.replace(/\/tests\/.*$/, '/'), }; if (typeof window.BLOCKLY_BOOTSTRAP_OPTIONS === 'object') { Object.assign(options, window.BLOCKLY_BOOTSTRAP_OPTIONS); @@ -57,10 +62,12 @@ // Load the Closure Library's base.js (the only part of the // libary we use, mainly for goog.require / goog.provide / // goog.module). - document.write(''); + document.write( + ''); // Load dependency graph info from build/deps.js. To update // deps.js, run `npm run build:deps`. - document.write(''); + document.write( + ''); // Msg loading kludge. This should go away once #5409 and/or // #1895 are fixed. @@ -68,7 +75,8 @@ // Load messages into a temporary Blockly.Msg object, deleting it // afterwards (after saving the messages!) window.Blockly = {Msg: Object.create(null)}; - document.write(''); + document.write( + ''); document.write(` '); + document.write(''); } } })();