From 77bf94964ac5be15896e16fef5b22b7cf2ad03ce Mon Sep 17 00:00:00 2001 From: Joe Nudell Date: Wed, 5 Jan 2022 11:26:51 -0800 Subject: [PATCH 1/4] fix: allow more client options to be configured via resource url --- client-src/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/client-src/index.js b/client-src/index.js index dc85fdcff0..6cc08c2cc4 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -58,6 +58,18 @@ if (parsedResourceQuery["live-reload"] === "true") { log.info("Live Reloading enabled."); } +if (parsedResourceQuery.progress === "true") { + options.progress = true; + + log.info("Progress reporting enabled."); +} + +if (parsedResourceQuery.overlay === "true") { + options.overlay = true; + + log.info("Error overlay enabled."); +} + if (parsedResourceQuery.logging) { options.logging = parsedResourceQuery.logging; } From 5fa140538ccc2acf75563a9f0110afc70c581d84 Mon Sep 17 00:00:00 2001 From: Joe Nudell Date: Wed, 12 Jan 2022 12:02:12 -0800 Subject: [PATCH 2/4] fix: support json options for overlay in resource query --- client-src/index.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/client-src/index.js b/client-src/index.js index 6cc08c2cc4..d614a63783 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -64,10 +64,22 @@ if (parsedResourceQuery.progress === "true") { log.info("Progress reporting enabled."); } -if (parsedResourceQuery.overlay === "true") { - options.overlay = true; - - log.info("Error overlay enabled."); +if (parsedResourceQuery.overlay) { + try { + options.overlay = JSON.parse(parsedResourceQuery.overlay); + log.info("Error overlay enabled."); + } catch (e) { + log.error("Error parsing overlay options from resource query:", e); + } + + // Fill in default "true" params for partially-specified objects. + if (typeof options.overlay === "object") { + options.overlay = { + errors: true, + warnings: true, + ...options.overlay, + }; + } } if (parsedResourceQuery.logging) { From e72e6fd99800792312551fac979a23523c0222c1 Mon Sep 17 00:00:00 2001 From: Joe Nudell Date: Wed, 12 Jan 2022 12:02:40 -0800 Subject: [PATCH 3/4] test: verify overlay resource query parsing is correct --- test/client/index.test.js | 54 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/test/client/index.test.js b/test/client/index.test.js index ee3c64a947..75a902cb1a 100644 --- a/test/client/index.test.js +++ b/test/client/index.test.js @@ -208,6 +208,60 @@ describe("index", () => { expect(overlay.show).toBeCalled(); }); + test("should parse overlay options from resource query", () => { + jest.isolateModules(() => { + // Pass JSON config with warnings disabled + global.__resourceQuery = `?overlay=${encodeURIComponent( + `{"warnings": false}` + )}`; + overlay.show.mockReset(); + socket.mockReset(); + jest.unmock("../../client-src/utils/parseURL.js"); + require("../../client-src"); + onSocketMessage = socket.mock.calls[0][1]; + + onSocketMessage.warnings(["warn1"]); + expect(overlay.show).not.toBeCalled(); + + onSocketMessage.errors(["error1"]); + expect(overlay.show).toBeCalledTimes(1); + }); + + jest.isolateModules(() => { + // Pass JSON config with errors disabled + global.__resourceQuery = `?overlay=${encodeURIComponent( + `{"errors": false}` + )}`; + overlay.show.mockReset(); + socket.mockReset(); + jest.unmock("../../client-src/utils/parseURL.js"); + require("../../client-src"); + onSocketMessage = socket.mock.calls[0][1]; + + onSocketMessage.errors(["error1"]); + expect(overlay.show).not.toBeCalled(); + + onSocketMessage.warnings(["warn1"]); + expect(overlay.show).toBeCalledTimes(1); + }); + + jest.isolateModules(() => { + // Use simple boolean + global.__resourceQuery = "?overlay=true"; + jest.unmock("../../client-src/utils/parseURL.js"); + socket.mockReset(); + overlay.show.mockReset(); + require("../../client-src"); + onSocketMessage = socket.mock.calls[0][1]; + + onSocketMessage.warnings(["warn2"]); + expect(overlay.show).toBeCalledTimes(1); + + onSocketMessage.errors(["error2"]); + expect(overlay.show).toBeCalledTimes(2); + }); + }); + test("should run onSocketMessage.error", () => { onSocketMessage.error("error!!"); From e29b6b7dfa77c30726c3f1f8d2f864fc6aeecb55 Mon Sep 17 00:00:00 2001 From: Joe Nudell Date: Wed, 12 Jan 2022 17:57:12 -0800 Subject: [PATCH 4/4] fix: add more nuance to logging about overlay option state --- client-src/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client-src/index.js b/client-src/index.js index d614a63783..8109be851b 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -67,7 +67,6 @@ if (parsedResourceQuery.progress === "true") { if (parsedResourceQuery.overlay) { try { options.overlay = JSON.parse(parsedResourceQuery.overlay); - log.info("Error overlay enabled."); } catch (e) { log.error("Error parsing overlay options from resource query:", e); } @@ -80,6 +79,17 @@ if (parsedResourceQuery.overlay) { ...options.overlay, }; } + + if ( + options.overlay === true || + (options.overlay.errors && options.overlay.warnings) + ) { + log.info("Overlay is enabled for errors and warnings."); + } else if (options.overlay.errors) { + log.info("Overlay is enabled for errors."); + } else if (options.overlay.warnings) { + log.info("Overlay is enabled for warnings."); + } } if (parsedResourceQuery.logging) {