Skip to content

Commit c7b4003

Browse files
authored
Merge pull request #75 from microcmsio/chore/update-dev-dependencies
開発用の依存関係について更新
2 parents 1a19fc2 + b891173 commit c7b4003

File tree

8 files changed

+2610
-3123
lines changed

8 files changed

+2610
-3123
lines changed

package-lock.json

Lines changed: 2307 additions & 2783 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@
3636
"async-retry": "^1.3.3"
3737
},
3838
"devDependencies": {
39-
"@swc/core": "^1.3.82",
40-
"@types/async-retry": "^1.4.5",
41-
"@types/jest": "^29.5.4",
39+
"@swc/core": "^1.4.7",
40+
"@types/async-retry": "^1.4.8",
41+
"@types/jest": "^29.5.12",
4242
"@types/node": "^18.19.14",
43-
"@typescript-eslint/eslint-plugin": "^6.5.0",
44-
"@typescript-eslint/parser": "^6.5.0",
45-
"eslint": "^8.48.0",
46-
"eslint-config-prettier": "^9.0.0",
47-
"eslint-plugin-jest": "^27.2.3",
48-
"jest": "^29.6.4",
49-
"msw": "^1.2.5",
50-
"prettier": "^3.0.3",
51-
"ts-jest": "^29.1.1",
52-
"tsup": "^7.2.0",
53-
"typescript": "^5.1.0"
43+
"@typescript-eslint/eslint-plugin": "^7.2.0",
44+
"@typescript-eslint/parser": "^7.2.0",
45+
"eslint": "^8.57.0",
46+
"eslint-config-prettier": "^9.1.0",
47+
"eslint-plugin-jest": "^27.9.0",
48+
"jest": "^29.7.0",
49+
"msw": "^2.2.3",
50+
"prettier": "^3.2.5",
51+
"ts-jest": "^29.1.2",
52+
"tsup": "^8.0.2",
53+
"typescript": "^5.4.2"
5454
}
5555
}

