refactor: monorepo+pnpm (removed husky)
This commit is contained in:
15
packages/hoppscotch-app/helpers/utils/__tests__/b64.spec.js
Normal file
15
packages/hoppscotch-app/helpers/utils/__tests__/b64.spec.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { TextDecoder } from "util"
|
||||
import { decodeB64StringToArrayBuffer } from "../b64"
|
||||
|
||||
describe("decodeB64StringToArrayBuffer", () => {
|
||||
test("decodes content correctly", () => {
|
||||
const decoder = new TextDecoder("utf-8")
|
||||
expect(
|
||||
decoder.decode(
|
||||
decodeB64StringToArrayBuffer("aG9wcHNjb3RjaCBpcyBhd2Vzb21lIQ==")
|
||||
)
|
||||
).toMatch("hoppscotch is awesome!")
|
||||
})
|
||||
|
||||
// TODO : More tests for binary data ?
|
||||
})
|
||||
@@ -0,0 +1,40 @@
|
||||
import { isJSONContentType } from "../contenttypes"
|
||||
|
||||
describe("isJSONContentType", () => {
|
||||
test("returns true for JSON content types", () => {
|
||||
expect(isJSONContentType("application/json")).toBe(true)
|
||||
expect(isJSONContentType("application/vnd.api+json")).toBe(true)
|
||||
expect(isJSONContentType("application/hal+json")).toBe(true)
|
||||
expect(isJSONContentType("application/ld+json")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for JSON types with charset specified", () => {
|
||||
expect(isJSONContentType("application/json; charset=utf-8")).toBe(true)
|
||||
expect(isJSONContentType("application/vnd.api+json; charset=utf-8")).toBe(
|
||||
true
|
||||
)
|
||||
expect(isJSONContentType("application/hal+json; charset=utf-8")).toBe(true)
|
||||
expect(isJSONContentType("application/ld+json; charset=utf-8")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns false for non-JSON content types", () => {
|
||||
expect(isJSONContentType("application/xml")).toBe(false)
|
||||
expect(isJSONContentType("text/html")).toBe(false)
|
||||
expect(isJSONContentType("application/x-www-form-urlencoded")).toBe(false)
|
||||
expect(isJSONContentType("foo/jsoninword")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for non-JSON content types with charset", () => {
|
||||
expect(isJSONContentType("application/xml; charset=utf-8")).toBe(false)
|
||||
expect(isJSONContentType("text/html; charset=utf-8")).toBe(false)
|
||||
expect(
|
||||
isJSONContentType("application/x-www-form-urlencoded; charset=utf-8")
|
||||
).toBe(false)
|
||||
expect(isJSONContentType("foo/jsoninword; charset=utf-8")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for null/undefined", () => {
|
||||
expect(isJSONContentType(null)).toBe(false)
|
||||
expect(isJSONContentType(undefined)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import debounce from "../debounce"
|
||||
|
||||
describe("debounce", () => {
|
||||
test("doesn't call function right after calling", () => {
|
||||
const fn = jest.fn()
|
||||
|
||||
const debFunc = debounce(fn, 100)
|
||||
debFunc()
|
||||
|
||||
expect(fn).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test("calls the function after the given timeout", () => {
|
||||
const fn = jest.fn()
|
||||
|
||||
jest.useFakeTimers()
|
||||
|
||||
const debFunc = debounce(fn, 100)
|
||||
debFunc()
|
||||
|
||||
jest.runAllTimers()
|
||||
|
||||
expect(fn).toHaveBeenCalled()
|
||||
// expect(setTimeout).toHaveBeenCalledWith(expect.any(Function), 100)
|
||||
})
|
||||
|
||||
test("calls the function only one time within the timeframe", () => {
|
||||
const fn = jest.fn()
|
||||
|
||||
const debFunc = debounce(fn, 1000)
|
||||
|
||||
for (let i = 0; i < 100; i++) debFunc()
|
||||
|
||||
jest.runAllTimers()
|
||||
|
||||
expect(fn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
21
packages/hoppscotch-app/helpers/utils/__tests__/uri.spec.js
Normal file
21
packages/hoppscotch-app/helpers/utils/__tests__/uri.spec.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { parseUrlAndPath } from "../uri"
|
||||
|
||||
describe("parseUrlAndPath", () => {
|
||||
test("has url and path fields", () => {
|
||||
const result = parseUrlAndPath("https://hoppscotch.io/")
|
||||
|
||||
expect(result).toHaveProperty("url")
|
||||
expect(result).toHaveProperty("path")
|
||||
})
|
||||
|
||||
test("parses out URL correctly", () => {
|
||||
const result = parseUrlAndPath("https://hoppscotch.io/test/page")
|
||||
|
||||
expect(result.url).toBe("https://hoppscotch.io")
|
||||
})
|
||||
test("parses out Path correctly", () => {
|
||||
const result = parseUrlAndPath("https://hoppscotch.io/test/page")
|
||||
|
||||
expect(result.path).toBe("/test/page")
|
||||
})
|
||||
})
|
||||
144
packages/hoppscotch-app/helpers/utils/__tests__/valid.spec.js
Normal file
144
packages/hoppscotch-app/helpers/utils/__tests__/valid.spec.js
Normal file
@@ -0,0 +1,144 @@
|
||||
import { wsValid, httpValid, socketioValid } from "../valid"
|
||||
|
||||
describe("wsValid", () => {
|
||||
test("returns true for valid URL with IP address", () => {
|
||||
expect(wsValid("wss://174.129.224.73/")).toBe(true)
|
||||
expect(wsValid("wss://174.129.224.73")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for valid URL with Hostname", () => {
|
||||
expect(wsValid("wss://echo.websocket.org/")).toBe(true)
|
||||
expect(wsValid("wss://echo.websocket.org")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns false for invalid URL with IP address", () => {
|
||||
expect(wsValid("wss://174.129.")).toBe(false)
|
||||
expect(wsValid("wss://174.129./")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for invalid URL with hostname", () => {
|
||||
expect(wsValid("wss://echo.websocket./")).toBe(false)
|
||||
expect(wsValid("wss://echo.websocket.")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for non-wss protocol URLs", () => {
|
||||
expect(wsValid("http://echo.websocket.org/")).toBe(false)
|
||||
expect(wsValid("http://echo.websocket.org")).toBe(false)
|
||||
expect(wsValid("http://174.129.224.73/")).toBe(false)
|
||||
expect(wsValid("http://174.129.224.73")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns true for wss protocol URLs", () => {
|
||||
expect(wsValid("wss://echo.websocket.org/")).toBe(true)
|
||||
expect(wsValid("wss://echo.websocket.org")).toBe(true)
|
||||
expect(wsValid("wss://174.129.224.73/")).toBe(true)
|
||||
expect(wsValid("wss://174.129.224.73")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for ws protocol URLs", () => {
|
||||
expect(wsValid("ws://echo.websocket.org/")).toBe(true)
|
||||
expect(wsValid("ws://echo.websocket.org")).toBe(true)
|
||||
expect(wsValid("ws://174.129.224.73/")).toBe(true)
|
||||
expect(wsValid("ws://174.129.224.73")).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("httpValid", () => {
|
||||
test("returns true for valid URL with IP address", () => {
|
||||
expect(httpValid("http://174.129.224.73/")).toBe(true)
|
||||
expect(httpValid("http://174.129.224.73")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for valid URL with Hostname", () => {
|
||||
expect(httpValid("http://echo.websocket.org/")).toBe(true)
|
||||
expect(httpValid("http://echo.websocket.org")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns false for invalid URL with IP address", () => {
|
||||
expect(httpValid("http://174.129./")).toBe(false)
|
||||
expect(httpValid("http://174.129.")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for invalid URL with hostname", () => {
|
||||
expect(httpValid("http://echo.websocket./")).toBe(false)
|
||||
expect(httpValid("http://echo.websocket.")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for non-http(s) protocol URLs", () => {
|
||||
expect(httpValid("wss://echo.websocket.org/")).toBe(false)
|
||||
expect(httpValid("wss://echo.websocket.org")).toBe(false)
|
||||
expect(httpValid("wss://174.129.224.73/")).toBe(false)
|
||||
expect(httpValid("wss://174.129.224.73")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns true for HTTP protocol URLs", () => {
|
||||
expect(httpValid("http://echo.websocket.org/")).toBe(true)
|
||||
expect(httpValid("http://echo.websocket.org")).toBe(true)
|
||||
expect(httpValid("http://174.129.224.73/")).toBe(true)
|
||||
expect(httpValid("http://174.129.224.73")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for HTTPS protocol URLs", () => {
|
||||
expect(httpValid("https://echo.websocket.org/")).toBe(true)
|
||||
expect(httpValid("https://echo.websocket.org")).toBe(true)
|
||||
expect(httpValid("https://174.129.224.73/")).toBe(true)
|
||||
expect(httpValid("https://174.129.224.73")).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
describe("socketioValid", () => {
|
||||
test("returns true for valid URL with IP address", () => {
|
||||
expect(socketioValid("http://174.129.224.73/")).toBe(true)
|
||||
expect(socketioValid("http://174.129.224.73")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for valid URL with Hostname", () => {
|
||||
expect(socketioValid("http://echo.websocket.org/")).toBe(true)
|
||||
expect(socketioValid("http://echo.websocket.org")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns false for invalid URL with IP address", () => {
|
||||
expect(socketioValid("http://174.129./")).toBe(false)
|
||||
expect(socketioValid("http://174.129.")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for invalid URL with hostname", () => {
|
||||
expect(socketioValid("http://echo.websocket./")).toBe(false)
|
||||
expect(socketioValid("http://echo.websocket.")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns false for non-http(s) and non-wss protocol URLs", () => {
|
||||
expect(socketioValid("ftp://echo.websocket.org/")).toBe(false)
|
||||
expect(socketioValid("ftp://echo.websocket.org")).toBe(false)
|
||||
expect(socketioValid("ftp://174.129.224.73/")).toBe(false)
|
||||
expect(socketioValid("ftp://174.129.224.73")).toBe(false)
|
||||
})
|
||||
|
||||
test("returns true for HTTP protocol URLs", () => {
|
||||
expect(socketioValid("http://echo.websocket.org/")).toBe(true)
|
||||
expect(socketioValid("http://echo.websocket.org")).toBe(true)
|
||||
expect(socketioValid("http://174.129.224.73/")).toBe(true)
|
||||
expect(socketioValid("http://174.129.224.73")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for HTTPS protocol URLs", () => {
|
||||
expect(socketioValid("https://echo.websocket.org/")).toBe(true)
|
||||
expect(socketioValid("https://echo.websocket.org")).toBe(true)
|
||||
expect(socketioValid("https://174.129.224.73/")).toBe(true)
|
||||
expect(socketioValid("https://174.129.224.73")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for wss protocol URLs", () => {
|
||||
expect(socketioValid("wss://echo.websocket.org/")).toBe(true)
|
||||
expect(socketioValid("wss://echo.websocket.org")).toBe(true)
|
||||
expect(socketioValid("wss://174.129.224.73/")).toBe(true)
|
||||
expect(socketioValid("wss://174.129.224.73")).toBe(true)
|
||||
})
|
||||
|
||||
test("returns true for ws protocol URLs", () => {
|
||||
expect(socketioValid("ws://echo.websocket.org/")).toBe(true)
|
||||
expect(socketioValid("ws://echo.websocket.org")).toBe(true)
|
||||
expect(socketioValid("ws://174.129.224.73/")).toBe(true)
|
||||
expect(socketioValid("ws://174.129.224.73")).toBe(true)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user