Skip to content

Commit 0b14d4e

Browse files
committed
chore: Added testing
1 parent 0de4566 commit 0b14d4e

File tree

7 files changed

+3769
-157
lines changed

7 files changed

+3769
-157
lines changed

.github/workflows/pr.yml

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: "Check PR"
2+
on:
3+
pull_request:
4+
5+
jobs:
6+
build:
7+
name: Build
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Cache node modules
15+
id: cache
16+
uses: actions/cache@v3
17+
with:
18+
path: |
19+
~/.cache
20+
**/node_modules
21+
key: cache-node-modules-${{ hashFiles('yarn.lock') }}
22+
restore-keys: |
23+
cache-node-modules-
24+
25+
- name: Set up Node
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: 20
29+
30+
- name: yarn install
31+
if: steps.cache.outputs.cache-hit != 'true'
32+
shell: bash
33+
run: yarn install --immutable
34+
35+
- name: Build
36+
shell: bash
37+
run: yarn build
38+
39+
test:
40+
name: Test (${{ matrix.node }})
41+
needs: [build]
42+
strategy:
43+
matrix:
44+
os:
45+
- "ubuntu-latest"
46+
node:
47+
- "20"
48+
- "18"
49+
runs-on: ${{ matrix.os }}
50+
steps:
51+
- uses: actions/checkout@v2
52+
53+
- name: Setup node
54+
uses: actions/setup-node@v2
55+
with:
56+
node-version: ${{ matrix.node }}
57+
58+
- name: Print Node.js version
59+
run: node -v
60+
61+
- name: Cache node modules
62+
id: cache
63+
uses: actions/cache@v3
64+
with:
65+
path: |
66+
~/.cache
67+
**/node_modules
68+
key: cache-node-modules-${{ hashFiles('yarn.lock') }}
69+
restore-keys: |
70+
cache-node-modules-
71+
72+
- name: Test
73+
run: yarn test

jest.config.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node'
5+
}

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,19 @@
2929
"module": "./dist/esm/index.js",
3030
"scripts": {
3131
"build": "tsc && tsc -p tsconfig.esm.json",
32-
"generate:sdk": "node ./generate-models.js && yarn build"
32+
"generate:sdk": "node ./generate-models.js && yarn build",
33+
"test": "jest"
3334
},
3435
"dependencies": {
3536
"axios": "^1.6.2"
3637
},
3738
"devDependencies": {
39+
"@jest/globals": "^29.7.0",
40+
"@types/jest": "^29.5.11",
3841
"@types/node": "^20.10.4",
42+
"jest": "^29.7.0",
3943
"openapi-typescript-codegen": "^0.25.0",
44+
"ts-jest": "^29.1.1",
4045
"typescript": "^5.3"
4146
},
4247
"packageManager": "[email protected]"

src/Doczilla.ts

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ export default class Doczilla {
1818
public readonly webhook: WebhookService
1919

2020
constructor(token: string, options: DoczillaOptions = {}) {
21+
if (!token) {
22+
throw new Error('No token provided!')
23+
}
24+
2125
this.client = axios.create({
2226
baseURL: options.baseURL || 'https://api.doczilla.app',
2327
headers: {

src/__tests__/Doczilla.spec.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { describe, expect, test } from '@jest/globals'
2+
3+
import Doczilla from '../Doczilla'
4+
5+
describe('Doczilla', () => {
6+
7+
test('it should throw an error if no api key is provided', () => {
8+
let error: Error
9+
try {
10+
// @ts-expect-error
11+
new Doczilla()
12+
} catch (err) {
13+
error = err
14+
}
15+
16+
expect(error.message).toEqual('No token provided!')
17+
})
18+
19+
})

tsconfig.json

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
"resolveJsonModule": true,
1212
"typeRoots": [
1313
"node_modules/@types"
14+
],
15+
"types": [
16+
"node",
17+
"jest"
1418
]
1519
},
1620
"exclude": [

0 commit comments

Comments
 (0)