Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
- Organize imports.
- Update CI config.
  - Bump dependent actions.
  - Fix a typo while referring to the Node.js version and run tests on LTS.
  - Move `Setup node` step above `Setup pnpm`.
- Bump CLI version.
  • Loading branch information
jamesgeorge007 committed Apr 16, 2024
1 parent 4589d63 commit e1cfdbd
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 36 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup environment
run: mv .env.example .env

- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Setup pnpm
uses: pnpm/action-setup@v2.2.4
uses: pnpm/action-setup@v3
with:
version: 8
run_install: true

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: pnpm

- name: Run tests
run: pnpm test
2 changes: 1 addition & 1 deletion packages/hoppscotch-cli/bin/hopp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import { cli } from "../dist/index.js";

import { cloneDeep } from "lodash-es";
import { spawnSync } from "child_process";
import { cloneDeep } from "lodash-es";

const nodeVersion = parseInt(process.versions.node.split(".")[0]);

Expand Down
2 changes: 1 addition & 1 deletion packages/hoppscotch-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hoppscotch/cli",
"version": "0.7.0",
"version": "0.7.1",
"description": "A CLI to run Hoppscotch test scripts in CI environments.",
"homepage": "https://hoppscotch.io",
"type": "module",
Expand Down
1 change: 1 addition & 0 deletions packages/hoppscotch-cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import chalk from "chalk";
import { Command } from "commander";
import * as E from "fp-ts/Either";

import { version } from "../package.json";
import { test } from "./commands/test";
import { handleError } from "./handlers/error";
Expand Down
3 changes: 3 additions & 0 deletions packages/hoppscotch-js-sandbox/setupFiles.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Vitest doesn't work without globals
// Ref: https://github.com/relmify/jest-fp-ts/issues/11

import decodeMatchers from "@relmify/jest-fp-ts/dist/decodeMatchers"
import eitherMatchers from "@relmify/jest-fp-ts/dist/eitherMatchers"
import optionMatchers from "@relmify/jest-fp-ts/dist/optionMatchers"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type from "@relmify/jest-fp-ts"
import * as TE from "fp-ts/TaskEither"
import { pipe } from "fp-ts/function"

Expand Down
18 changes: 9 additions & 9 deletions packages/hoppscotch-js-sandbox/src/node/pre-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ export const runPreRequestScript = (
// Methods in the isolate context can't be invoked straightaway
const finalScript = `
const pw = new Proxy(serializedAPIMethods, {
get: (target, prop) => {
if (prop in target && typeof target[prop] === "object") {
return new Proxy(target[prop], {
get: (pwObjTarget, pwObjProp) => {
const topLevelEntry = pwObjTarget[pwObjProp]
// "pw.env" set of API methods
if (topLevelEntry && typeof topLevelEntry === "object") {
return new Proxy(topLevelEntry, {
get: (subTarget, subProp) => {
if (subProp in subTarget && subTarget[subProp].typeof === "function") {
return (...args) => subTarget[subProp].applySync(null, args)
const subLevelProperty = subTarget[subProp]
if (subLevelProperty && subLevelProperty.typeof === "function") {
return (...args) => subLevelProperty.applySync(null, args)
}
return
},
})
}
return
}
})
Expand Down
31 changes: 16 additions & 15 deletions packages/hoppscotch-js-sandbox/src/node/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,22 @@ const executeScriptInContext = (
// Methods in the isolate context can't be invoked straightaway
const finalScript = `
const pw = new Proxy(serializedAPIMethods, {
get: (pwObj, pwKey) => {
get: (pwObj, pwObjProp) => {
// pw.expect(), pw.env, etc.
const topLevelProperty = pwObj[pwKey]
const topLevelEntry = pwObj[pwObjProp]
// If the property exists and is a function
// If the entry exists and is a function
// pw.expect(), pw.test(), etc.
if (topLevelProperty && topLevelProperty.typeof === "function") {
if (topLevelEntry && topLevelEntry.typeof === "function") {
// pw.test() just involves invoking the function via "applySync()"
if (pwKey === "test") {
return (...args) => topLevelProperty.applySync(null, args)
if (pwObjProp === "test") {
return (...args) => topLevelEntry.applySync(null, args)
}
// pw.expect() returns an object with matcher methods
return (...args) => {
// Invoke "pw.expect()" and get access to the object with matcher methods
const expectFnResult = topLevelProperty.applySync(
const expectFnResult = topLevelEntry.applySync(
null,
args.map((expectVal) => {
if (typeof expectVal === "object") {
Expand Down Expand Up @@ -157,9 +157,9 @@ const executeScriptInContext = (
if (matcherMethodProp === "not") {
return new Proxy(matcherMethodEntry, {
get: (negatedTarget, prop) => {
get: (negatedObjTarget, negatedObjprop) => {
// Return the negated matcher method defn that is invoked from the test script
const negatedMatcherMethodDefn = negatedTarget.getSync(prop)
const negatedMatcherMethodDefn = negatedObjTarget.getSync(negatedObjprop)
return negatedMatcherMethodDefn
},
})
Expand All @@ -174,20 +174,21 @@ const executeScriptInContext = (
}
// "pw.env" set of API methods
if (typeof topLevelProperty === "object" && pwKey !== "response") {
return new Proxy(topLevelProperty, {
if (typeof topLevelEntry === "object" && pwObjProp !== "response") {
return new Proxy(topLevelEntry, {
get: (subTarget, subProp) => {
const subLevelProperty = subTarget[subProp]
if (
subProp in subTarget &&
subTarget[subProp].typeof === "function"
subLevelProperty &&
subLevelProperty.typeof === "function"
) {
return (...args) => subTarget[subProp].applySync(null, args)
return (...args) => subLevelProperty.applySync(null, args)
}
},
})
}
return topLevelProperty
return topLevelEntry
},
})
Expand Down
2 changes: 1 addition & 1 deletion packages/hoppscotch-js-sandbox/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export function preventCyclicObjects(

/**
* Creates an Expectation object for use inside the sandbox
* @param resolvedExpectVal The expecting value of the expectation
* @param expectVal The expecting value of the expectation
* @param negated Whether the expectation is negated (negative)
* @param currTestStack The current state of the test execution stack
* @returns Object with the expectation methods
Expand Down

0 comments on commit e1cfdbd

Please sign in to comment.