From fe84605f2477ed050bb4f9daa8533f418008aeac Mon Sep 17 00:00:00 2001 From: Billy Richardson Date: Tue, 31 May 2022 05:16:47 -0700 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=91=B7=20Add=20JS=20QUnit=20tests=20t?= =?UTF-8?q?o=20build=20workflow=20with=20node-qunit-puppeteer=20(#4534)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44d27367b..84c8c2f39 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -65,6 +65,19 @@ jobs: run: | pytest + test-js-unit: + name: ๐Ÿงช JavaScript unit tests + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: ๐Ÿ— Set up test dependencies + run: | + npm -g install node-qunit-puppeteer@2.1.0 + - name: ๐Ÿš€ Run helpers.js test suite + run: | + node-qunit-puppeteer tests/static/js/test-helpers.html + test-install: name: ๐Ÿงช Installation tests needs: build @@ -146,6 +159,7 @@ jobs: needs: - pre-commit - test-unit + - test-js-unit - test-install - test-e2e runs-on: ubuntu-latest From e8be86c15f8de90b2b429e80ca75594c44345e0c Mon Sep 17 00:00:00 2001 From: Billy Richardson Date: Tue, 31 May 2022 05:17:27 -0700 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20Add=20a=20few=20unit=20tests=20?= =?UTF-8?q?for=20helpers.js=20(#4529)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/octoprint/static/js/app/helpers.js | 8 +- tests/static/js/test-helpers.js | 221 +++++++++++++++++++++++++ 2 files changed, 227 insertions(+), 2 deletions(-) diff --git a/src/octoprint/static/js/app/helpers.js b/src/octoprint/static/js/app/helpers.js index fe6b9d649..8a3c015cc 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -1555,7 +1555,7 @@ var copyToClipboard = function (text) { }; var getExternalHostUrl = function () { - var loc = window.location; + var loc = fetchWindowLocation(); var port = ""; if ( (loc.protocol === "http:" && loc.port !== "80") || @@ -1576,7 +1576,7 @@ var validateWebcamUrl = function (streamUrl) { if (lower.startsWith("//")) { // protocol relative - toParse = window.location.protocol + streamUrl; + toParse = fetchWindowLocation().protocol + streamUrl; } else if (lower.startsWith("/")) { // host relative toParse = getExternalHostUrl() + streamUrl; @@ -1751,3 +1751,7 @@ var startWebRTC = function (videoElement, streamUrl, iceServers) { negotiateWebRTC(streamUrl); return pc; }; + +var fetchWindowLocation = function () { + return window.location; +}; diff --git a/tests/static/js/test-helpers.js b/tests/static/js/test-helpers.js index 89b947a06..ccf34fc5a 100644 --- a/tests/static/js/test-helpers.js +++ b/tests/static/js/test-helpers.js @@ -189,3 +189,224 @@ QUnit.cases( "As expected: " + String(params.expected) ); }); + +QUnit.module("determineWebcamStreamType"); +QUnit.cases( + (function () { + var cases = []; + + var params = [ + { + streamUrl: undefined, + exceptionExpected: "Empty streamUrl. Cannot determine stream type.", + expectedResult: undefined + }, + { + streamUrl: "invalidUrl", + exceptionExpected: "Invalid streamUrl. Cannot determine stream type.", + expectedResult: undefined + }, + { + streamUrl: "webrtc://localhost/stream", + exceptionExpected: undefined, + expectedResult: "webrtc" + }, + { + streamUrl: "webrtcs://localhost/stream", + exceptionExpected: undefined, + expectedResult: "webrtc" + }, + { + streamUrl: "https://localhost/stream.m3u8", + exceptionExpected: undefined, + expectedResult: "hls" + }, + { + streamUrl: "https://localhost/stream", + exceptionExpected: undefined, + expectedResult: "mjpg" + } + ]; + + var param, i; + for (i = 0; i < params.length; i++) { + param = params[i]; + param["title"] = + String(param.streamUrl) + + String(param.exceptionExpected) + + String(param.expectedResult); + cases.push(param); + } + + return cases; + })() +).test("determineWebcamStreamType", function (params, assert) { + var exceptionMessage = undefined; + var result = undefined; + + try { + result = determineWebcamStreamType(params.streamUrl); + } catch (ex) { + exceptionMessage = ex; + } + + assert.equal( + params.exceptionExpected, + exceptionMessage, + "Exception expected: " + String(params.exceptionExpected) + ); + + assert.equal( + params.expectedResult, + result, + "As expected: " + String(params.expectedResult) + ); +}); + +QUnit.module("validateWebcamUrl"); +QUnit.cases( + (function () { + var cases = []; + + var params = [ + { + streamUrl: undefined, + expected: false, + windowLocationOverride: undefined + }, + { + streamUrl: "//localhost/stream", + expected: new URL("https://localhost/stream"), + windowLocationOverride: {protocol: "https:"} + }, + { + streamUrl: "/stream", + expected: new URL("https://localhost/stream"), + windowLocationOverride: { + protocol: "https:", + port: "443", + hostname: "localhost" + } + }, + { + streamUrl: "http://localhost/stream", + expected: new URL("http://localhost/stream"), + windowLocationOverride: undefined + }, + { + streamUrl: "https://localhost/stream", + expected: new URL("https://localhost/stream"), + windowLocationOverride: undefined + }, + { + streamUrl: "webrtc://localhost/stream", + expected: new URL("webrtc://localhost/stream"), + windowLocationOverride: undefined + }, + { + streamUrl: "webrtcs://localhost/stream", + expected: new URL("webrtcs://localhost/stream"), + windowLocationOverride: undefined + }, + { + streamUrl: "invalid", + expected: false, + windowLocationOverride: undefined + }, + { + streamUrl: "//exception", + expected: false, + windowLocationOverride: {protocol: ":"} + } + ]; + + var param, i; + for (i = 0; i < params.length; i++) { + param = params[i]; + param["title"] = String(param.streamUrl) + String(param.expected); + cases.push(param); + } + + return cases; + })() +).test("validateWebcamUrl", function (params, assert) { + if (params.windowLocationOverride) { + fetchWindowLocation = function () { + return params.windowLocationOverride; + }; + } + + var result = validateWebcamUrl(params.streamUrl); + + assert.equal( + params.expected.toString(), + result.toString(), + "As expected: " + String(params.expected) + ); +}); + +QUnit.module("getExternalHostUrl"); +QUnit.cases( + (function () { + var cases = []; + + var params = [ + { + windowLocation: { + protocol: "https:", + port: "443", + hostname: "localhost" + }, + expected: "https://localhost" + }, + { + windowLocation: { + protocol: "https:", + port: "8000", + hostname: "localhost" + }, + expected: "https://localhost:8000" + }, + + { + windowLocation: { + protocol: "http:", + port: "80", + hostname: "localhost" + }, + expected: "http://localhost" + }, + { + windowLocation: { + protocol: "http:", + port: "8000", + hostname: "localhost" + }, + expected: "http://localhost:8000" + } + ]; + + var param, i; + for (i = 0; i < params.length; i++) { + param = params[i]; + param["title"] = + String(param.windowLocation.protocol) + + "//" + + String(param.windowLocation.hostname) + + String(param.windowLocation.port); + cases.push(param); + } + + return cases; + })() +).test("getExternalHostUrl", function (params, assert) { + if (params.windowLocation) { + fetchWindowLocation = function () { + return params.windowLocation; + }; + } + + var result = getExternalHostUrl(); + + assert.equal(params.expected, result, "As expected: " + String(params.expected)); +}); From 999ccac2308d613903448aaf654a4f38f767a870 Mon Sep 17 00:00:00 2001 From: luzpaz Date: Tue, 31 May 2022 08:18:38 -0400 Subject: [PATCH 3/3] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20misc.=20typos=20?= =?UTF-8?q?(#4533)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Found via `codespell -q 3 -S *.po` --- docs/api/timelapse.rst | 4 ++-- docs/api/util.rst | 2 +- docs/features/accesscontrol.rst | 4 ++-- docs/plugins/hooks.rst | 2 +- docs/plugins/python3_migration.rst | 2 +- src/octoprint/plugins/pluginmanager/__init__.py | 2 +- src/octoprint/static/js/app/viewmodels/control.js | 2 +- src/octoprint/static/js/recovery/recovery.js | 2 +- src/octoprint/static/less/bootstrap/reset.less | 2 +- src/octoprint/util/json/serializing.py | 2 +- src/octoprint/util/pip.py | 2 +- tests/filemanager/test_localstorage.py | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/api/timelapse.rst b/docs/api/timelapse.rst index ebe291e83..e739b43ee 100644 --- a/docs/api/timelapse.rst +++ b/docs/api/timelapse.rst @@ -76,7 +76,7 @@ Change current timelapse config .. http:post:: /api/timelapse Save a new :ref:`timelapse configuration ` to use for the next print. Set the optional ``save`` flag in the - configuration to ``true`` in order to make the new configuration persist accross restarts. + configuration to ``true`` in order to make the new configuration persist across restarts. The configuration is expected as the request body. @@ -220,7 +220,7 @@ Timelapse configuration * - ``save`` - 1 - bool - - Optional flag to be included when when saving a configuration to make the configuration persist accross restarts + - Optional flag to be included when when saving a configuration to make the configuration persist across restarts Further fields are timelapse type specific, see below for details. diff --git a/docs/api/util.rst b/docs/api/util.rst index bb1271240..e3ea44b29 100644 --- a/docs/api/util.rst +++ b/docs/api/util.rst @@ -76,7 +76,7 @@ Various tests * ``content_type_whitelist``: Optional array of supported content types. If set and the URL returns a content type not included in this list, the test will fail. E.g. ``["image/*", "text/plain"]``. * ``content_type_blacklist``: Optional array of unsupported content types. If set and the URL returns a content - type included in this list, the test wil fail. E.g. ``["video/*"]``. Can be used together with ``content_type_whitelist`` + type included in this list, the test will fail. E.g. ``["video/*"]``. Can be used together with ``content_type_whitelist`` to further limit broader content type definition, e.g. by putting ``image/*`` into the whitelist, but disallowing PNG by including ``image/png`` on the blacklist. diff --git a/docs/features/accesscontrol.rst b/docs/features/accesscontrol.rst index 218e3bb9c..97c166a07 100644 --- a/docs/features/accesscontrol.rst +++ b/docs/features/accesscontrol.rst @@ -110,7 +110,7 @@ The subnet to use is usually the IP address range of your LAN, which sounds scar actually isn't. Just `figure out your PC's IP address and subnet mask `_ and then combine both with a / in between. -On OctoPi (or another Linux distribution) you can use the follwing command: +On OctoPi (or another Linux distribution) you can use the following command: .. code-block:: @@ -189,7 +189,7 @@ further down there's also a dedicated list of steps for OctoPi specifically. 4. Restart OctoPrint, check that everything works. -This will automatically log you in as the user you specified whenver you connect to +This will automatically log you in as the user you specified whenever you connect to OctoPrint from an address in the address range (e.g. a device on your local network). OctoPi specific steps diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index 6d1b32709..47822eb48 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -1433,7 +1433,7 @@ octoprint.server.http.access_validator Allows adding additional access validators to the default tornado routers. - Your plugin might need to this to restrict acccess to downloads and webcam snapshots further. + Your plugin might need to this to restrict access to downloads and webcam snapshots further. .. important:: diff --git a/docs/plugins/python3_migration.rst b/docs/plugins/python3_migration.rst index cbf9ccaf4..d90b74e22 100644 --- a/docs/plugins/python3_migration.rst +++ b/docs/plugins/python3_migration.rst @@ -235,7 +235,7 @@ will now fail with an error. You'll need to explicitly make the import a relativ from . import my_sub_package -To make your code behave the same in that regard unter both Python 2 and Python 3, you should add the corresponding +To make your code behave the same in that regard in both Python 2 and Python 3, you should add the corresponding future import: .. code-block:: python diff --git a/src/octoprint/plugins/pluginmanager/__init__.py b/src/octoprint/plugins/pluginmanager/__init__.py index 4b338e668..1c8a5f6be 100644 --- a/src/octoprint/plugins/pluginmanager/__init__.py +++ b/src/octoprint/plugins/pluginmanager/__init__.py @@ -97,7 +97,7 @@ def map_repository_entry(entry): entry["compatibility"]["python"] ) else: - # we default to only assume py2 compatiblity for now + # we default to only assume py2 compatibility for now result["is_compatible"]["python"] = is_python_compatible(">=2.7,<3") return result diff --git a/src/octoprint/static/js/app/viewmodels/control.js b/src/octoprint/static/js/app/viewmodels/control.js index ca8c4cb4b..81fd783d4 100644 --- a/src/octoprint/static/js/app/viewmodels/control.js +++ b/src/octoprint/static/js/app/viewmodels/control.js @@ -868,7 +868,7 @@ $(function () { // If we found the rotation container, the view is rotated 90 degrees. This // means we need to manually calculate the player dimensions and apply them // to the rotation target where height = width and width = height (to - // accomodate the rotation). The target is centered in the container and + // accommodate the rotation). The target is centered in the container and // rotated around its center, so after we manually resized the container // everything will layout nicely. if (rotationContainer && player.videoWidth && player.videoHeight) { diff --git a/src/octoprint/static/js/recovery/recovery.js b/src/octoprint/static/js/recovery/recovery.js index 6f5bc671e..1ce4cbc6e 100644 --- a/src/octoprint/static/js/recovery/recovery.js +++ b/src/octoprint/static/js/recovery/recovery.js @@ -41,7 +41,7 @@ $(function () { // system commands self.systemCommands = ko.observableArray([]); - // systen info + // system info self.systemInfo = ko.observableArray([]); // printer diff --git a/src/octoprint/static/less/bootstrap/reset.less b/src/octoprint/static/less/bootstrap/reset.less index cf00d9c23..7afdcaecb 100644 --- a/src/octoprint/static/less/bootstrap/reset.less +++ b/src/octoprint/static/less/bootstrap/reset.less @@ -77,7 +77,7 @@ sub { img { /* Responsive images (ensure images don't scale beyond their parents) */ - max-width: 100%; /* Part 1: Set a maxium relative to the parent */ + max-width: 100%; /* Part 1: Set a maximum relative to the parent */ width: auto\9; /* IE7-8 need help adjusting responsive images */ height: auto; /* Part 2: Scale the height according to the width, otherwise you get stretching */ diff --git a/src/octoprint/util/json/serializing.py b/src/octoprint/util/json/serializing.py index 668bf4bd7..d8b9ab970 100644 --- a/src/octoprint/util/json/serializing.py +++ b/src/octoprint/util/json/serializing.py @@ -57,7 +57,7 @@ class SerializableJsonEncoding(JsonEncoding): def encode(cls, val): """ Recursively replace all instances of encodable types with their encoded - value. This is useful over the ``default=`` functionallity of the JSON + value. This is useful over the ``default=`` functionality of the JSON encoder because JSON will not call default for tuples, lists, ints, etc: https://docs.python.org/3/library/json.html#json.JSONEncoder diff --git a/src/octoprint/util/pip.py b/src/octoprint/util/pip.py index 5dc5c9340..ff25391e1 100644 --- a/src/octoprint/util/pip.py +++ b/src/octoprint/util/pip.py @@ -83,7 +83,7 @@ def is_python_mismatch(lines): def is_egg_problem(lines): """ - Returns whether the given output lines indicates an occurence of the "egg-problem". + Returns whether the given output lines indicates an occurrence of the "egg-problem". If something (target or dependency of target) was installed as an egg at an earlier date (e.g. thanks to just running python setup.py install), pip install will throw an diff --git a/tests/filemanager/test_localstorage.py b/tests/filemanager/test_localstorage.py index 508446f26..13fe028a1 100644 --- a/tests/filemanager/test_localstorage.py +++ b/tests/filemanager/test_localstorage.py @@ -896,7 +896,7 @@ class LocalStorageTest(unittest.TestCase): """ Adds a folder to the storage. - Verifies existance of folder. + Verifies existence of folder. Returns sanitized path. """