diff --git a/.github/workflows/exports.yml b/.github/workflows/exports.yml new file mode 100644 index 0000000..c5b45e6 --- /dev/null +++ b/.github/workflows/exports.yml @@ -0,0 +1,14 @@ +name: exports +on: [push] + +jobs: + format: + runs-on: ubuntu-latest + name: module exports + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: "20" + - name: jest check + run: npm run test diff --git a/.github/workflows/formatting.yml b/.github/workflows/formatting.yml new file mode 100644 index 0000000..4fd1741 --- /dev/null +++ b/.github/workflows/formatting.yml @@ -0,0 +1,14 @@ +name: formatting +on: [push] + +jobs: + format: + runs-on: ubuntu-latest + name: prettier + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: "20" + - name: prettier check + run: npx prettier -c ./src --config ./src/.prettierrc diff --git a/src/checkTypes.ts b/src/checkTypes.ts index 33009fc..520d8b0 100644 --- a/src/checkTypes.ts +++ b/src/checkTypes.ts @@ -5,7 +5,7 @@ function checkKey( item: string, key: string, expectedTypes: string[], - optional: boolean + optional: boolean, ): string | undefined { if (!optional && !obj.hasOwnProperty(key)) { return `${key} key must be present in each ${item} item`; diff --git a/src/constructCurl.ts b/src/constructCurl.ts index cd086f1..594b4a5 100644 --- a/src/constructCurl.ts +++ b/src/constructCurl.ts @@ -32,7 +32,7 @@ export function getCurlRequest(request: RequestSpec): string { curl += ` '${getURL( request.httpRequest.baseUrl, request.httpRequest.url, - getParamsForUrl(request.httpRequest.params, request.options.rawParams) + getParamsForUrl(request.httpRequest.params, request.options.rawParams), )}'`; return curl; diff --git a/src/executeRequest.ts b/src/executeRequest.ts index 78a1863..c8e734d 100644 --- a/src/executeRequest.ts +++ b/src/executeRequest.ts @@ -8,7 +8,7 @@ export function constructGotRequest(allData: RequestSpec): GotRequest { const completeUrl: string = getURL( allData.httpRequest.baseUrl, allData.httpRequest.url, - getParamsForUrl(allData.httpRequest.params, allData.options.rawParams) + getParamsForUrl(allData.httpRequest.params, allData.options.rawParams), ); const options: OptionsOfTextResponseBody = { diff --git a/src/index.ts b/src/index.ts index 890c5c5..1302290 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,10 +1,4 @@ -export { - RequestPosition, - ResponseData, - RequestSpec, - GotRequest, - TestResult -} from "./models"; +export { RequestPosition, ResponseData, RequestSpec, GotRequest, TestResult } from "./models"; export { getRequestPositions, getAllRequestSpecs, getRequestSpec } from "./parseBundle"; diff --git a/src/mergeData.ts b/src/mergeData.ts index 22fa6f0..bdd614c 100644 --- a/src/mergeData.ts +++ b/src/mergeData.ts @@ -51,7 +51,7 @@ function getMergedParams(commonParams: RawParams, requestParams: RawParams): Par function getMergedHeaders( commonHeaders: RawHeaders, - requestHeaders: RawHeaders + requestHeaders: RawHeaders, ): { [name: string]: string } { if (Array.isArray(commonHeaders)) { commonHeaders = getArrayHeadersAsObject(commonHeaders); @@ -79,7 +79,7 @@ function getMergedOptions(cOptions: RawOptions = {}, rOptions: RawOptions = {}): function getMergedSetVars( setvars: RawSetVars = {}, - captures: Captures = {} + captures: Captures = {}, ): { mergedVars: SetVar[]; hasJsonVars: boolean } { const mergedVars: SetVar[] = []; let hasJsonVars = false; @@ -152,7 +152,7 @@ function mergePrefixBasedTests(tests: RawTests) { function getMergedTests( cTests: RawTests = {}, - rTests: RawTests = {} + rTests: RawTests = {}, ): { mergedTests: Tests; hasJsonTests: boolean } { // Convert $. and h. at root level into headers and json keys mergePrefixBasedTests(cTests); @@ -209,11 +209,11 @@ export function getMergedData(commonData: Common, requestData: RawRequest): Requ const { mergedTests: tests, hasJsonTests: hasJsonTests } = getMergedTests( commonData?.tests, - requestData.tests + requestData.tests, ); const { mergedVars: setvars, hasJsonVars: hasJsonVars } = getMergedSetVars( requestData.setvars, - requestData.capture + requestData.capture, ); const mergedData: RequestSpec = { diff --git a/src/parseBundle.ts b/src/parseBundle.ts index 5828cb8..be6b1dc 100644 --- a/src/parseBundle.ts +++ b/src/parseBundle.ts @@ -45,7 +45,7 @@ function getRawRequests(doc: string): { function checkAndMergeRequest( commonData: Common, allRequests: { [name: string]: RawRequest }, - name: string + name: string, ): RequestSpec { let request = allRequests[name]; if (request === undefined) throw new Error(`Request ${name} is not defined in this bundle`); diff --git a/src/replaceVars.ts b/src/replaceVars.ts index 2a830f4..3e78449 100644 --- a/src/replaceVars.ts +++ b/src/replaceVars.ts @@ -5,7 +5,7 @@ import { RequestSpec } from "./models"; function replaceVariablesInArray( data: any[], - variables: Variables + variables: Variables, ): { data: any[]; undefinedVars: string[] } { let newData: any[] = []; let undefs: string[] = []; @@ -22,7 +22,7 @@ function replaceVariablesInArray( function replaceVariablesInDict( obj: { [key: string]: any }, - variables: Variables + variables: Variables, ): { data: { [key: string]: any }; undefinedVars: string[] } { let newData: { [key: string]: any } = {}; let undefs: string[] = []; @@ -39,7 +39,7 @@ function replaceVariablesInDict( function replaceVariablesInObject( data: { [key: string]: any } | any[], - variables: Variables + variables: Variables, ): { data: any; undefinedVars: string[] } { if (Array.isArray(data)) { return replaceVariablesInArray(data, variables); @@ -79,7 +79,7 @@ const VAR_REGEX_WITHOUT_BRACES = /(?, - R = T extends undefined ? undefined : string + R = T extends undefined ? undefined : string, >(value: T): R { if (typeof value === "undefined") return undefined as R; if (typeof value === "object") return JSON.stringify(value) as R; // handles dicts, arrays, null, date (all obj) diff --git a/src/variableParser.ts b/src/variableParser.ts index d5b73a4..69f88f9 100644 --- a/src/variableParser.ts +++ b/src/variableParser.ts @@ -41,7 +41,7 @@ export function getEnvironments(bundleContent: string | undefined, varFileConten export function loadVariables( envName: string | undefined, bundleContent: string | undefined, - varFileContents: string[] + varFileContents: string[], ): Variables { if (!envName) return {}; diff --git a/tests/execute_got_request.test.ts b/tests/execute_got_request.test.ts new file mode 100644 index 0000000..8eb40bb --- /dev/null +++ b/tests/execute_got_request.test.ts @@ -0,0 +1,10 @@ +import got from "got"; + +import { executeGotRequest } from "../src"; + +test("execute simple-get GOT request", async () => { + const response = await executeGotRequest(got("https://postman-echo.com/get", {method: "GET"})); + expect(response.byteLength).toBeGreaterThan(0); + expect(response.executionTime).toBeGreaterThan(0); + expect(response.error.length).toBeLessThan(1); +});