Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tests #360

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

10 changes: 0 additions & 10 deletions .eslintrc.json

This file was deleted.

48 changes: 0 additions & 48 deletions .github/workflows/codequality.yml

This file was deleted.

31 changes: 15 additions & 16 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ on:

jobs:
test:
name: Node v${{ matrix.node_version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node_version: [18]
os: [ubuntu-latest]
name: Tests
runs-on: ubuntu-latest

steps:
- name: Checkout Project
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node_version }}
uses: actions/setup-node@v2
uses: actions/checkout@v4

- name: Install NodeJS
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
cache: yarn
node-version: 20

- name: Restore CI Cache
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-${{ matrix.node_version }}-${{ hashFiles(matrix.os == 'windows-latest' && '**\yarn.lock' || '**/yarn.lock') }}
key: NODE-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- name: Install Dependencies
run: yarn
- name: Build Project
run: yarn build
- name: Test
run: yarn test

- name: Run Tests
run: yarn test
8 changes: 0 additions & 8 deletions .prettierrc

This file was deleted.

118 changes: 2 additions & 116 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# OldSchoolJS

A NodeJS library for doing everything OSRS related. Access the OSRS hiscores, news, worlds, wiki, items, simulating killing monsters, and opening clue caskets - and more.
A NodeJS library for doing everything OSRS related. Access the OSRS hiscores, wiki, items, simulating killing monsters, and opening clue caskets - and more.

For discussion, help or questions - please join https://discord.gg/ob and then our `#developers` channel.

Expand Down Expand Up @@ -129,91 +129,6 @@ const CorporealBeastTable = new LootTable()
CorporealBeastTable.roll();
```

## News

```js
import { News } from 'oldschooljs';
```

Be careful with _fetching_ news articles too often, as the website will ratelimit you after roughly 30 requests in a short period. Whenever a fetch is done, the `News` collection will have any new articles cached.

Rather than fetching articles on demand, you may want to

#### Fetch recent news articles

```js
const recentArticles = await News.fetchRecent();

const mostRecentArticle = recentArticles.first();
```

#### Get news articles for a specific month

```js
const monthOfArticles = await News.filter(article => article.year === 2018 && article.month === 12);

console.log(`There were ${monthOfArticles.size} articles in that month.`);
```

#### Fetch news articles for a specific month

This will _fetch_ news articles for a specific month, i.e it wont be cached. In most cases you can just use `News.filter()` instead of this.

```js
const monthOfArticles = await News.fetchMonth({ year: 2018, month: 12 });

console.log(`There were ${monthOfArticles.size} articles in that month.`);
```

#### List every available news article

If you want this to be up to 100% up to date, you need to call `News.fetchNewArticles()` to fetch newly released articles that aren't cached by oldschooljs.

```js
for (const article of News.values()) {
console.log(article);
}
```

## Worlds

```js
import { Worlds } from 'oldschooljs';
```

#### Fetch and cache all worlds

You **must** call this atleast once to be able to use `Worlds`. To keep worlds up to date, fetching once at startup and then once every few days is enough. If you need an up to date playercount of worlds, you can call it more often or on demand.

```js
await Worlds.fetch();
```

#### Getting a particular world

You can use either form of numbering, giving `301` and `1` will both give you World 1.

```js
const worldOne = Worlds.get(301);
const worldTwo = Worlds.get(2);
```

#### Filtering Worlds

```js
const australianWorlds = Worlds.filter(world => world.location === 'Australia');