tests/createClient.test.ts

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { rest } from 'msw';
1+
import { http, HttpResponse } from 'msw';
22
import { createClient } from '../src/createClient';
33
import { testBaseUrl } from './mocks/handlers';
44
import { server } from './mocks/server';
@@ -23,12 +23,12 @@ describe('createClient', () => {
2323
test('Throws an error if `serviceDomain` or `apiKey` is missing', () => {
2424
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2525
// @ts-expect-error
26-
expect(() => createClient({ serviceDomain: 'foo' })).toThrowError(
26+
expect(() => createClient({ serviceDomain: 'foo' })).toThrow(
2727
new Error('parameter is required (check serviceDomain and apiKey)'),
2828
);
2929
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3030
// @ts-expect-error
31-
expect(() => createClient({ apiKey: 'foo' })).toThrowError(
31+
expect(() => createClient({ apiKey: 'foo' })).toThrow(
3232
new Error('parameter is required (check serviceDomain and apiKey)'),
3333
);
3434
});
@@ -37,21 +37,21 @@ describe('createClient', () => {
3737
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
3838
// @ts-expect-error
3939
createClient({ serviceDomain: 10, apiKey: 'foo' }),
40-
).toThrowError(new Error('parameter is not string'));
40+
).toThrow(new Error('parameter is not string'));
4141
expect(() =>
4242
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4343
// @ts-expect-error
4444
createClient({ serviceDomain: 'foo', apiKey: 10 }),
45-
).toThrowError(new Error('parameter is not string'));
45+
).toThrow(new Error('parameter is not string'));
4646
});
4747

4848
describe('Throws an error when response.ok is false', () => {
4949
test('If there is a message', () => {
5050
server.use(
51-
rest.get(`${testBaseUrl}/list-type`, async (_, res, ctx) => {
52-
return res(
53-
ctx.status(401),
54-
ctx.json({ message: 'X-MICROCMS-KEY header is invalid.' }),
51+
http.get(`${testBaseUrl}/list-type`, async () => {
52+
return HttpResponse.json(
53+
{ message: 'X-MICROCMS-KEY header is invalid.' },
54+
{ status: 401 },
5555
);
5656
}),
5757
);
@@ -60,41 +60,41 @@ describe('createClient', () => {
6060
apiKey: 'apiKey',
6161
});
6262

63-
expect(client.get({ endpoint: 'list-type' })).rejects.toThrowError(
63+
expect(client.get({ endpoint: 'list-type' })).rejects.toThrow(
6464
new Error(
6565
'fetch API response status: 401\n message is `X-MICROCMS-KEY header is invalid.`',
6666
),
6767
);
6868
});
6969
test('If there is no message', () => {
7070
server.use(
71-
rest.get(`${testBaseUrl}/list-type`, async (_, res, ctx) => {
72-
return res(ctx.status(404));
71+
http.get(`${testBaseUrl}/list-type`, async () => {
72+
return new HttpResponse(null, { status: 404 });
7373
}),
7474
);
7575
const client = createClient({
7676
serviceDomain: 'serviceDomain',
7777
apiKey: 'apiKey',
7878
});
7979

80-
expect(client.get({ endpoint: 'list-type' })).rejects.toThrowError(
80+
expect(client.get({ endpoint: 'list-type' })).rejects.toThrow(
8181
new Error('fetch API response status: 404'),
8282
);
8383
});
8484
});
8585

8686
test('Throws an error in the event of a network error.', () => {
8787
server.use(
88-
rest.get(`${testBaseUrl}/list-type`, async (_, res) => {
89-
return res.networkError('Failed to fetch');
88+
http.get(`${testBaseUrl}/list-type`, async () => {
89+
return HttpResponse.error();
9090
}),
9191
);
9292
const client = createClient({
9393
serviceDomain: 'serviceDomain',
9494
apiKey: 'apiKey',
9595
});
9696

97-
expect(client.get({ endpoint: 'list-type' })).rejects.toThrowError(
97+
expect(client.get({ endpoint: 'list-type' })).rejects.toThrow(
9898
new Error('Network Error.\n Details: Failed to fetch'),
9999
);
100100
});
@@ -110,45 +110,46 @@ describe('createClient', () => {
110110
let apiCallCount = 0;
111111

112112
server.use(
113-
rest.get(`${testBaseUrl}/500`, async (_, res, ctx) => {
113+
http.get(`${testBaseUrl}/500`, async () => {
114114
apiCallCount++;
115-
return res(ctx.status(500));
115+
return new HttpResponse(null, {
116+
status: 500,
117+
});
116118
}),
117119
);
118120

119-
await expect(
120-
retryableClient.get({ endpoint: '500' }),
121-
).rejects.toThrowError(new Error('fetch API response status: 500'));
121+
await expect(retryableClient.get({ endpoint: '500' })).rejects.toThrow(
122+
new Error('fetch API response status: 500'),
123+
);
122124
expect(apiCallCount).toBe(3);
123125
}, 30000);
124126

125127
test('Returns an error message if 4xx error(excluding 429)', async () => {
126128
let apiCallCount = 0;
127129

128130
server.use(
129-
rest.get(`${testBaseUrl}/400`, async (_, res, ctx) => {
131+
http.get(`${testBaseUrl}/400`, async () => {
130132
apiCallCount++;
131-
return res(ctx.status(400));
133+
return new HttpResponse(null, { status: 400 });
132134
}),
133135
);
134136

135-
await expect(
136-
retryableClient.get({ endpoint: '400' }),
137-
).rejects.toThrowError(new Error('fetch API response status: 400'));
137+
await expect(retryableClient.get({ endpoint: '400' })).rejects.toThrow(
138+
new Error('fetch API response status: 400'),
139+
);
138140
expect(apiCallCount).toBe(1);
139141
});
140142

141143
test('List format contents can be retrieved if failed twice and succeeded once', async () => {
142144
let failedRequestCount = 0;
143145
server.use(
144-
rest.get(`${testBaseUrl}/two-times-fail`, (_, res, ctx) => {
146+
http.get(`${testBaseUrl}/two-times-fail`, () => {
145147
if (failedRequestCount < 2) {
146148
failedRequestCount++;
147-
return res(ctx.status(500));
149+
return new HttpResponse(null, { status: 500 });
148150
} else {
149-
return res(
150-
ctx.status(200),
151-
ctx.json({
151+
return HttpResponse.json(
152+
{
152153
contents: [
153154
{
154155
id: 'foo',
@@ -162,7 +163,8 @@ describe('createClient', () => {
162163
totalCount: 1,
163164
limit: 10,
164165
offset: 0,
165-
}),
166+
},
167+
{ status: 200 },
166168
);
167169
}
168170
}),
@@ -189,12 +191,11 @@ describe('createClient', () => {
189191
test('List format contents can be retrieved if succeeded once and failed twice', async () => {
190192
let apiCallCount = 0;
191193
server.use(
192-
rest.get(`${testBaseUrl}/only-first-time-success`, (_, res, ctx) => {
194+
http.get(`${testBaseUrl}/only-first-time-success`, () => {
193195
apiCallCount++;
194196
if (apiCallCount === 1) {
195-
return res(
196-
ctx.status(200),
197-
ctx.json({
197+
return HttpResponse.json(
198+
{
198199
contents: [
199200
{
200201
id: 'foo',
@@ -208,10 +209,11 @@ describe('createClient', () => {
208209
totalCount: 1,
209210
limit: 10,
210211
offset: 0,
211-
}),
212+
},
213+
{ status: 200 },
212214
);
213215
} else {
214-
return res(ctx.status(500));
216+
return new HttpResponse(null, { status: 500 });
215217
}
216218
}),
217219
);

tests/get.test.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { rest } from 'msw';
1+
import { http, HttpResponse } from 'msw';
22
import { createClient } from '../src/createClient';
33
import { testBaseUrl } from './mocks/handlers';
44
import { server } from './mocks/server';
@@ -58,12 +58,9 @@ describe('get', () => {
5858
test('Return error message in case of server error', () => {
5959
// Create temporary server error
6060
server.use(
61-
rest.get(`${testBaseUrl}/list-type`, (_, res, ctx) => {
62-
return res.once(
63-
ctx.status(500),
64-
ctx.json({ message: 'Internal Server Error' })
65-
);
66-
})
61+
http.get(`${testBaseUrl}/list-type`, () => {
62+
return HttpResponse.json({ message: 'Internal Server Error' }, { status: 500 });
63+
}, { once: true })
6764
);
6865

6966
expect(client.get({ endpoint: 'list-type' })).rejects.toThrow(

0 commit comments

Comments
 (0)