diff --git a/src/pyodide.js b/src/pyodide.js index 25691ffd6..c2f1050a9 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -3,7 +3,7 @@ */ // Regexp for validating package name and URI -var package_name_regexp = '[a-z0-9_\-]+' +var package_name_regexp = '[a-z0-9_][a-z0-9_\-]*' var package_uri_regexp = new RegExp('^https?://.*?(' + package_name_regexp + ').js$', 'i'); var package_name_regexp = new RegExp('^' + package_name_regexp + '$', 'i'); @@ -44,8 +44,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { const package = _uri_to_package_name(package_uri); if (package == null) { - console.log(`Invalid package name or URI '${package_uri}'`); - break; + throw new Error(`Invalid package name or URI '${package_uri}'`); } else if (package == package_uri) { package_uri = 'default channel'; } @@ -54,9 +53,10 @@ var languagePluginLoader = new Promise((resolve, reject) => { if (package in loadedPackages) { if (package_uri != loadedPackages[package]) { - console.log(`Error: URI mismatch, attempting to load package ` + - `${package} from ${package_uri} while it is already ` + - `loaded from ${loadedPackages[package]}!`); + throw new Error( + `URI mismatch, attempting to load package ` + + `${package} from ${package_uri} while it is already ` + + `loaded from ${loadedPackages[package]}!`); } } else { toLoad[package] = package_uri; @@ -67,7 +67,7 @@ var languagePluginLoader = new Promise((resolve, reject) => { } }); } else { - console.log(`Unknown package '${package}'`); + log.console(`Unknown package '${package}'`); } } } diff --git a/test/conftest.py b/test/conftest.py index 7d988ede0..9abca9395 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -40,7 +40,8 @@ def _display_driver_logs(browser, driver): elif browser == 'firefox': # browser logs are not available in GeckoDriver # https://github.com/mozilla/geckodriver/issues/284 - print('Cannot access browser logs for Firefox.') + print('Accessing raw browser logs with Selenium is not ' + 'supported by Firefox.') class SeleniumWrapper: diff --git a/test/test_package_loading.py b/test/test_package_loading.py index 52f0d8338..47e87d3df 100644 --- a/test/test_package_loading.py +++ b/test/test_package_loading.py @@ -1,3 +1,5 @@ +import pytest +from selenium.common.exceptions import WebDriverException def test_load_from_url(selenium_standalone, web_server): @@ -16,15 +18,19 @@ def test_load_from_url(selenium_standalone, web_server): def test_uri_mismatch(selenium_standalone): selenium_standalone.load_package('pyparsing') - selenium_standalone.load_package('http://some_url/pyparsing.js') + with pytest.raises(WebDriverException, + match="URI mismatch, attempting " + "to load package pyparsing"): + selenium_standalone.load_package('http://some_url/pyparsing.js') assert "Invalid package name or URI" not in selenium_standalone.logs - assert ("URI mismatch, attempting " - "to load package pyparsing") in selenium_standalone.logs def test_invalid_package_name(selenium): - selenium.load_package('wrong name+$') - assert "Invalid package name or URI" in selenium.logs + with pytest.raises(WebDriverException, + match="Invalid package name or URI"): + selenium.load_package('wrong name+$') selenium.clean_logs() - selenium.load_package('tcp://some_url') - assert "Invalid package name or URI" in selenium.logs + + with pytest.raises(WebDriverException, + match="Invalid package name or URI"): + selenium.load_package('tcp://some_url')