console.log(`There are ${australianWorlds.size} Australian Worlds!`);
```

#### Iterating over worlds

```js
for (const world of Worlds.values()) {
console.log(world);
}
```

## Wiki

```js
Expand Down Expand Up @@ -244,27 +159,6 @@ const twistedBowPage = await Wiki.fetchPage(82098);
console.log(twistedBowPage);
```

## Polls

```js
import { Polls } from 'oldschooljs';
```

#### Iterating over worlds

```js
for (const poll of Polls.values()) {
console.log(poll.title);
}
```

#### Getting all polls in a year

```js
const pollsFrom2013 = Polls.filter(poll => new Date(poll.datePosted).getFullYear() === 2013);
console.log(pollsFrom2013.size);
```

## Utilities

```js
Expand Down Expand Up @@ -293,12 +187,4 @@ Util.fromKMB('5'); // 5
Util.fromKMB('1k'); // 1000
Util.fromKMB('1m'); // 1000000
Util.fromKMB('1.2b'); // 1200000000
```

## Planned features

- Ability to ping worlds?
- CrystalMathLabs
- Simulating: killing monsters, opening clue scrolls, pets (like in osbot)
- Quests (e.g. containing all wiki data on quests)
- fetch wiki page by item ID?
```
44 changes: 44 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$schema": "https://biomejs.dev/schemas/1.5.3/schema.json",
"organizeImports": {
"enabled": true
},
"files": {
"maxSize": 10000000
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"a11y": {
"useAltText": "off",
"useKeyWithClickEvents": "off"
},
"suspicious": {
"noExplicitAny": "warn"
},
"style": {
"noNonNullAssertion": "warn",
"noParameterAssign": "off",
"useExponentiationOperator": "off",
"noUselessElse": "off"
},
"correctness": {
"useExhaustiveDependencies": "warn",
"noUnnecessaryContinue": "warn"
},
"complexity": {
"noExtraBooleanCast": "warn"
}
}
},
"formatter": {
"enabled": true,
"formatWithErrors": true,
"indentStyle": "tab",
"indentWidth": 4,
"lineWidth": 120,
"lineEnding": "lf",
"ignore": []
}
}
38 changes: 13 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "oldschooljs",
"version": "2.3.8",
"description": "Allows you to interact with the OSRS Hiscores, Wiki, Worlds, Items, News & more.",
"description": "Allows you to interact with the OSRS Hiscores, Wiki, Items, & more.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"license": "MIT",
Expand All @@ -13,42 +13,30 @@
"prepublishOnly": "yarn build",
"test": "yarn test:run",
"test:unit": "vitest run --coverage",
"test:run": "yarn build && yarn test:unit",
"test:lint": "eslint \"{src,test}/**/*.ts\"",
"lint": "eslint --ext ts src test scripts --fix && prettier --check \"{src,test}/**/*.json\" --write",
"test:run": "yarn build && concurrently \"yarn test:lint\" \"yarn test:unit\"",
"build": "tsc -p .",
"dev": "tsc --watch -p .",
"prepareData": "yarn build && yarn prepareData:run",
"prepareData:run": "ts-node scripts/prepare",
"prepmon": "yarn build && ts-node scripts/prepareMonsters.ts"
"prepareData:run": "tsx scripts/prepare",
"prepmon": "yarn build && tsx scripts/prepareMonsters.ts",
"lint": "biome check --apply ./src --diagnostic-level=error",
"test:lint": "biome check ./src --diagnostic-level=error"
},
"dependencies": {
"deepmerge": "^4.2.2",
"deepmerge": "^4.3.1",
"e": "^0.2.32",
"jsdom": "^21.1.1",
"node-fetch": "^2.6.7"
},
"devDependencies": {
"@types/deepmerge": "^2.2.0",
"@types/jsdom": "^16.2.5",
"typedoc": "^0.19.2",
"@oldschoolgg/eslint-config": "^2.0.13",
"@biomejs/biome": "^1.5.3",
"@oldschoolgg/ts-config": "^0.0.1",
"@types/node": "^14.18.12",
"@types/node-fetch": "^2.6.1",
"@typescript-eslint/eslint-plugin": "^5.41.0",
"@typescript-eslint/parser": "^5.41.0",
"@vitest/coverage-c8": "^0.31.0",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-simple-import-sort": "^8.0.0",
"eslint-plugin-unicorn": "^44.0.2",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"typescript": "^5.0.2",
"vitest": "^0.31.0"
"@vitest/coverage-v8": "^1.3.1",
"concurrently": "^8.2.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
"vitest": "^1.3.1"
},
"keywords": [
"osrs",
Expand Down
4 changes: 0 additions & 4 deletions scripts/prepare.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import minifyDist from './minifyDist';
import prepareItems from './prepareItems';
import prepareNews from './prepareNews';
import preparePolls from './preparePolls';

prepareNews();
preparePolls();
minifyDist();
prepareItems();
Loading
Loading