open-index/open-npm huggingface dataset:
npm package: @golevelup/ts-sinon
Description: Utilities for making testing [NestJS](https://docs.nestjs.com) applications easier.
Author: Omer Morad
Latest version: 2.0.0

# Sinon Mocking (ts-sinon)

Utilities for making testing [NestJS](https://docs.nestjs.com) applications easier.

<div style="display: flex; gap: 10px;">
<a href="https://www.npmjs.com/package/@golevelup/ts-sinon"><img src="https://img.shields.io/npm/v/@golevelup/ts-sinon.svg?style=flat" alt="version" /></a>
<a href="https://www.npmjs.com/package/@golevelup/ts-sinon"><img alt="downloads" src="https://img.shields.io/npm/dt/@golevelup/ts-sinon.svg?style=flat"></a>
<img alt="license" src="https://img.shields.io/npm/l/@golevelup/ts-sinon.svg">
</div>

## Getting Started

::: code-group

```bash [npm]
npm install @golevelup/ts-sinon -D
```

```bash [yarn]
yarn add @golevelup/ts-sinon -D
```

```bash [pnpm]
pnpm add @golevelup/ts-sinon -D
```

:::

### Creating Mocks

1. Import the `createMock` function into your test class.
2. Create a variable and set it equal to the `createMock` function with its generic type input.
3. Use the mock, Luke.

Here's an example with NestJS' `ExecutionContext`:

```ts
import { createMock } from '@golevelup/ts-sinon';
import { ExecutionContext } from '@nestjs/common';

describe('Mocked Execution Context', () => {
  it('should have a fully mocked Execution Context', () => {
    const mockExecutionContext = createMock<ExecutionContext>();
    expect(mockExecutionContext.switchToHttp()).toBeDefined();
  });
});
```

`createMock` generates all sub-properties as `sinon.stub()`, so you can chain method calls:

```ts
it('should correctly resolve mocked providers', async () => {
  const request = {
    key: 'val',
  };

  mockExecutionContext.switchToHttp.returns(
    createMock<HttpArgumentsHost>({
      getRequest: () => request,
    }),
  );

  const mockResult = mockExecutionContext.switchToHttp().getRequest();
  expect(mockResult).toBe(request);
});
```

You can also easily provide your own mocks:

```ts
const mockExecutionContext = createMock<ExecutionContext>({
  switchToHttp: () => ({
    getRequest: () => ({
      headers: {
        authorization: 'auth',
      },
    }),
    getResponse: sinon.stub().returns({ data: 'res return data' }),
  }),
});
```

::: warning Note
When providing your own mocks, the number of times a parent mock function was called includes the times needed to set your mocks.
:::
npm package: @golfy/loggify
Description: A standardized error logger
Author: Golfy
Latest version: 1.0.0

# loggify 📦

> A simple and standardized error logging library for Node.js (written in TypeScript)

## Installation

```bash
npm install loggify chalk
```

## Usage

```ts
import { logError, initLogger } from "loggify";

initLogger({
  level: "warn",
  output: "file",
  filePath: "./logs/app.log",
  webhookUrl: "https://my-webhook.com/log",
  compress: true
});

try {
  throw new Error("Something went wrong!");
} catch (err) {
  logError(err, { context: "login", userId: 42 }, "fatal");
}
```

## CLI Tool

```bash
node dist/cli.js ./logs/app.log
# or for compressed logs
node dist/cli.js ./logs/app.log.gz
```

Prints a readable and colorized version of the log file.

## License

MIT © Golfy