test("should not be able to listen if the server is already listening", async () => { // arrange process.env.CUBEJS_ENABLE_TLS = "false"; let cubeServer = new CubeServer(); // act try { await cubeServer.listen(); await cubeServer.listen(); } catch (err) { // assert expect(err.message).toBe("CubeServer is already listening"); expect(http.createServer).toHaveBeenCalledTimes(1); expect(http.__mockServer.listen).toHaveBeenCalledTimes(1); expect(cubeServer.server).not.toBe(null); } });
expect(protocol.logResponseError).not.toBe(false)
test("fetch 404", async () => { expect.assertions(1); try { await fetch("/404"); } catch (err) { expect(err.message).toBe(body404.message); } });
describe("#Regex", () => { it("should escape", () => { const str = "/abc/$#/de0/12"; expect(escape(str)).toBe("\\/abc\\/\\$#\\/de0\\/12"); }); });
describe("Test Package helper", () => { it("should throw error with no package.json", async () => { try { getPackage("wrongpath"); } catch (err) { expect(err.code).toBe("ENOENT"); } }); it("should get right pkg template", () => { return expect(getPackage(dest)).toHaveProperty("template", "cli"); }); });
test("parse url ok", async () => { const endpoint = "http://api.36node.com?a=b&c=d"; const { url, query } = parseUrl(endpoint); expect(url).toBe("http://api.36node.com"); expect(query).toEqual({ a: "b", c: "d" }); });
test("stringify ok", async () => { const query = { a: "b" }; const search = stringify(query); expect(search).toBe("a=b"); });
test("stringify ok", async () => { const query = { a: "b" }; const search = stringify(query); expect(search).toBe("a=b"); });
test("fetch 500", async () => { expect.assertions(1); try { await fetch("/500"); } catch (err) { expect(err.message).toBe(body500.message); } });
test("fetch 401", async () => { expect.assertions(1); try { await fetch("/401"); } catch (err) { expect(err.message).toBe(body401.message); } });
test("fetch 401", async () => { expect.assertions(1); try { await fetch("/401"); } catch (err) { expect(err.message).toBe(body401.message); } });
test("parse url ok", async () => { const endpoint = "http://api.36node.com?a=b&c=d"; const { url, query } = parseUrl(endpoint); expect(url).toBe("http://api.36node.com"); expect(query).toEqual({ a: "b", c: "d" }); });
test("fetch 500", async () => { expect.assertions(1); try { await fetch("/500"); } catch (err) { expect(err.message).toBe(body500.message); } });