From b567eba324bf7035888b6ed80f4772a070229177 Mon Sep 17 00:00:00 2001 From: Pierre Awaragi Date: Tue, 16 Apr 2024 13:31:49 -0400 Subject: [PATCH] added request timeout and request socket timeout options (default undefined) --- README.md | 6 +++++- lib/eleventy-plugin-plantuml.js | 7 +++++- test/eleventy-plugin-plantuml.test.js | 31 +++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b9a56c..9850904 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,9 @@ eleventyConfig.addPlugin(plantuml.plugin, { port: 8888, prefix: "", outputType: "svg", - imgClass: "plantuml", + imgClass: "plantuml", + requestTimeout: undefined, // undefined or millisecondes + requestSocketTimeout: undefined, // undefined or millisecondes }); ``` @@ -42,6 +44,8 @@ If the server options are omitted, the plugin defaults to { // request url - const response = request("GET", url); + const response = request("GET", url, { + timeout: options.requestTimeout, + socketTimeout: options.requestSocketTimeout, + }); // convert from Uint8Array to buffer return Buffer.from(response.getBody()); }; diff --git a/test/eleventy-plugin-plantuml.test.js b/test/eleventy-plugin-plantuml.test.js index 6f67b8a..9298f39 100644 --- a/test/eleventy-plugin-plantuml.test.js +++ b/test/eleventy-plugin-plantuml.test.js @@ -132,4 +132,35 @@ Bob -> Alice : hello 'Plantuml Diagram' ); }); + + it("Test request timeout", () => { + try { + eleventyPluginPlantuml.highlight( + `@startuml @enduml`, + Object.assign({}, eleventyPluginPlantuml.defaultOptions, { + requestTimeout: 1, + }) + ); + // should not get here + expect(false).beTruthy(); + } catch (e) { + // test passed + expect(e).toBeInstanceOf(Error); } + }); + + it("Test request socket timeout", () => { + try { + eleventyPluginPlantuml.highlight( + `@startuml @enduml`, + Object.assign({}, eleventyPluginPlantuml.defaultOptions, { + requestSocketTimeout: 1, + }) + ); + // should not get here + expect(false).beTruthy(); + } catch (e) { + // test passed + expect(e).toBeInstanceOf(Error); + } + }); });