Compare commits

...

13 commits

Author SHA1 Message Date
RenovateBot 490b8e9546 Update dependency ts-jest to v29.2.3
All checks were successful
Test / build (push) Successful in 7s
2024-07-28 23:02:46 +00:00
Ethan Lane 7574139a07 Move to a fork of pkg (#202)
All checks were successful
Test / build (push) Successful in 7s
- Moved from `pkg` to `@yao-pkg/pkg` fork as its now more maintained

#170

Reviewed-on: #202
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-07-26 18:26:58 +01:00
Ethan Lane 2b3e65302b Add new limit option to limit the requested amount of posts from the Reddit API (#203)
All checks were successful
Test / build (push) Successful in 8s
- Add the limit option
- Valid number between 1 and 100
- Defaults to 100
- Updated documentation to mention this

#137

Reviewed-on: #203
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-07-26 18:23:19 +01:00
Ethan Lane 6f0109ae6e Update eslint (#198)
All checks were successful
Test / build (push) Successful in 8s
- Update eslint

#95, #185

Reviewed-on: #198
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-07-26 18:21:28 +01:00
Ethan Lane ed297b2643 Add type/dependency label to renovate config (#197)
All checks were successful
Test / build (push) Successful in 7s
- Add the `type/dependency` label to the renovate config so the bot will add the label to its created PRs

#98

Reviewed-on: #197
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-07-26 18:19:44 +01:00
Ethan Lane 56c886862c Add a newline character to the output of a file (#196)
All checks were successful
Test / build (push) Successful in 7s
- Add a newline character at the end of the outputted file contents
- This is so it follows POSIX convention

#80

Reviewed-on: #196
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-07-26 18:18:43 +01:00
Ethan Lane 7c9411b4e2 Fix deprecated toBeCalledWith function call (#195)
All checks were successful
Test / build (push) Successful in 7s
- Remove the missed deprecated `toBeCalledWith` function call and replaced with `toHaveBeenCalledWith`
- There should now no longer be any deprecated functions

#138

Reviewed-on: #195
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-07-26 18:17:21 +01:00
RenovateBot c9d44683a0 Update dependency @babel/traverse to v7.24.8 (#193)
All checks were successful
Test / build (push) Successful in 7s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@babel/traverse](https://babel.dev/docs/en/next/babel-traverse) ([source](https://github.com/babel/babel/tree/HEAD/packages/babel-traverse)) | resolutions | patch | [`7.24.7` -> `7.24.8`](https://renovatebot.com/diffs/npm/@babel%2ftraverse/7.24.7/7.24.8) |

---

### Release Notes

<details>
<summary>babel/babel (@&#8203;babel/traverse)</summary>

### [`v7.24.8`](https://github.com/babel/babel/blob/HEAD/CHANGELOG.md#v7248-2024-07-11)

[Compare Source](https://github.com/babel/babel/compare/v7.24.7...v7.24.8)

##### 👓 Spec Compliance

-   `babel-parser`
    -   [#&#8203;16567](https://github.com/babel/babel/pull/16567) Do not use strict mode in TS `declare` ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))

##### 🐛 Bug Fix

-   `babel-generator`
    -   [#&#8203;16630](https://github.com/babel/babel/pull/16630) Correctly print parens around `in` in `for` heads ([@&#8203;nicolo-ribaudo](https://github.com/nicolo-ribaudo))
    -   [#&#8203;16626](https://github.com/babel/babel/pull/16626) Fix printing of comments in `await using` ([@&#8203;nicolo-ribaudo](https://github.com/nicolo-ribaudo))
    -   [#&#8203;16591](https://github.com/babel/babel/pull/16591) fix typescript code generation for yield expression inside type expre… ([@&#8203;SreeXD](https://github.com/SreeXD))
-   `babel-parser`
    -   [#&#8203;16613](https://github.com/babel/babel/pull/16613) Disallow destructuring assignment in `using` declarations ([@&#8203;H0onnn](https://github.com/H0onnn))
    -   [#&#8203;16490](https://github.com/babel/babel/pull/16490) fix: do not add `.value: undefined` to regexp literals ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))
-   `babel-types`
    -   [#&#8203;16615](https://github.com/babel/babel/pull/16615) Remove boolean props from `ObjectTypeInternalSlot` visitor keys ([@&#8203;nicolo-ribaudo](https://github.com/nicolo-ribaudo))
-   `babel-plugin-transform-typescript`
    -   [#&#8203;16566](https://github.com/babel/babel/pull/16566) fix: Correctly handle `export import x =` ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))

##### 💅 Polish

-   `babel-generator`
    -   [#&#8203;16625](https://github.com/babel/babel/pull/16625) Avoid unnecessary parens around `async` in `for await` ([@&#8203;nicolo-ribaudo](https://github.com/nicolo-ribaudo))
-   `babel-traverse`
    -   [#&#8203;16619](https://github.com/babel/babel/pull/16619) Avoid checking `Scope.globals` multiple times ([@&#8203;liuxingbaoyu](https://github.com/liuxingbaoyu))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzEuNCIsInVwZGF0ZWRJblZlciI6IjM3LjQzMS40IiwidGFyZ2V0QnJhbmNoIjoiZGV2ZWxvcCIsImxhYmVscyI6W119-->

Reviewed-on: #193
Reviewed-by: Vylpes <ethan@vylpes.com>
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-07-22 18:01:39 +01:00
RenovateBot 35910fe6f9 Update actions/setup-node action to v4 (#192)
All checks were successful
Test / build (push) Successful in 7s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [actions/setup-node](https://github.com/actions/setup-node) | action | major | `v3` -> `v4` |

---

### Release Notes

<details>
<summary>actions/setup-node (actions/setup-node)</summary>

### [`v4`](https://github.com/actions/setup-node/compare/v3...v4)

[Compare Source](https://github.com/actions/setup-node/compare/v3...v4)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: #192
Reviewed-by: Vylpes <ethan@vylpes.com>
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-07-22 18:00:37 +01:00
RenovateBot bfc4879107 Update dependency typescript to v5.5.3 (#191)
All checks were successful
Test / build (push) Successful in 7s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [typescript](https://www.typescriptlang.org/) ([source](https://github.com/Microsoft/TypeScript)) | devDependencies | minor | [`5.4.5` -> `5.5.3`](https://renovatebot.com/diffs/npm/typescript/5.4.5/5.5.3) |

---

### Release Notes

<details>
<summary>Microsoft/TypeScript (typescript)</summary>

### [`v5.5.3`](https://github.com/microsoft/TypeScript/releases/tag/v5.5.3): TypeScript 5.5.3

[Compare Source](https://github.com/Microsoft/TypeScript/compare/v5.5.2...v5.5.3)

For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/).

For the complete list of fixed issues, check out the

-   [fixed issues query for TypeScript v5.5.3 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+5.5.3%22+is%3Aclosed+).
-   [fixed issues query for TypeScript v5.5.2 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+5.5.2%22+is%3Aclosed+).
-   [fixed issues query for TypeScript v5.5.1 (RC)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+5.5.1%22+is%3Aclosed+).
-   [fixed issues query for TypeScript v5.5.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+5.5.0%22+is%3Aclosed+).

Downloads are available on:

-   [npm](https://www.npmjs.com/package/typescript)
-   [NuGet package](https://www.nuget.org/packages/Microsoft.TypeScript.MSBuild)

### [`v5.5.2`](https://github.com/microsoft/TypeScript/releases/tag/v5.5.2): TypeScript 5.5

[Compare Source](https://github.com/Microsoft/TypeScript/compare/v5.4.5...v5.5.2)

For release notes, check out the [release announcement](https://devblogs.microsoft.com/typescript/announcing-typescript-5-5/).

For the complete list of fixed issues, check out the

-   [fixed issues query for TypeScript v5.5.2 (Stable)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+5.5.2%22+is%3Aclosed+).
-   [fixed issues query for TypeScript v5.5.1 (RC)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+5.5.1%22+is%3Aclosed+).
-   [fixed issues query for TypeScript v5.5.0 (Beta)](https://github.com/Microsoft/TypeScript/issues?utf8=%E2%9C%93\&q=is%3Aissue+milestone%3A%22TypeScript+5.5.0%22+is%3Aclosed+).

Downloads are available on:

-   [npm](https://www.npmjs.com/package/typescript)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4wLjAiLCJ0YXJnZXRCcmFuY2giOiJkZXZlbG9wIn0=-->

Reviewed-on: #191
Reviewed-by: Vylpes <ethan@vylpes.com>
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-07-22 17:59:34 +01:00
RenovateBot f93d10f8bb Update dependency np to v10.0.7 (#189)
All checks were successful
Test / build (push) Successful in 7s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [np](https://github.com/sindresorhus/np) | devDependencies | patch | [`10.0.5` -> `10.0.7`](https://renovatebot.com/diffs/npm/np/10.0.5/10.0.7) |

---

### Release Notes

<details>
<summary>sindresorhus/np (np)</summary>

### [`v10.0.7`](https://github.com/sindresorhus/np/releases/tag/v10.0.7)

[Compare Source](https://github.com/sindresorhus/np/compare/v10.0.6...v10.0.7)

-   Allow `publishConfig.registry` to be npm default registry when using Yarn berry ([#&#8203;750](https://github.com/sindresorhus/np/issues/750))  [`6c5eee3`](https://github.com/sindresorhus/np/commit/6c5eee3)

### [`v10.0.6`](https://github.com/sindresorhus/np/releases/tag/v10.0.6)

[Compare Source](https://github.com/sindresorhus/np/compare/v10.0.5...v10.0.6)

-   Fix usage with `pnpm` and `--any-branch` or `--branch` ([#&#8203;745](https://github.com/sindresorhus/np/issues/745))  [`d0c1493`](https://github.com/sindresorhus/np/commit/d0c1493)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy40MzEuNCIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AifQ==-->

Reviewed-on: #189
Reviewed-by: Vylpes <ethan@vylpes.com>
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-07-22 17:58:20 +01:00
RenovateBot 4658a7bc6f Update dependency @types/node to v20.14.11 (#188)
All checks were successful
Test / build (push) Successful in 7s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/node) ([source](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node)) | devDependencies | patch | [`20.14.2` -> `20.14.11`](https://renovatebot.com/diffs/npm/@types%2fnode/20.14.2/20.14.11) |

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy40MzEuNCIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AifQ==-->

Reviewed-on: #188
Reviewed-by: Vylpes <ethan@vylpes.com>
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-07-22 17:57:20 +01:00
RenovateBot 44ea80a42a Update dependency @typescript-eslint/eslint-plugin to v7.16.1 (#169)
All checks were successful
Test / build (push) Successful in 8s
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@typescript-eslint/eslint-plugin](https://typescript-eslint.io/packages/eslint-plugin) ([source](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin)) | devDependencies | minor | [`7.6.0` -> `7.16.1`](https://renovatebot.com/diffs/npm/@typescript-eslint%2feslint-plugin/7.6.0/7.16.1) |

---

### Release Notes

<details>
<summary>typescript-eslint/typescript-eslint (@&#8203;typescript-eslint/eslint-plugin)</summary>

### [`v7.16.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7161-2024-07-15)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.16.0...v7.16.1)

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-type-parameters] descend into all parts of mapped types in no-unnecessary-type-parameters

##### ❤️  Thank You

-   Dan Vanderkam

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.16.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7160-2024-07-08)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.15.0...v7.16.0)

##### 🚀 Features

-   **rule-tester:** stricter rule test validations

-   **eslint-plugin:** \[no-unnecessary-parameter-property-assignment] add new rule

-   **eslint-plugin:** add support for nested namespaces to unsafe-member-access

-   **eslint-plugin:** \[no-floating-promises] add checkThenables option

##### 🩹 Fixes

-   **deps:** update dependency [@&#8203;eslint-community/regexpp](https://github.com/eslint-community/regexpp) to v4.11.0

-   **eslint-plugin:** \[no-floating-promises] add `suggestions` to tests from [#&#8203;9263](https://github.com/typescript-eslint/typescript-eslint/issues/9263) `checkThenables`

-   **website:** react key error on internal pages of website

-   **eslint-plugin:** \[restrict-template-expressions] don't report tuples if `allowArray` option is enabled

##### ❤️  Thank You

-   Abraham Guo
-   auvred
-   Josh Goldberg 
-   Juan Sanchez
-   Vinccool96
-   YeonJuan
-   Yukihiro Hasegawa

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.15.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7150-2024-07-01)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.14.1...v7.15.0)

##### 🚀 Features

-   **eslint-plugin:** \[array-type] detect `Readonly<string[]>` case

-   **eslint-plugin:** back-port new rules around empty object types from v8

##### 🩹 Fixes

-   disable `EXPERIMENTAL_useProjectService` in `disabled-type-checked` shared config

-   **eslint-plugin:** \[no-unsafe-return] differentiate a types-error any from a true any

-   **eslint-plugin:** \[no-unsafe-call] differentiate a types-error any from a true any

##### ❤️  Thank You

-   auvred
-   Kim Sang Du
-   rgehbt
-   Vinccool96

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.14.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7141-2024-06-24)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.14.0...v7.14.1)

##### 🩹 Fixes

-   **eslint-plugin:** \[prefer-nullish-coalescing] treat enums and literals as their underlying primitive types

-   **eslint-plugin:** \[prefer-nullish-coalescing] ensure ternary fix does not remove parens

##### ❤️  Thank You

-   Jake Bailey

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.14.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7140-2024-06-24)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.13.1...v7.14.0)

##### 🚀 Features

-   support TypeScript 5.5

##### 🩹 Fixes

-   **eslint-plugin:** \[no-extraneous-class] handle abstract members

-   **eslint-plugin:** \[prefer-nullish-coalescing] handle intersected primitive types

-   **eslint-plugin:** \[no-invalid-this] support AccessorProperty

##### ❤️  Thank You

-   Brad Zacher
-   cm-ayf
-   Jake Bailey
-   James Zhan
-   Joshua Chen
-   yoshi2no

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.13.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7131-2024-06-17)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.13.0...v7.13.1)

##### 🩹 Fixes

-   **eslint-plugin:** \[prefer-readonly] refine report locations

-   **eslint-plugin:** \[return-await] support explicit resource management

-   **eslint-plugin:** \[no-unsafe-member-access] differentiate a types-error any from a true any

##### ❤️  Thank You

-   Kirk Waiblinger
-   Yukihiro Hasegawa

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.13.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7130-2024-06-10)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.12.0...v7.13.0)

##### 🚀 Features

-   **typescript-estree:** require `import = require()` argument to be a string literal

-   **typescript-estree:** forbid `.body`, `.async`, `.generator` on `declare function`

-   **eslint-plugin:** \[no-dynamic-delete] allow all string literals as index

##### 🩹 Fixes

-   **ast-spec:** function-call-like callee should be Expression not LeftHandSideExpression

-   **scope-manager:** handle index signature in class

-   **eslint-plugin:** \[init-declarations] refine report locations

-   **eslint-plugin:** \[no-base-to-string] make error message more nuanced

-   **eslint-plugin:** \[no-unsafe-assignment] be more specific about error types

-   **eslint-plugin:** \[no-magic-numbers] fix implementation of the `ignore` option

##### ❤️  Thank You

-   Fotis Papadogeorgopoulos
-   Joshua Chen
-   Kirk Waiblinger
-   Tobiloba Adedeji
-   Vinccool96
-   YeonJuan

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.12.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7120-2024-06-03)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.11.0...v7.12.0)

##### 🚀 Features

-   **eslint-plugin:** \[no-useless-template-literals] rename to `no-useless-template-expression` (deprecate `no-useless-template-literals`)

-   **rule-tester:** check for parsing errors in suggestion fixes

-   **rule-tester:** port `checkDuplicateTestCases` from ESLint

-   **eslint-plugin:** \[no-floating-promises] add option 'allowForKnownSafePromises'

##### 🩹 Fixes

-   no-useless-template-expression -> no-unnecessary-template-expression

-   **eslint-plugin:** \[no-unnecessary-type-assertion] combine template literal check with `const` variable check

-   **eslint-plugin:** \[dot-notation] fix false positive when accessing private/protected property with optional chaining

-   **eslint-plugin:** \[explicit-member-accessibility] refine report locations

-   **eslint-plugin:** \[no-unnecessary-type-assertion] declares are always defined, so always check `declare`s

-   **eslint-plugin:** \[prefer-literal-enum-member] allow using member it self on allowBitwiseExpressions

-   **eslint-plugin:** \[return-await] clean up in-try-catch detection and make autofixes safe

-   **eslint-plugin:** \[member-ordering] also TSMethodSignature can be get/set

##### ❤️  Thank You

-   Abraham Guo
-   Han Yeong-woo
-   Joshua Chen
-   Kim Sang Du
-   Kirk Waiblinger
-   YeonJuan

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.11.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7110-2024-05-27)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.10.0...v7.11.0)

##### 🚀 Features

-   **eslint-plugin:** deprecate prefer-ts-expect-error in favor of ban-ts-comment

##### 🩹 Fixes

-   **eslint-plugin:** \[consistent-type-assertions] prevent syntax errors on arrow functions

##### ❤️  Thank You

-   Abraham Guo
-   auvred
-   Dom Armstrong
-   Kirk Waiblinger

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.10.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#7100-2024-05-20)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.9.0...v7.10.0)

##### 🚀 Features

-   **eslint-plugin:** \[sort-type-constituents] support case sensitive sorting

##### 🩹 Fixes

-   **eslint-plugin:** \[prefer-regexp-exec] fix heuristic to check whether regex may contain global flag

##### ❤️  Thank You

-   auvred
-   Emanuel Hoogeveen
-   jsfm01
-   Kirk Waiblinger

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.9.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#790-2024-05-13)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.8.0...v7.9.0)

##### 🩹 Fixes

-   **eslint-plugin:** \[explicit-function-return-types] fix false positive on default parameters

##### ❤️  Thank You

-   Kirk Waiblinger
-   Sheetal Nandi
-   Vinccool96

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.8.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#780-2024-04-29)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.7.1...v7.8.0)

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unsafe-argument] handle  tagged templates

-   **eslint-plugin:** \[prefer-optional-chain] suggests optional chaining during strict null equality check

-   **eslint-plugin:** \[consistent-type-assertions] handle tagged templates

-   **eslint-plugin:** \[no-unsafe-return] handle union types

-   **eslint-plugin:** \[no-unused-vars] clear error report range

##### ❤️  Thank You

-   auvred
-   Josh Goldberg 
-   jsfm01
-   Kim Sang Du
-   YeonJuan

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.7.1`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#771-2024-04-22)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.7.0...v7.7.1)

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unsafe-assignment] handle shorthand property assignment

-   **eslint-plugin:** \[explicit-function-return-type] fix checking wrong ancestor's return type

-   **eslint-plugin:** \[prefer-optional-chain] only look at left operand for `requireNullish`

-   **eslint-plugin:** \[no-for-in-array] refine report location

-   **eslint-plugin:** \[no-unnecessary-type-assertion] allow non-null assertion for void type

##### ❤️  Thank You

-   Abraham Guo
-   Kirk Waiblinger
-   YeonJuan

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

### [`v7.7.0`](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#770-2024-04-15)

[Compare Source](https://github.com/typescript-eslint/typescript-eslint/compare/v7.6.0...v7.7.0)

##### 🚀 Features

-   **eslint-plugin:** replace `no-new-symbol` with `no-new-native-nonconstructor`

##### ❤️  Thank You

-   Dave
-   Josh Goldberg 

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4wLjAiLCJ1cGRhdGVkSW5WZXIiOiIzNy40MzEuNCIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AifQ==-->

Reviewed-on: #169
Reviewed-by: Vylpes <ethan@vylpes.com>
Co-authored-by: Renovate Bot <renovate@vylpes.com>
Co-committed-by: Renovate Bot <renovate@vylpes.com>
2024-07-22 17:55:36 +01:00
22 changed files with 673 additions and 698 deletions

View file

@ -1 +0,0 @@
dist/

View file

@ -1,50 +0,0 @@
{
"parserOptions": {
"ecmaVersion": 6
},
"extends": [
"eslint:recommended"
],
"rules": {
"camelcase": "error",
"brace-style": [
"error",
"1tbs"
],
"comma-dangle": [
"error",
"never"
],
"comma-spacing": [
"error",
{
"before": false,
"after": true
}
],
"comma-style": [
"error",
"last"
],
"arrow-body-style": [
"error",
"as-needed"
],
"arrow-parens": [
"error",
"as-needed"
],
"arrow-spacing": "error",
"no-var": "error",
"prefer-template": "error",
"prefer-const": "error"
},
"globals": {
"exports": "writable",
"module": "writable",
"require": "writable",
"process": "writable",
"console": "writable",
"jest": "writable"
}
}

View file

@ -13,7 +13,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: 20.x node-version: 20.x
- run: yarn install --frozen-lockfile - run: yarn install --frozen-lockfile
@ -26,7 +26,7 @@ jobs:
runs-on: node runs-on: node
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: actions/setup-node@v3 - uses: actions/setup-node@v4
with: with:
node-version: 20.x node-version: 20.x
- run: yarn install --frozen-lockfile - run: yarn install --frozen-lockfile

View file

@ -17,7 +17,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Use Node.js - name: Use Node.js
uses: actions/setup-node@v3 uses: actions/setup-node@v4
with: with:
node-version: 20.x node-version: 20.x
- run: yarn install --frozen-lockfile - run: yarn install --frozen-lockfile

View file

@ -4,7 +4,7 @@ Since Version 2.2, Random Bunny contains a command line interface (CLI).
## Downloads ## Downloads
The project can be downloaded as a binary for your system via the [GitHub Releases](https://github.com/Vylpes/random-bunny/releases) or [Gitea Releases](https://gitea.vylpes.xyz/RabbitLabs/random-bunny/releases) page. The project can be downloaded as a binary for your system via the [GitHub Releases](https://github.com/Vylpes/random-bunny/releases) or [Forgejo Releases](https://git.vylpes.xyz/RabbitLabs/random-bunny/releases) page.
We currently support: We currently support:
- Linux (x64) - Linux (x64)
@ -13,6 +13,8 @@ We currently support:
The git repository can also be cloned and ran via `yarn build` and `yarn start`. The git repository can also be cloned and ran via `yarn build` and `yarn start`.
You can produce the binary using the `yarn package` command. This creates the binaries in the `./bin` folder.
> **NOTE:** We are aware of a bug in the macOS Arm64 builds failing to execute. For now you're still able to use the x64 builds under Rosetta fine. This will hopefully be fixed in a future release. > **NOTE:** We are aware of a bug in the macOS Arm64 builds failing to execute. For now you're still able to use the x64 builds under Rosetta fine. This will hopefully be fixed in a future release.
## Default Output ## Default Output
@ -20,7 +22,7 @@ The git repository can also be cloned and ran via `yarn build` and `yarn start`.
By default, the command will fetch a random image from `r/rabbits` and return it in a human-readable output. By default, the command will fetch a random image from `r/rabbits` and return it in a human-readable output.
``` ```
$ randombunny $ random-bunny
Archived = false Archived = false
Downvotes = 0 Downvotes = 0
@ -38,11 +40,11 @@ Url = https://i.redd.it/sfz0srdrimjc1.png
The command also includes a help option in case you are stuck. The command also includes a help option in case you are stuck.
``` ```
$ randombunny --help $ random-bunny --help
# or # or
$ randombunny -h $ random-bunny -h
Usage: random-bunny [options] Usage: random-bunny [options]
@ -55,6 +57,7 @@ Options:
-q, --query-metadata Include query metadata in result -q, --query-metadata Include query metadata in result
-o <file> Output to file -o <file> Output to file
--sort <sort> Sort by (choices: "hot", "new", "top", default: "hot") --sort <sort> Sort by (choices: "hot", "new", "top", default: "hot")
--limit <limit> The amount of posts to fetch from the reddit api (default: 100)
-h, --help display help for command -h, --help display help for command
``` ```
@ -63,11 +66,11 @@ Options:
You can also convert the output into JSON, if you need to input it to another program. You can also convert the output into JSON, if you need to input it to another program.
```bash ```bash
$ randombunny --json $ random-bunny --json
# or # or
$ randonbunny -j $ randon-bunny -j
{"Archived":false,"Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1av1rg9/cute_baby_bun/","Subreddit":"Rabbits","SubredditSubscribers":486085,"Title":"Cute baby bun","Ups":210,"Url":"https://i.redd.it/sfz0srdrimjc1.png"} {"Archived":false,"Downs":0,"Hidden":false,"Permalink":"/r/Rabbits/comments/1av1rg9/cute_baby_bun/","Subreddit":"Rabbits","SubredditSubscribers":486085,"Title":"Cute baby bun","Ups":210,"Url":"https://i.redd.it/sfz0srdrimjc1.png"}
``` ```
@ -79,9 +82,9 @@ You can also choose the sorting option which reddit will use to return the avail
This defaults to "hot". The valid options are "hot", "new", and "top". This defaults to "hot". The valid options are "hot", "new", and "top".
``` ```
$ randombunny --sort hot $ random-bunny --sort hot
$ randombunny --sort new $ random-bunny --sort new
$ randomBunny --sort top $ random-bunny --sort top
``` ```
@ -92,8 +95,8 @@ You can change the subreddit which the command fetches from.
This defaults to "rabbits" This defaults to "rabbits"
``` ```
$ randombunny --subreddit rabbits $ random-bunny --subreddit rabbits
$ randombunny -s horses $ random-bunny -s horses
``` ```
## Output to file ## Output to file
@ -103,3 +106,17 @@ If you'd rather send the output to a file, you can supply the `-o` flag.
``` ```
$ randombunny -o ~/Desktop/output.txt $ randombunny -o ~/Desktop/output.txt
``` ```
## Reddit API Return Limits
You can also limit the amount the posts the script requests from the Reddit API
using the `--limit` option.
This defaults to 100. This accepts any number between 1 and 100.
Please note limiting the calls to less than 100 will give a higher chance of
the script not finding any valid image post to return.
```
$ random-bunny --limit 50
```

54
eslint.config.mjs Normal file
View file

@ -0,0 +1,54 @@
import js from "@eslint/js";
import ts from "typescript-eslint";
export default [
{
ignores: [
"**/dist/",
"eslint.config.mjs",
"jest.config.cjs",
"jest.setup.js"
],
},
js.configs.recommended,
...ts.configs.recommended,
{
languageOptions: {
globals: {
exports: "writable",
module: "writable",
require: "writable",
process: "writable",
console: "writable",
jest: "writable",
},
ecmaVersion: 6,
sourceType: "script",
},
files: [
"./src",
"./tests"
],
rules: {
camelcase: "error",
"brace-style": ["error", "1tbs"],
"comma-dangle": ["error", "never"],
"comma-spacing": ["error", {
before: false,
after: true,
}],
"comma-style": ["error", "last"],
"arrow-body-style": ["error", "as-needed"],
"arrow-parens": ["error", "as-needed"],
"arrow-spacing": "error",
"no-var": "error",
"prefer-template": "error",
"prefer-const": "error",
},
}
];

View file

@ -39,19 +39,22 @@
"homepage": "https://gitea.vylpes.xyz/RabbitLabs/random-bunny", "homepage": "https://gitea.vylpes.xyz/RabbitLabs/random-bunny",
"funding": "https://ko-fi.com/vylpes", "funding": "https://ko-fi.com/vylpes",
"devDependencies": { "devDependencies": {
"@types/eslint": "^8.21.1", "@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.7.0",
"@types/eslint": "^9.6.0",
"@types/jest": "^29.5.8", "@types/jest": "^29.5.8",
"@types/node": "^20.0.0", "@types/node": "^20.0.0",
"@typescript-eslint/eslint-plugin": "^7.0.0", "@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0", "@typescript-eslint/parser": "^7.0.0",
"eslint": "^8.49.0", "@yao-pkg/pkg": "^5.12.0",
"eslint": "^9.7.0",
"jest": "^29.7.0", "jest": "^29.7.0",
"jest-mock-extended": "^3.0.3", "jest-mock-extended": "^3.0.3",
"np": "^10.0.0", "np": "^10.0.0",
"pkg": "^5.8.1",
"ts-jest": "^29.1.1", "ts-jest": "^29.1.1",
"ts-mockito": "^2.6.1", "ts-mockito": "^2.6.1",
"typescript": "^5.0.0" "typescript": "^5.0.0",
"typescript-eslint": "^7.17.0"
}, },
"resolutions": { "resolutions": {
"np/**/got": "^14.0.0", "np/**/got": "^14.0.0",

View file

@ -33,7 +33,7 @@ console.log(result);
### `randomBunny()` ### `randomBunny()`
Returns a `json string` for a random post. Accepts 2 arguments: `subreddit`, and `sortby` ('new', 'hot', 'top') Returns a `json string` for a random post. Accepts 3 arguments: `subreddit`, `sortby` ('new', 'hot', 'top'), and `limit` (1-100, default 100)
The json string which gets returned consists of: The json string which gets returned consists of:
- archived - archived

View file

@ -1,4 +1,5 @@
{ {
"$schema": "https://docs.renovatebot.com/renovate-schema.json", "$schema": "https://docs.renovatebot.com/renovate-schema.json",
"baseBranches": ["develop"] "baseBranches": ["develop"],
"labels": ["type/dependencies"]
} }

View file

@ -14,11 +14,12 @@ program
.option('-j, --json', 'Output as JSON') .option('-j, --json', 'Output as JSON')
.option('-q, --query-metadata', 'Include query metadata in result') .option('-q, --query-metadata', 'Include query metadata in result')
.option('-o <file>', 'Output to file') .option('-o <file>', 'Output to file')
.addOption(new Option('--sort <sort>', 'Sort by').default('hot').choices(['hot', 'new', 'top'])); .addOption(new Option('--sort <sort>', 'Sort by').default('hot').choices(['hot', 'new', 'top']))
.addOption(new Option('--limit <limit>', 'The amount of posts to fetch from the reddit api').default(100));
program.parse(); program.parse();
const options: ICliOptions = program.opts(); const options: ICliOptions = program.opts();
randomBunny(options.subreddit, options.sort) randomBunny(options.subreddit, options.sort, options.limit)
.then((response) => exit(CliHelper.Endpoint(response, options))); .then((response) => exit(CliHelper.Endpoint(response, options)));

View file

@ -3,4 +3,5 @@ export enum ErrorCode {
FailedToFetchReddit, FailedToFetchReddit,
UnableToParseJSON, UnableToParseJSON,
NoImageResultsFound, NoImageResultsFound,
LimitOutOfRange,
} }

View file

@ -2,4 +2,5 @@ export default class ErrorMessages {
public static readonly FailedToFetchReddit = "Failed to fetch result from Reddit"; public static readonly FailedToFetchReddit = "Failed to fetch result from Reddit";
public static readonly UnableToParseJSON = "Unable to parse the JSON result"; public static readonly UnableToParseJSON = "Unable to parse the JSON result";
public static readonly NoImageResultsFound = "No image results found in response from Reddit"; public static readonly NoImageResultsFound = "No image results found in response from Reddit";
public static readonly LimitOutOfRange = "Limit must be a number between 1 and 100";
} }

View file

@ -3,5 +3,6 @@ export default interface ICliOptions {
json?: boolean, json?: boolean,
sort: "new" | "hot" | "top", sort: "new" | "hot" | "top",
o?: string, o?: string,
limit: number,
queryMetadata?: boolean, queryMetadata?: boolean,
} }

View file

@ -1,4 +1,5 @@
export default interface QueryResult { export default interface QueryResult {
subreddit: string, subreddit: string,
sortBy: string, sortBy: string,
limit: number,
} }

View file

@ -9,7 +9,7 @@ export default class CliHelper {
const output = OutputHelper.GenerateOutput(response, options); const output = OutputHelper.GenerateOutput(response, options);
if (options.o) { if (options.o) {
writeFileSync(options.o, output); writeFileSync(options.o, `${output}\n`);
} else { } else {
console.log(output); console.log(output);
} }

View file

@ -24,6 +24,7 @@ export default class OutputHelper {
if (options.queryMetadata != null) { if (options.queryMetadata != null) {
outputLines.push(`Query.Subreddit = ${response.Query.subreddit}`); outputLines.push(`Query.Subreddit = ${response.Query.subreddit}`);
outputLines.push(`Query.Sort By = ${response.Query.sortBy}`); outputLines.push(`Query.Sort By = ${response.Query.sortBy}`);
outputLines.push(`Query.Limit = ${response.Query.limit}`);
} }
return outputLines.join("\n"); return outputLines.join("\n");

View file

@ -7,8 +7,23 @@ import { ErrorCode } from "./constants/ErrorCode";
import ErrorMessages from "./constants/ErrorMessages"; import ErrorMessages from "./constants/ErrorMessages";
import ImageHelper from "./helpers/imageHelper"; import ImageHelper from "./helpers/imageHelper";
export default async function randomBunny(subreddit: string, sortBy: "new" | "hot" | "top" = 'hot'): Promise<IReturnResult> { export default async function randomBunny(subreddit: string, sortBy: "new" | "hot" | "top" = 'hot', limit: number = 100): Promise<IReturnResult> {
const result = await fetch(`https://reddit.com/r/${subreddit}/${sortBy}.json?limit=100`) if (limit < 1 || limit > 100) {
return {
IsSuccess: false,
Query: {
subreddit: subreddit,
sortBy: sortBy,
limit: limit,
},
Error: {
Code: ErrorCode.LimitOutOfRange,
Message: ErrorMessages.LimitOutOfRange,
}
};
}
const result = await fetch(`https://reddit.com/r/${subreddit}/${sortBy}.json?limit=${limit}`)
.then((res) => { .then((res) => {
return res; return res;
}) })
@ -22,6 +37,7 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
Query: { Query: {
subreddit: subreddit, subreddit: subreddit,
sortBy: sortBy, sortBy: sortBy,
limit: limit,
}, },
Error: { Error: {
Code: ErrorCode.FailedToFetchReddit, Code: ErrorCode.FailedToFetchReddit,
@ -38,6 +54,7 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
Query: { Query: {
subreddit: subreddit, subreddit: subreddit,
sortBy: sortBy, sortBy: sortBy,
limit: limit,
}, },
Error: { Error: {
Code: ErrorCode.UnableToParseJSON, Code: ErrorCode.UnableToParseJSON,
@ -60,6 +77,7 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
Query: { Query: {
subreddit: subreddit, subreddit: subreddit,
sortBy: sortBy, sortBy: sortBy,
limit: limit,
}, },
Error: { Error: {
Code: ErrorCode.NoImageResultsFound, Code: ErrorCode.NoImageResultsFound,
@ -85,6 +103,7 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
Query: { Query: {
subreddit: subreddit, subreddit: subreddit,
sortBy: sortBy, sortBy: sortBy,
limit: limit,
}, },
Error: { Error: {
Code: ErrorCode.NoImageResultsFound, Code: ErrorCode.NoImageResultsFound,
@ -115,6 +134,7 @@ export default async function randomBunny(subreddit: string, sortBy: "new" | "ho
Query: { Query: {
subreddit: subreddit, subreddit: subreddit,
sortBy: sortBy, sortBy: sortBy,
limit: limit,
}, },
Result: redditResult Result: redditResult
}; };

View file

@ -25,5 +25,6 @@ Title = This is my Ms Bear!
Upvotes = 17 Upvotes = 17
Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d Url = https://preview.redd.it/d5yno653zf7d1.jpg?width=640&crop=smart&auto=webp&s=5064d1caec3c12ac2855eb57ff131d0b313d5e9d
Query.Subreddit = rabbits Query.Subreddit = rabbits
Query.Sort By = hot" Query.Sort By = hot
Query.Limit = 100"
`; `;

View file

@ -35,7 +35,7 @@ describe("Endpoint", () => {
expect(OutputHelper.GenerateOutput).toHaveBeenCalledWith(response, options); expect(OutputHelper.GenerateOutput).toHaveBeenCalledWith(response, options);
expect(fs.writeFileSync).toHaveBeenCalledTimes(1); expect(fs.writeFileSync).toHaveBeenCalledTimes(1);
expect(fs.writeFileSync).toHaveBeenCalledWith("file.txt", "test output"); expect(fs.writeFileSync).toHaveBeenCalledWith("file.txt", "test output\n");
expect(console.log).not.toHaveBeenCalled(); expect(console.log).not.toHaveBeenCalled();

View file

@ -10,6 +10,7 @@ describe("GenerateOutput", () => {
Query: { Query: {
subreddit: "rabbits", subreddit: "rabbits",
sortBy: "hot", sortBy: "hot",
limit: 100,
}, },
Result: { Result: {
Archived: false, Archived: false,
@ -40,6 +41,7 @@ describe("GenerateOutput", () => {
Query: { Query: {
subreddit: "rabbits", subreddit: "rabbits",
sortBy: "hot", sortBy: "hot",
limit: 100,
}, },
Result: { Result: {
Archived: false, Archived: false,
@ -72,6 +74,7 @@ describe("GenerateOutput", () => {
Query: { Query: {
subreddit: "rabbits", subreddit: "rabbits",
sortBy: "hot", sortBy: "hot",
limit: 100,
}, },
Result: { Result: {
Archived: false, Archived: false,

View file

@ -7,6 +7,10 @@ import fetch from "got-cjs";
jest.mock('got-cjs'); jest.mock('got-cjs');
const fetchMock = jest.mocked(fetch); const fetchMock = jest.mocked(fetch);
beforeEach(() => {
fetchMock.mockReset();
});
describe('randomBunny', () => { describe('randomBunny', () => {
test('GIVEN subreddit AND sortBy is supplied, EXPECT successful result', async() => { test('GIVEN subreddit AND sortBy is supplied, EXPECT successful result', async() => {
fetchMock.mockResolvedValue({ fetchMock.mockResolvedValue({
@ -122,7 +126,7 @@ describe('randomBunny', () => {
expect(result.Error!.Code).toBe(ErrorCode.NoImageResultsFound); expect(result.Error!.Code).toBe(ErrorCode.NoImageResultsFound);
expect(result.Error!.Message).toBe(ErrorMessages.NoImageResultsFound); expect(result.Error!.Message).toBe(ErrorMessages.NoImageResultsFound);
expect(fetchMock).toBeCalledWith('https://reddit.com/r/rabbits/new.json?limit=100'); expect(fetchMock).toHaveBeenCalledWith('https://reddit.com/r/rabbits/new.json?limit=100');
}); });
test('GIVEN randomSelect does NOT find a valid response, EXPECT failure result', async () => { test('GIVEN randomSelect does NOT find a valid response, EXPECT failure result', async () => {
@ -231,4 +235,106 @@ describe('randomBunny', () => {
expect(result.Error?.Code).toBe(ErrorCode.NoImageResultsFound); expect(result.Error?.Code).toBe(ErrorCode.NoImageResultsFound);
expect(result.Error?.Message).toBe(ErrorMessages.NoImageResultsFound); expect(result.Error?.Message).toBe(ErrorMessages.NoImageResultsFound);
}); });
test("GIVEN limit is supplied, EXPECT limit sent to the API", async () => {
fetchMock.mockResolvedValue({
body: JSON.stringify({
data: {
children: [
{
data: {
archived: false,
downs: 0,
hidden: false,
permalink: '/r/Rabbits/comments/12pa5te/someone_told_pickles_its_monday_internal_fury/',
subreddit: 'Rabbits',
subreddit_subscribers: 298713,
title: 'Someone told pickles its Monday… *internal fury*',
ups: 1208,
url: 'https://i.redd.it/cr8xudsnkgua1.jpg',
},
},
],
}
}),
});
const result = await randomBunny('rabbits', 'new', 50);
expect(result.IsSuccess).toBeTruthy();
expect(result.Result).toBeDefined();
expect(result.Error).toBeUndefined();
expect(fetchMock).toHaveBeenCalledWith('https://reddit.com/r/rabbits/new.json?limit=50');
});
test("GIVEN limit is less than 1, EXPECT error to be returned", async () => {
fetchMock.mockResolvedValue({
body: JSON.stringify({
data: {
children: [
{
data: {
archived: false,
downs: 0,
hidden: false,
permalink: '/r/Rabbits/comments/12pa5te/someone_told_pickles_its_monday_internal_fury/',
subreddit: 'Rabbits',
subreddit_subscribers: 298713,
title: 'Someone told pickles its Monday… *internal fury*',
ups: 1208,
url: 'https://i.redd.it/cr8xudsnkgua1.jpg',
},
},
],
}
}),
});
const result = await randomBunny('rabbits', 'new', 0);
expect(result.IsSuccess).toBeFalsy();
expect(result.Result).toBeUndefined();
expect(result.Error).toBeDefined();
expect(result.Error!.Code).toBe(ErrorCode.LimitOutOfRange);
expect(result.Error!.Message).toBe(ErrorMessages.LimitOutOfRange);
expect(fetchMock).not.toHaveBeenCalled();
});
test("GIVEN limit is greater than 100, EXPECT error to be returned", async () => {
fetchMock.mockResolvedValue({
body: JSON.stringify({
data: {
children: [
{
data: {
archived: false,
downs: 0,
hidden: false,
permalink: '/r/Rabbits/comments/12pa5te/someone_told_pickles_its_monday_internal_fury/',
subreddit: 'Rabbits',
subreddit_subscribers: 298713,
title: 'Someone told pickles its Monday… *internal fury*',
ups: 1208,
url: 'https://i.redd.it/cr8xudsnkgua1.jpg',
},
},
],
}
}),
});
const result = await randomBunny('rabbits', 'new', 101);
expect(result.IsSuccess).toBeFalsy();
expect(result.Result).toBeUndefined();
expect(result.Error).toBeDefined();
expect(result.Error!.Code).toBe(ErrorCode.LimitOutOfRange);
expect(result.Error!.Message).toBe(ErrorMessages.LimitOutOfRange);
expect(fetchMock).not.toHaveBeenCalled();
});
}); });

1053
yarn.lock

File diff suppressed because it is too large Load diff