diff options
| author | Elena Vilchik | 2019-12-18 17:10:10 +0100 | 
|---|---|---|
| committer | Alban Auzeill | 2019-12-18 17:10:10 +0100 | 
| commit | c8f0071c4f5336dfe0efc5d3c218ab49f2401264 (patch) | |
| tree | 254cd5ed9531d7c62bab4f8ec082e085795ecb8f /sonar-css-plugin/css-bundle/tests/utils.ts | |
| parent | 13fe08e87c8a70ffe6e248b774ef826bbe1f779d (diff) | |
| download | sonar-css-c8f0071c4f5336dfe0efc5d3c218ab49f2401264.tar.bz2 | |
Rely on NodeJS API of Stylelint to execute CSS rules (#221)
Diffstat (limited to 'sonar-css-plugin/css-bundle/tests/utils.ts')
| -rw-r--r-- | sonar-css-plugin/css-bundle/tests/utils.ts | 36 | 
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(); +  }); +} | 
