From 13d52b7dd495c68c72ad8ab3f5063307bf42cfad Mon Sep 17 00:00:00 2001 From: Tibor Blenessy Date: Mon, 13 Jan 2020 11:44:34 +0100 Subject: Implement close endpoint to shutdown the Node.js process (#243) --- sonar-css-plugin/css-bundle/src/server.ts | 7 +++++++ sonar-css-plugin/css-bundle/tests/server.test.ts | 9 +++++++++ 2 files changed, 16 insertions(+) (limited to 'sonar-css-plugin/css-bundle') diff --git a/sonar-css-plugin/css-bundle/src/server.ts b/sonar-css-plugin/css-bundle/src/server.ts index 93bb6cb..e9c66c0 100644 --- a/sonar-css-plugin/css-bundle/src/server.ts +++ b/sonar-css-plugin/css-bundle/src/server.ts @@ -27,6 +27,13 @@ export function start(port = 0): Promise { resp.send("OK!") ); + app.post("/close", (_req: express.Request, resp: express.Response) => { + console.log("DEBUG stylelint-bridge server will shutdown"); + resp.end(() => { + server.close(); + }); + }); + // every time something is wrong we log error and send empty response (with 0 issues) // it's important to keep this call last in configuring "app" app.use( diff --git a/sonar-css-plugin/css-bundle/tests/server.test.ts b/sonar-css-plugin/css-bundle/tests/server.test.ts index 84fc617..8574129 100644 --- a/sonar-css-plugin/css-bundle/tests/server.test.ts +++ b/sonar-css-plugin/css-bundle/tests/server.test.ts @@ -167,3 +167,12 @@ describe("server", () => { return postToServer(data, endpoint, server); } }); + +describe("server close", () => { + it("should stop listening when closed", async () => { + const server = await start(); + expect(server.listening).toBeTruthy(); + await postToServer("", "/close", server); + expect(server.listening).toBeFalsy(); + }); +}); -- cgit v1.2.3