Skip to content

Commit

Permalink
add tests and configure prettier (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
BolajiOlajide authored Jun 26, 2024
1 parent 9b91562 commit 4d58d51
Show file tree
Hide file tree
Showing 21 changed files with 2,000 additions and 211 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ jobs:

- name: Install dependencies
run: pnpm install --frozen-lockfile
- run: pnpm run build
- uses: simenandre/publish-with-pnpm@v1

- name: Test
run: pnpm test

- name: Build
run: |
pnpm run build
- uses: simenandre/publish-with-pnpm@v2
with:
npm-auth-token: ${{ secrets.NPM_ACCESS_TOKEN }}
88 changes: 88 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
setup:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 8

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'pnpm'

- uses: actions/cache@v4
with:
path: "**/node_modules"
key: ${{ runner.os }}-modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Install dependencies
run: pnpm install --frozen-lockfile

lint:
needs: setup
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 8

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'pnpm'

- name: Load node_modules
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Run linter for now-playing
run: pnpm format

- name: Ensure there is no diff
run: |
git diff --exit-code
test:
needs: setup
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: pnpm/action-setup@v4
with:
version: 8

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'pnpm'

- name: Load node_modules
uses: actions/cache@v4
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/pnpm-lock.yaml') }}

- name: Run test for now-playing
run: pnpm test
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.github
*.yaml
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": false,
"singleQuote": true
}
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ yarn add @BolajiOlajide/now-playing
## Usage

```ts
import { NowPlaying, Providers } from "@BolajiOlajide/now-playing";
import { NowPlaying, Providers } from '@BolajiOlajide/now-playing'

const np = new NowPlaying(Providers.SPOTIFY, {
useCache: false, // default is true
cacheDuration: 30000, // in milliseconds
streamerArgs: {
clientId: "foo",
clientSecret: "bar",
refreshToken: "baz",
clientId: 'foo',
clientSecret: 'bar',
refreshToken: 'baz',
},
});
})
```

### Storage
Expand All @@ -41,7 +41,7 @@ Data is stored in memory. This is to reduce overhead. We plan to expose the `ISt

#### Spotify

You need two things.
You need three things.

1. Spotify Client ID
2. Spotify Client Secret
Expand Down
7 changes: 3 additions & 4 deletions examples/spotify.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { NowPlaying, Providers } from "../dist";
import { NowPlaying, Providers } from '../dist'

const np = new NowPlaying(Providers.SPOTIFY, {
streamerArgs: {
clientId: 'foo',
clientSecret: 'bar',
refreshToken: 'baz',
},
});
})


console.log("Hello World", np);
console.log('Hello World', np)
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"type": "module",
"scripts": {
"ex:spotify": "ts-node examples/spotify.ts",
"build": "npx rimraf dist && rollup --config"
"build": "npx rimraf dist && rollup --config",
"test": "vitest",
"format": "prettier . --write"
},
"exports": {
"types": "./dist/now-playing.d.ts",
Expand All @@ -20,20 +22,23 @@
],
"keywords": [],
"author": "",
"license": "ISC",
"license": "MIT",
"dependencies": {
"@types/node-fetch": "2.6.11",
"node-fetch": "2.6.7",
"zod": "3.23.8"
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.6",
"@types/node": "^18.12.1",
"rollup": "^4.18.0",
"rollup-plugin-dts": "^6.1.1",
"@rollup/plugin-typescript": "11.1.6",
"@types/node": "20.14.9",
"@types/node-fetch": "2.6.11",
"msw": "2.3.1",
"prettier": "3.3.2",
"rollup": "4.18.0",
"rollup-plugin-dts": "6.1.1",
"ts-node": "10.9.2",
"tslib": "^2.6.3",
"typescript": "5.4.5"
"tslib": "2.6.3",
"typescript": "5.4.5",
"vitest": "1.6.0"
},
"engines": {
"node": ">=18"
Expand Down
Loading

0 comments on commit 4d58d51

Please sign in to comment.