Browse Source

feat: fix up jest tests

Andrew Bastin 3 years ago
parent
commit
36246da9e1

+ 26 - 0
packages/hoppscotch-app/babel.config.js

@@ -0,0 +1,26 @@
+function isBabelLoader(caller) {
+  return caller && caller.name === "babel-loader"
+}
+
+module.exports = function (api) {
+  if (api.env("test") && !api.caller(isBabelLoader)) {
+    return {
+      plugins: [
+        "@babel/plugin-proposal-class-properties",
+        "@babel/plugin-proposal-nullish-coalescing-operator",
+        "@babel/plugin-proposal-optional-chaining",
+      ],
+      presets: [
+        [
+          "@babel/preset-env",
+          {
+            targets: {
+              node: "current",
+            },
+          },
+        ],
+      ],
+    }
+  }
+  return {}
+}

+ 2 - 2
packages/hoppscotch-app/helpers/postwomanTesting.ts

@@ -47,7 +47,7 @@ export default function runTestScriptWithVariables(
     expect(value: any) {
       try {
         return expect(value, this._testReports)
-      } catch (e) {
+      } catch (e: any) {
         pw._testReports.push({
           result: "ERROR",
           message: e.toString(),
@@ -80,7 +80,7 @@ function test(
   _testReports.push({ startBlock: descriptor })
   try {
     func()
-  } catch (e) {
+  } catch (e: any) {
     _testReports.push({ result: "ERROR", message: e, styles: styles.ERROR })
   }
   _testReports.push({ endBlock: true })

+ 0 - 4
packages/hoppscotch-app/jest.config.js

@@ -14,10 +14,6 @@ module.exports = {
   setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
   snapshotSerializers: ["jest-serializer-vue"],
   collectCoverage: true,
-  collectCoverageFrom: [
-    "<rootDir>/components/**/*.vue",
-    "<rootDir>/pages/*.vue",
-  ],
   testURL: "http://localhost/",
   preset: "ts-jest/presets/js-with-babel",
   testEnvironment: "jsdom",

+ 5 - 4
packages/hoppscotch-app/package.json

@@ -5,8 +5,8 @@
   "author": "Hoppscotch (support@hoppscotch.io)",
   "private": true,
   "engines": {
-      "node": ">=14",
-      "pnpm": ">=3"
+    "node": ">=14",
+    "pnpm": ">=3"
   },
   "scripts": {
     "dev": "nuxt",
@@ -36,6 +36,7 @@
     "ace-builds": "^1.4.12",
     "acorn": "^8.5.0",
     "acorn-walk": "^8.2.0",
+    "axios": "^0.21.4",
     "core-js": "^3.17.2",
     "esprima": "^4.0.1",
     "firebase": "^9.0.1",
@@ -65,10 +66,9 @@
   "devDependencies": {
     "@babel/core": "^7.15.5",
     "@babel/preset-env": "^7.15.4",
-    "@nuxt/types": "^2.15.8",
     "@commitlint/cli": "^13.1.0",
     "@commitlint/config-conventional": "^13.1.0",
-    "lint-staged": "^11.1.2",
+    "@nuxt/types": "^2.15.8",
     "@nuxt/typescript-build": "^2.1.0",
     "@nuxtjs/color-mode": "^2.1.1",
     "@nuxtjs/dotenv": "^1.4.1",
@@ -93,6 +93,7 @@
     "eslint-plugin-vue": "^7.17.0",
     "jest": "^27.1.0",
     "jest-serializer-vue": "^2.0.2",
+    "lint-staged": "^11.1.2",
     "nuxt-windicss": "^1.2.3",
     "prettier": "^2.3.2",
     "pretty-quick": "^3.1.1",

+ 0 - 0
tsconfig.json → packages/hoppscotch-app/tsconfig.json


+ 2 - 0
pnpm-lock.yaml

@@ -43,6 +43,7 @@ importers:
       ace-builds: ^1.4.12
       acorn: ^8.5.0
       acorn-walk: ^8.2.0
+      axios: ^0.21.4
       babel-core: ^7.0.0-bridge.0
       babel-jest: ^27.1.0
       core-js: ^3.17.2
@@ -104,6 +105,7 @@ importers:
       ace-builds: 1.4.12
       acorn: 8.5.0
       acorn-walk: 8.2.0
+      axios: 0.21.4
       core-js: 3.17.3
       esprima: 4.0.1
       firebase: 9.0.1