Socket
Socket
Sign inDemoInstall

@kie/mock-github

Package Overview
Dependencies
99
Maintainers
4
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

4

build/src/endpoint-mocker/request/abstract-request-mocker.d.ts

@@ -6,5 +6,7 @@ import { DataMatcherMap } from "nock/types";

private _baseUrl;
constructor(baseUrl: string, endpointDetails: EndpointDetails);
private _allowUnmocked;
constructor(baseUrl: string, endpointDetails: EndpointDetails, allowUnmocked?: boolean);
get baseUrl(): string;
get endpointDetails(): EndpointDetails;
get allowUnmocked(): boolean;
protected parseParams(params?: Params): {

@@ -11,0 +13,0 @@ path: string | RegExp;

@@ -5,5 +5,6 @@ "use strict";

class RequestMocker {
constructor(baseUrl, endpointDetails) {
constructor(baseUrl, endpointDetails, allowUnmocked = false) {
this._endpointDetails = endpointDetails;
this._baseUrl = baseUrl;
this._allowUnmocked = allowUnmocked;
}

@@ -16,2 +17,5 @@ get baseUrl() {

}
get allowUnmocked() {
return this._allowUnmocked;
}
parseParams(params) {

@@ -22,3 +26,3 @@ const { pathParams, query, requestBody } = this.extractParams(params);

// replace any path variables with either values or regex expression
for (const match of this.endpointDetails.path.match(/\{[^\{\}]+\}/g) ??
for (const match of this.endpointDetails.path.match(/{[^{}]+}/g) ??
[]) {

@@ -44,3 +48,3 @@ let replacementParam;

extractParams(params) {
let pathParams = {};
const pathParams = {};
let query = undefined;

@@ -47,0 +51,0 @@ let requestBody = undefined;

@@ -11,3 +11,3 @@ import { DataMatcherMap } from "nock";

private method;
constructor(baseUrl: string, path: string | RegExp, method: string, query?: DataMatcherMap, requestBody?: DataMatcherMap);
constructor(baseUrl: string, path: string | RegExp, method: string, query?: DataMatcherMap, requestBody?: DataMatcherMap, allowUnmocked?: boolean);
setResponse(responses: Response<T, S> | Response<T, S>[]): this;

@@ -14,0 +14,0 @@ reply(response?: Response<T, S>): this;

@@ -9,4 +9,4 @@ "use strict";

class ResponseMocker {
constructor(baseUrl, path, method, query, requestBody) {
this.scope = (0, nock_1.default)(baseUrl);
constructor(baseUrl, path, method, query, requestBody, allowUnmocked = false) {
this.scope = (0, nock_1.default)(baseUrl, { allowUnmocked });
this.responses = [];

@@ -36,3 +36,3 @@ this.path = path;

else {
this.responses.forEach((res) => {
this.responses.forEach(res => {
this.scope = this.interceptor

@@ -39,0 +39,0 @@ .times(res.repeat ?? 1)

@@ -89,3 +89,3 @@ "use strict";

});
app.on("error", (err) => {
app.on("error", err => {
reject(err);

@@ -98,3 +98,3 @@ });

if (this.app) {
this.app.close((err) => {
this.app.close(err => {
if (err) {

@@ -101,0 +101,0 @@ reject(err);

@@ -31,5 +31,6 @@ "use strict";

async setup() {
if (!this.inputFromConfig)
if (!this.inputFromConfig) {
return;
Object.keys(this.inputFromConfig).forEach((key) => {
}
Object.keys(this.inputFromConfig).forEach(key => {
this.update(key, this.inputFromConfig[key]);

@@ -39,3 +40,3 @@ });

async teardown() {
Object.keys(this.currentInput).forEach((key) => {
Object.keys(this.currentInput).forEach(key => {
this.delete(key);

@@ -42,0 +43,0 @@ });

@@ -34,3 +34,3 @@ "use strict";

this.currentEnv = this.envFromConfig;
Object.keys(this.currentEnv).forEach((key) => {
Object.keys(this.currentEnv).forEach(key => {
this.update(key, this.currentEnv[key]);

@@ -44,3 +44,3 @@ });

const env = this.envFromConfig;
Object.keys(env).forEach((key) => {
Object.keys(env).forEach(key => {
this.delete(key);

@@ -47,0 +47,0 @@ });

@@ -41,4 +41,5 @@ "use strict";

// rm the setup dir only if we had created it
if (this.setupDirCreated)
if (this.setupDirCreated) {
(0, fs_extra_1.rmSync)(this.setupPath, { recursive: true });
}
this.hasCalledSetup = false;

@@ -45,0 +46,0 @@ }

@@ -34,3 +34,3 @@ "use strict";

? [(0, fs_extra_1.rm)(this.setupPath, { recursive: true, force: true })]
: Object.keys(this.repositories).map((repoName) => (0, fs_extra_1.rm)(this._repositoryState.getPath(repoName), {
: Object.keys(this.repositories).map(repoName => (0, fs_extra_1.rm)(this._repositoryState.getPath(repoName), {
recursive: true,

@@ -37,0 +37,0 @@ force: true,

@@ -96,3 +96,3 @@ "use strict";

}
(await Promise.all(promises)).forEach((res) => result.push(...res));
(await Promise.all(promises)).forEach(res => result.push(...res));
return result;

@@ -99,0 +99,0 @@ }

@@ -9,4 +9,4 @@ "use strict";

class Moctokit {
constructor(baseUrl) {
this._rest = (0, endpoint_request_1.default)(baseUrl ?? "https://api.github.com");
constructor(baseUrl, allowUnmocked = false) {
this._rest = (0, endpoint_request_1.default)(baseUrl ?? "https://api.github.com", allowUnmocked);
}

@@ -13,0 +13,0 @@ get rest() {

@@ -7,4 +7,4 @@ import { MockRequestParameters } from "../../moctokit/request/request-mocker.types";

export declare class MoctokitRequestMocker<Path extends keyof paths, Method extends keyof paths[Path]> extends RequestMocker {
constructor(baseUrl: string, endpointDetails: EndpointDetails);
constructor(baseUrl: string, endpointDetails: EndpointDetails, allowUnmocked?: boolean);
request(params?: MockRequestParameters<paths[Path][Method]>): MoctokitResponseMocker<Path, Method>;
}

@@ -7,4 +7,4 @@ "use strict";

class MoctokitRequestMocker extends abstract_request_mocker_1.RequestMocker {
constructor(baseUrl, endpointDetails) {
super(baseUrl, endpointDetails);
constructor(baseUrl, endpointDetails, allowUnmocked = false) {
super(baseUrl, endpointDetails, allowUnmocked);
// need to bind the instance context to the function. otherwise it is lost during endpointToMethod generation

@@ -15,5 +15,5 @@ this.request = this.request.bind(this);

const { path, query, requestBody } = this.parseParams(params);
return new response_mocker_1.MoctokitResponseMocker(this.baseUrl, path, this.endpointDetails.method, query, requestBody);
return new response_mocker_1.MoctokitResponseMocker(this.baseUrl, path, this.endpointDetails.method, query, requestBody, this.allowUnmocked);
}
}
exports.MoctokitRequestMocker = MoctokitRequestMocker;
/** Adapted from: https://github.com/octokit/types.ts/blob/bd5f9f7bce9fa448c87fcfadb7bd547de66ad115/src/generated/Endpoints.ts */
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type UnionToIntersection<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type UnionWithRegex<R> = {

@@ -8,3 +8,3 @@ [K in keyof R]: R[K] | RegExp;

[K in keyof T["parameters"]]: T["parameters"][K];
}[keyof T["parameters"]]> : {};
}[keyof T["parameters"]]> : Record<never, never>;
type RequestBody<T> = "requestBody" extends keyof T ? "content" extends keyof T["requestBody"] ? "application/json" extends keyof T["requestBody"]["content"] ? T["requestBody"]["content"]["application/json"] : {

@@ -18,4 +18,4 @@ data: {

}[keyof T["requestBody"]];
} : {};
} : Record<never, never>;
export type MockRequestParameters<T> = UnionWithRegex<Partial<Parameters<T> & RequestBody<T>>>;
export {};

@@ -7,3 +7,3 @@ import { Response } from "../../endpoint-mocker/response/abstract-response-mocker.types";

} : T;
type MockResponse<T, S extends number> = T extends Array<any> ? Response<Subset<T[number]>[], S> : Response<Subset<T>, S>;
type MockResponse<T, S extends number> = T extends Array<unknown> ? Response<Subset<T[number]>[], S> : Response<Subset<T>, S>;
type DataType<T> = {

@@ -10,0 +10,0 @@ [K in KnownJsonResponseTypes & keyof T]: T[K];

{
"name": "@kie/mock-github",
"version": "1.0.0",
"version": "1.0.1",
"description": "A bunch of tools to configure and create a local github environment to test your github actions in without having to clutter your github with test repositories, actions or hitting github api rate limits.",

@@ -32,2 +32,4 @@ "main": "build/src/index.js",

"update-all": "npm-run-all update:*",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"file": "ts-node"

@@ -44,7 +46,7 @@ },

"@types/node": "^18.0.0",
"@typescript-eslint/eslint-plugin": "^5.29.0",
"@typescript-eslint/parser": "^5.29.0",
"@typescript-eslint/eslint-plugin": "^5.48.2",
"@typescript-eslint/parser": "^5.48.2",
"@vercel/ncc": "^0.34.0",
"axios": "^0.27.2",
"eslint": "^8.18.0",
"eslint": "^8.32.0",
"github-openapi-graphql-query": "^2.1.2",

@@ -51,0 +53,0 @@ "jest": "^28.1.1",

@@ -10,3 +10,3 @@ # Mock Github

- [Moctokit](#moctokit)
- [Specifying which base url to use](#specifying-which-base-url-to-use)
- [Initialization options](#initialization-options)
- [Mock an api](#mock-an-api)

@@ -33,5 +33,4 @@ - [Mock the entire endpoint](#mock-the-entire-endpoint)

## Moctokit
Allows you to mock [octokit](https://octokit.github.io/rest.js/v19) using an octokit like interface.
Provides a simple interface to mock any github api endpoints. This interface is just like the one from [@octokit/rest](https://octokit.github.io/rest.js/v19).
Example

@@ -49,3 +48,3 @@

### Specifying which base url to use
### Initialization options

@@ -64,2 +63,8 @@ By default a moctokit instance uses `https://api.github.com` as the base url

You can enable other APIs to pass through if there is no exact match
```typescript
const moctokit = new Moctokit(undefined, true); // mocks github apis for https://api.github.com and lets unmatched apis to pass through
```
### Mock an api

@@ -66,0 +71,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc