Skip to content

Commit 64c2282

Browse files
authored
Perform type check with TypeScript in CI (#113)
* Add check script Update tsconfig.json * Run check script in CI * Upgrade jest and @types/jest * Fix type checking issues in tests
1 parent 096cea9 commit 64c2282

File tree

5 files changed

+365
-379
lines changed

5 files changed

+365
-379
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ "main" ]
5+
branches: ["main"]
66
pull_request:
7-
branches: [ "main" ]
7+
branches: ["main"]
88

99
jobs:
1010
test:
@@ -16,12 +16,13 @@ jobs:
1616
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
1717

1818
steps:
19-
- uses: actions/checkout@v3
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v3
22-
with:
23-
node-version: ${{ matrix.node-version }}
24-
cache: 'npm'
25-
- run: npm ci
26-
- run: npm run test
27-
- run: npm run lint
19+
- uses: actions/checkout@v3
20+
- name: Use Node.js ${{ matrix.node-version }}
21+
uses: actions/setup-node@v3
22+
with:
23+
node-version: ${{ matrix.node-version }}
24+
cache: "npm"
25+
- run: npm ci
26+
- run: npm run test
27+
- run: npm run check
28+
- run: npm run lint

index.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, jest, test } from '@jest/globals';
2-
import Replicate, { Prediction } from 'replicate';
2+
import Replicate, { ApiError, Prediction } from 'replicate';
33
import nock from 'nock';
44
import fetch from 'cross-fetch';
55

@@ -37,14 +37,6 @@ describe('Replicate client', () => {
3737
test('Throws error if no auth token is provided', () => {
3838
const expected = 'Missing required parameter: auth'
3939

40-
expect(() => {
41-
new Replicate({ auth: undefined });
42-
}).toThrow(expected);
43-
44-
expect(() => {
45-
new Replicate({ auth: null });
46-
}).toThrow(expected);
47-
4840
expect(() => {
4941
new Replicate({ auth: "" });
5042
}).toThrow(expected);
@@ -156,7 +148,7 @@ describe('Replicate client', () => {
156148
nock(BASE_URL)
157149
.post('/predictions')
158150
.reply(201, (_uri, body) => {
159-
expect(body[ 'stream' ]).toBe(true);
151+
expect((body as any).stream).toBe(true);
160152
return body
161153
})
162154

@@ -200,8 +192,8 @@ describe('Replicate client', () => {
200192
},
201193
});
202194
} catch (error) {
203-
expect(error.response.status).toBe(400);
204-
expect(error.message).toContain("Invalid input")
195+
expect((error as ApiError).response.status).toBe(400);
196+
expect((error as ApiError).message).toContain("Invalid input")
205197
}
206198
})
207199
// Add more tests for error handling, edge cases, etc.

0 commit comments

Comments
 (0)