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/server-mock-stylelint.test.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/server-mock-stylelint.test.ts')
| -rw-r--r-- | sonar-css-plugin/css-bundle/tests/server-mock-stylelint.test.ts | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sonar-css-plugin/css-bundle/tests/server-mock-stylelint.test.ts b/sonar-css-plugin/css-bundle/tests/server-mock-stylelint.test.ts new file mode 100644 index 0000000..f7df176 --- /dev/null +++ b/sonar-css-plugin/css-bundle/tests/server-mock-stylelint.test.ts @@ -0,0 +1,51 @@ +import { start, setLogHandlersForTests } from "../src/server"; +import { Server } from "http"; +import * as path from "path"; +import { promisify } from "util"; +import * as stylelint from "stylelint"; +import { postToServer } from "./utils"; + +const filePath = path.join(__dirname, "fixtures", "file.css"); + +const request = JSON.stringify({ + filePath, + configFile: path.join(__dirname, "fixtures", "stylelintconfig.json") +}); + +jest.mock("stylelint"); + +describe("server", () => { + let server: Server; + let close: () => Promise<void>; + const logSpy = jest.fn(); + const errorSpy = jest.fn(); + + beforeAll(async () => { + setLogHandlersForTests(logSpy, errorSpy); + server = await start(); + close = promisify(server.close.bind(server)); + }); + + afterAll(async () => { + jest.restoreAllMocks(); + await close(); + }); + + it("should not return issues for not original file", async () => { + (stylelint.lint as any).mockResolvedValue({ + results: [{ source: "foo.bar" }] + }); + const response = await postToServer(request, "/analyze", server); + expect(JSON.parse(response)).toEqual([]); + expect(logSpy).toHaveBeenCalledWith( + `DEBUG For file [${filePath}] received issues with [foo.bar] as a source. They will not be reported.` + ); + }); + + it("should not return issues when failed promise returned", async () => { + (stylelint.lint as any).mockRejectedValue("some reason"); + const response = await postToServer(request, "/analyze", server); + expect(JSON.parse(response)).toEqual([]); + expect(errorSpy).toHaveBeenCalledWith("some reason"); + }); +}); |
