Feature: hopp-cli in TypeScript (#2074)
Co-authored-by: Andrew Bastin <andrewbastin.k@gmail.com> Co-authored-by: liyasthomas <liyascthomas@gmail.com> Co-authored-by: Gita Alekhya Paul <gitaalekhyapaul@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
export default {
|
||||
module.exports = {
|
||||
preset: "ts-jest",
|
||||
testEnvironment: "node",
|
||||
collectCoverage: true,
|
||||
|
||||
@@ -3,19 +3,25 @@
|
||||
"version": "2.0.0",
|
||||
"description": "JavaScript sandboxes for running external scripts used by Hoppscotch clients",
|
||||
"main": "./lib/index.js",
|
||||
"module": "./lib/index.mjs",
|
||||
"type": "commonjs",
|
||||
"exports": {
|
||||
".": {
|
||||
"require": "./lib/index.js",
|
||||
"default": "./lib/index.mjs"
|
||||
}
|
||||
},
|
||||
"types": "./lib/",
|
||||
"type": "module",
|
||||
"engines": {
|
||||
"node": ">=14",
|
||||
"pnpm": ">=3"
|
||||
},
|
||||
"scripts": {
|
||||
"demo": "esrun src/demo.ts",
|
||||
"lint": "eslint --ext .ts,.js --ignore-path .gitignore .",
|
||||
"lintfix": "eslint --fix --ext .ts,.js --ignore-path .gitignore .",
|
||||
"test": "npx jest",
|
||||
"build": "npx tsc",
|
||||
"clean": "npx tsc --build --clean",
|
||||
"test": "pnpx jest",
|
||||
"build": "pnpx tsup",
|
||||
"clean": "pnpx tsc --build --clean",
|
||||
"postinstall": "pnpm run build",
|
||||
"prepublish": "pnpm run build",
|
||||
"do-lint": "pnpm run lint",
|
||||
@@ -37,7 +43,8 @@
|
||||
"@hoppscotch/data": "workspace:^0.4.0",
|
||||
"fp-ts": "^2.11.9",
|
||||
"lodash": "^4.17.21",
|
||||
"quickjs-emscripten": "^0.15.0"
|
||||
"quickjs-emscripten": "^0.15.0",
|
||||
"tsup": "^5.11.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@digitak/esrun": "^3.1.2",
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
import { runTestScript } from "./index"
|
||||
import { TestResponse } from "./test-runner"
|
||||
|
||||
const dummyResponse: TestResponse = {
|
||||
status: 200,
|
||||
body: "hoi",
|
||||
headers: [],
|
||||
}
|
||||
// eslint-disable-next-line prettier/prettier
|
||||
;(async () => {
|
||||
console.dir(
|
||||
await runTestScript(
|
||||
`
|
||||
pw.test("Arithmetic operations and toBe", () => {
|
||||
const size = 500 + 500;
|
||||
pw.expect(size).toBe(1000);
|
||||
pw.expect(size - 500).toBe(500);
|
||||
pw.expect(size * 4).toBe(4000);
|
||||
pw.expect(size / 4).toBe(250);
|
||||
});
|
||||
pw.test("toBeLevelxxx", () => {
|
||||
pw.expect(200).toBeLevel2xx();
|
||||
pw.expect(204).toBeLevel2xx();
|
||||
pw.expect(300).not.toBeLevel2xx();
|
||||
pw.expect(300).toBeLevel3xx();
|
||||
pw.expect(304).toBeLevel3xx();
|
||||
pw.expect(204).not.toBeLevel3xx();
|
||||
pw.expect(401).toBeLevel4xx();
|
||||
pw.expect(404).toBeLevel4xx();
|
||||
pw.expect(204).not.toBeLevel4xx();
|
||||
pw.expect(501).toBeLevel5xx();
|
||||
pw.expect(504).toBeLevel5xx();
|
||||
pw.expect(204).not.toBeLevel5xx();
|
||||
});
|
||||
pw.test("toBeType", () => {
|
||||
pw.expect("hello").toBeType("string");
|
||||
pw.expect(10).toBeType("number");
|
||||
pw.expect(true).toBeType("boolean");
|
||||
pw.expect("deffonotanumber").not.toBeType("number");
|
||||
});
|
||||
pw.test("toHaveLength", () => {
|
||||
const arr = [1, 2, 3];
|
||||
pw.expect(arr).toHaveLength(3);
|
||||
pw.expect(arr).not.toHaveLength(4);
|
||||
});
|
||||
`,
|
||||
dummyResponse
|
||||
),
|
||||
{
|
||||
depth: 100,
|
||||
}
|
||||
)
|
||||
})()
|
||||
@@ -3,11 +3,14 @@ import * as TE from "fp-ts/TaskEither"
|
||||
import { execPreRequestScript } from "./preRequest"
|
||||
import {
|
||||
execTestScript,
|
||||
TestResponse,
|
||||
TestResponse as _TestResponse,
|
||||
TestDescriptor as _TestDescriptor,
|
||||
TestResult,
|
||||
} from "./test-runner"
|
||||
|
||||
export * from "./test-runner"
|
||||
|
||||
export type TestResponse = _TestResponse
|
||||
export type TestDescriptor = _TestDescriptor
|
||||
export type SandboxTestResult = TestResult & { tests: TestDescriptor }
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES6",
|
||||
"module": "ESNext",
|
||||
"module": "CommonJS",
|
||||
"moduleResolution": "Node",
|
||||
"skipLibCheck": true,
|
||||
"lib": ["ESNext", "ESNext.AsyncIterable", "DOM"],
|
||||
@@ -19,5 +19,5 @@
|
||||
"sourceMap": true
|
||||
},
|
||||
"include": ["./src", "./src/global.d.ts"],
|
||||
"exclude": ["node_modules", "./src/__tests__", "./src/demo.ts"]
|
||||
"exclude": ["node_modules", "./src/__tests__"]
|
||||
}
|
||||
|
||||
11
packages/hoppscotch-js-sandbox/tsup.config.ts
Normal file
11
packages/hoppscotch-js-sandbox/tsup.config.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { defineConfig } from "tsup"
|
||||
|
||||
export default defineConfig({
|
||||
entry: ["src/index.ts"],
|
||||
outDir: "./lib/",
|
||||
format: ["esm", "cjs"],
|
||||
dts: true,
|
||||
splitting: true,
|
||||
sourcemap: true,
|
||||
clean: true,
|
||||
})
|
||||
Reference in New Issue
Block a user