Merge pull request #1088 from hoppscotch/tests
This commit is contained in:
21
babel.config.js
Normal file
21
babel.config.js
Normal file
@@ -0,0 +1,21 @@
|
||||
function isBabelLoader(caller) {
|
||||
return caller && caller.name === "babel-loader"
|
||||
}
|
||||
|
||||
module.exports = function (api) {
|
||||
if (api.env("test") && !api.caller(isBabelLoader)) {
|
||||
return {
|
||||
presets: [
|
||||
[
|
||||
"@babel/preset-env",
|
||||
{
|
||||
targets: {
|
||||
node: "current",
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
}
|
||||
}
|
||||
return {}
|
||||
}
|
||||
144
helpers/utils/__tests__/valid.spec.js
Normal file
144
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)
|
||||
})
|
||||
})
|
||||
3501
package-lock.json
generated
3501
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
37
package.json
37
package.json
@@ -13,7 +13,7 @@
|
||||
"pregenerate": "node build.js",
|
||||
"generate": "nuxt generate",
|
||||
"pretty-quick": "pretty-quick --staged --pattern \"**/*.*(html|js|json|vue)\"",
|
||||
"test": ""
|
||||
"test": "jest"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
@@ -48,16 +48,49 @@
|
||||
"yargs-parser": "^19.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.11.1",
|
||||
"@babel/preset-env": "^7.11.0",
|
||||
"@nuxtjs/dotenv": "^1.4.1",
|
||||
"@nuxtjs/google-analytics": "^2.4.0",
|
||||
"@nuxtjs/pwa": "^3.0.1",
|
||||
"@vue/test-utils": "^1.0.4",
|
||||
"babel-core": "^7.0.0-bridge.0",
|
||||
"babel-jest": "^26.3.0",
|
||||
"@nuxtjs/svg": "^0.1.11",
|
||||
"eslint": "^7.7.0",
|
||||
"eslint-plugin-vue": "^6.2.2",
|
||||
"husky": "^4.2.5",
|
||||
"jest": "^26.4.0",
|
||||
"jest-serializer-vue": "^2.0.2",
|
||||
"node-sass": "^4.14.1",
|
||||
"prettier": "^2.0.5",
|
||||
"pretty-quick": "^2.0.1",
|
||||
"sass-loader": "^9.0.3"
|
||||
"sass-loader": "^9.0.3",
|
||||
"vue-jest": "^3.0.6"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"vue"
|
||||
],
|
||||
"watchman": false,
|
||||
"moduleNameMapper": {
|
||||
"^~/(.*)$": "<rootDir>/$1",
|
||||
"^~~/(.*)$": "<rootDir>/$1"
|
||||
},
|
||||
"transform": {
|
||||
"^.+\\.js$": "babel-jest",
|
||||
".*\\.(vue)$": "vue-jest"
|
||||
},
|
||||
"snapshotSerializers": [
|
||||
"jest-serializer-vue"
|
||||
],
|
||||
"collectCoverage": true,
|
||||
"collectCoverageFrom": [
|
||||
"<rootDir>/components/**/*.vue",
|
||||
"<rootDir>/pages/*.vue"
|
||||
],
|
||||
"testURL": "http://localhost/"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user