aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-css-plugin/css-bundle/tests/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-css-plugin/css-bundle/tests/utils.ts')
-rw-r--r--sonar-css-plugin/css-bundle/tests/utils.ts36
1 files changed, 36 insertions, 0 deletions
diff --git a/sonar-css-plugin/css-bundle/tests/utils.ts b/sonar-css-plugin/css-bundle/tests/utils.ts
new file mode 100644
index 0000000..0be132b
--- /dev/null
+++ b/sonar-css-plugin/css-bundle/tests/utils.ts
@@ -0,0 +1,36 @@
+import * as http from "http";
+import { Server } from "http";
+import { AddressInfo } from "net";
+
+export function postToServer(
+ data: string,
+ endpoint: string,
+ server: Server
+): Promise<string> {
+ const options = {
+ host: "localhost",
+ port: (<AddressInfo>server.address()).port,
+ path: endpoint,
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json"
+ }
+ };
+
+ return new Promise((resolve, reject) => {
+ let response = "";
+
+ const req = http.request(options, res => {
+ res.on("data", chunk => {
+ response += chunk;
+ });
+
+ res.on("end", () => resolve(response));
+ });
+
+ req.on("error", reject);
+
+ req.write(data);
+ req.end();
+ });
+}